Heteroskedasticity: Whose Variance Differs? How Does It Manifest Differently in Cross-Sectional vs. Panel Data? How to Test and Address It?
You study \"the effect of education on personal income.\" You run an OLS regression:
1. Opening: In the Same Regression Model, Does the Wage Volatility of the Rich Equal That of the Poor?
You study "the effect of education on personal income." You run an OLS regression:
One of the standard assumptions of OLS is homoskedasticity: , meaning the variance of the error term is a constant—regardless of a person's education level, the volatility of the unexplained part of their income is the same.
But think about it—is this assumption reasonable?
A person with only a primary school education will likely have income hovering near the minimum wage, with a very small range of fluctuation—no matter how hard they work or how lucky they get, the upper bound of their income is locked in by their education. What about a PhD graduate? They might land a high-paying job at a startup, or earn a modest but stable salary in academia, or command a sky-high compensation package in industry—their income fluctuation range is far larger than that of someone with low education. In other words:
This is heteroskedasticity—the variance of the error term is not constant across observations but depends systematically on the values of certain variables.
Core message: Heteroskedasticity means "the variance of the error term ε differs at different values of X"—not the variance of Y, not the variance of X, but the conditional variance of ε varying with X. In cross-sectional data, heteroskedasticity typically manifests as "the dispersion of errors widening as some continuous variable (e.g., income, firm size) increases." In panel data, heteroskedasticity has two layers—different individuals at the same point in time have different error variances (groupwise heteroskedasticity), and the same individual has different error variances across time (within-group heteroskedasticity). The standard solution for cross-sectional data is robust standard errors (White/Huber); the standard solution for panel data is cluster-robust standard errors—treating each individual's errors across time periods as a 'cluster,' allowing arbitrary within-cluster correlation and heteroskedasticity.
2. Heteroskedasticity: Whose Variance Differs?—Three "It Is Not" Statements
2.1 It Is Not That the Variance of Y Differs
The variance of Y can vary with X—this is what the regression model itself predicts. If your model is , then a person with Education = 20 naturally has a higher predicted income than someone with Education = 6—the conditional mean of Y differs, and part of the variance of Y is explained by X. This is not heteroskedasticity—this is the regression model doing its job.
2.2 It Is Not That the Variance of X Differs
The variance of X is a sample characteristic—whether years of education in your sample are concentrated between 9–16 years or spread across 0–22 years—this does not affect the classical OLS assumptions. X can have any distribution.
2.3 Heteroskedasticity Is That the Conditional Variance of ε Differs
In plain language: After you have used X to explain all the "explainable part" of Y, the volatility of the remaining "unexplainable noise"—differs at different values of X. The volatility of this noise should not depend systematically on the magnitude of X. If it does, you have heteroskedasticity.
3. No Need to Run Tests—You Can Judge the Presence of Heteroskedasticity from Theory and Logic
Before running any formal heteroskedasticity test, you can often already infer from theory and common sense—"this data almost certainly has heteroskedasticity." The following four lines of logic can help you make this prior judgment.
3.1 Logic One: The Values of Y Themselves Constrain the Range of Error Volatility
If your Y is a variable like "counts," "expenditure," or "income" with a lower bound of zero and no hard upper bound, the larger the absolute value of Y, the larger its natural fluctuation range tends to be.
- Someone earning 5,000 yuan a year—errors can at most swing their income between 0 and 10,000.
- Someone earning 500,000 yuan a year—errors can swing their income between 100,000 and 5 million.
The larger the conditional mean of Y → the larger the natural fluctuation range of Y → the larger the fluctuation range of the errors → heteroskedasticity. This is the most common pattern of heteroskedasticity in cross-sectional data—the "megaphone shape" (variance diverging as the conditional mean increases).
Conversely, if Y is a variable with clear upper and lower bounds, such as "proportions," "percentages," or "test scores (0–100)," Y fluctuates most in the middle and necessarily less near the endpoints of 0 or 100%—this also implies heteroskedasticity, but the pattern is "spindle-shaped."
3.2 Logic Two: The Size of Observational Units Varies Enormously
In firm and industry data:
- Small micro-enterprises (annual revenue of 500,000 yuan) and Huawei (annual revenue of 600 billion yuan) in the same regression—the profit fluctuation range of a micro-enterprise is tens of thousands of yuan, while Huawei's profit fluctuation range is tens of billions of yuan.
- Conclusion: As long as your sample contains observational units with vastly different "scales," heteroskedasticity is almost inevitable. This is also why empirical research at the firm level almost by default uses robust standard errors.
Similarly, in cross-country comparisons—Luxembourg (population 600,000) and the United States (population 330 million) in the same sample—the magnitude of volatility of any variable is incomparable.
3.3 Logic Three: Y Is Group-Level Aggregated Data
If your Y is "per capita GDP of a province," "average wage of an industry," or "crime rate of a city"—each observation is itself the mean of a group. The sample sizes of the groups differ (large province vs. small province), and the precision of the estimated means differs. For provinces with large sample sizes, the per capita GDP estimate is more precise (smaller error variance); for provinces with small sample sizes, the error variance is larger.
Group-level aggregated data almost always exhibit heteroskedasticity—the variance of the errors is inversely proportional to the group's sample size. In this case, using weighted least squares (WLS, with weights = group sample sizes) is more efficient than OLS + robust standard errors.
3.4 Logic Four: Y Is a 0/1 Variable (Linear Probability Model)
As discussed in the previous article, the variance of a Bernoulli distribution is p(1−p)—constructive heteroskedasticity, which necessarily exists.
4. Heteroskedasticity in Cross-Sectional Data—Manifestations, Tests, and Solutions
4.1 Manifestations
Heteroskedasticity in cross-sectional data almost always appears in the form of "error variance varying with some X or ":
- Megaphone shape: Var(ε | X) increases as X increases (the most common pattern, e.g., income, firm size data).
- Spindle shape: Var(ε | X) is largest in the middle of X and smallest at the two ends (proportions, test scores, saturation indicators).
- Irregular patterns: Variance suddenly changes in certain ranges of X (e.g., different uncertainty before and after a policy discontinuity).
Diagnostic tool: rvfplot (residual-versus-fitted plot) is the most intuitive initial check. If the spread of residuals is clearly different at different levels of → a strong signal of heteroskedasticity.
4.2 Testing Methods
(a) Breusch-Pagan test (BP test)—most commonly used
H₀: Homoskedasticity ().
The BP test regresses the squared residuals on all X variables. If X can significantly explain the variation in → the error variance is related to X → reject homoskedasticity.
reg y x1 x2 x3
estat hettest // default uses fitted values ŷ
estat hettest, rhs // uses all X (rather than fitted values)
estat hettest x1 x2 // tests only the specified X variablesLimitation of the BP test: It assumes heteroskedasticity is a linear function of X. If the pattern of heteroskedasticity is not linear (e.g., related to X²), the BP test may fail to detect it.
(b) White test—more general
The White test regresses on X, X², and all cross-products of X. It does not presuppose a specific form of heteroskedasticity—hence it is more flexible, but it consumes many degrees of freedom when there are many variables, and its power may be low in small samples.
reg y x1 x2 x3
estat imtest, white(c) Practical recommendations
In empirical papers, the BP test is sufficient. You do not need to run BP, White, and Goldfeld-Quandt all at once—one test to demonstrate the existence of heteroskedasticity, then handle it with robust standard errors. Report one sentence: "The Breusch-Pagan test rejects the null hypothesis of homoskedasticity (p < 0.01); therefore, heteroskedasticity-robust standard errors are used throughout."
4.3 Solutions
Method One: Robust standard errors (Huber-White)—most commonly used
The core idea of this formula: Instead of assuming each observation has the same error variance (all σ²), let each observation use its own squared residual to estimate its own variance. This is called the "sandwich estimator"—X'X is the bread, and the in the middle is the filling.
reg y x1 x2 x3, robustKey fact: Robust standard errors do not change the coefficient estimates— is exactly the same as in ordinary OLS. They only change the standard errors (and the resulting t-values, p-values, and confidence intervals). When heteroskedasticity is present, the SEs from robust standard errors are more reliable than those from ordinary OLS.
Method Two: Weighted least squares (WLS)—more efficient but requires knowing the "weights"
If you know the specific form of heteroskedasticity—for example, —you can use 1/Xᵢ as weights so that the weighted residual variance is approximately constant. WLS is BLUE (provided the weights are correctly specified)—more efficient than OLS + robust standard errors.
But in practice, you rarely know the exact form of heteroskedasticity—guessing the wrong weights can make WLS worse than OLS. Therefore, OLS + robust standard errors is the default in empirical work, and WLS is only recommended when you have a clear prior theory (e.g., weighting by group sample size for grouped data).
Method Three: Taking ln—not necessarily for heteroskedasticity, but often helpful
Taking the ln of Y often alleviates heteroskedasticity—because it compresses "absolute volatility magnitudes" into "relative volatility proportions." The absolute fluctuation range of an annual income of 5,000 yuan versus 500,000 yuan differs by two orders of magnitude, but on the ln scale, the relative fluctuations of the two are comparable in proportional terms. This is not the main purpose of taking ln (the main purpose is elasticity and semi-elasticity interpretation), but it is a beneficial "side effect" of taking ln.
5. Heteroskedasticity in Panel Data—An Entire Additional Dimension Compared to Cross-Sectional Data
5.1 Two Forms of Heteroskedasticity in Panel Data
In panel data, the error has two dimensions—individual (i) and time (t). Heteroskedasticity can also unfold along these two dimensions:
(a) Groupwise heteroskedasticity: Different individuals have different error variances.
For example: In a panel regression studying "firm R&D expenditure," the fluctuation in Huawei's (a large firm) R&D expenditure is far larger than that of a small tech company—the variances differ across individuals.
(b) Within-group serial correlation: Errors of the same individual across different time periods are correlated.
For example: Huawei's R&D expenditure this year and next year are correlated—because factors that do not vary over time, such as the firm's R&D strategy, management style, and technology path, simultaneously affect R&D expenditure in all periods.
Strictly speaking, within-group serial correlation is not "heteroskedasticity" (heteroskedasticity is different variances; serial correlation is nonzero covariance)—but in panel data practice, the two almost always appear together and are handled together.
5.2 Manifestations of Heteroskedasticity in Panel Data—Why Is It More Subtle Than in Cross-Sectional Data?
In cross-sectional data, you can draw an rvfplot to visually see whether residuals diverge. In panel data, the situation is more complex:
- The residuals of the same individual "cluster together" over time—if Huawei's residuals are positive in all years (all above the model's predictions), this does not mean the model is wrong—it merely means Huawei has some "fixed advantage" that the model does not control for (which is precisely what fixed effects models remove).
- If you use a fixed effects model (
xtreg, fe), the time-invariant individual-level factors have already been eliminated—among the remaining residuals, there may still be variance differences across individuals (groupwise heteroskedasticity) and serial correlation within the same individual.
5.3 Testing Methods
(a) Test for groupwise heteroskedasticity—modified Wald test
After a fixed effects model:
xtreg y x1 x2, fe
ssc install xttest3
xttest3H₀: for all i (groupwise homoskedasticity). p < 0.05 → groupwise heteroskedasticity exists.
(b) Test for within-group serial correlation—Wooldridge test
ssc install xtserial
xtserial y x1 x2H₀: No first-order autocorrelation. p < 0.05 → within-group serial correlation exists.
(c) Simultaneously testing groupwise heteroskedasticity and within-group serial correlation—Breusch-Pagan LM test
After a random effects model:
xtreg y x1 x2, re
xttest0This test compares the suitability of random effects versus pooled OLS—it essentially tests whether the individual effects () are zero. If individual effects are significant → errors of the same individual across periods are correlated (because they share the individual effect uᵢ).
5.4 Solutions
Method One: Clustered standard errors—the industry standard for panel empirical work
Core idea: Allow arbitrary forms of correlation and heteroskedasticity among the errors of the same individual (i) across different time periods (t)—no need to assume they are independent, no need to assume they are homoskedastic. Each individual is treated as a "cluster," within which errors can be arbitrarily related, while errors across clusters are treated as independent.
xtreg y x1 x2, fe cluster(id) // clustering at the individual level
reg y x1 x2, cluster(id) // OLS + clustered standard errorsChoosing the level of clustering:
- Clustering at the individual level (
cluster(id))—the most common and most robust choice. - If your treatment variable varies at a higher level (e.g., a policy at the "province" level), you should cluster at that higher level (
cluster(province))—because errors of different individuals within the same province may be correlated. - If T is very small (e.g., T = 2 or 3), standard errors clustered at the individual level may be underestimated—in this case, you can use bootstrap standard errors or wild bootstrap.
Method Two: FGLS (feasible generalized least squares)—more efficient but more fragile
FGLS first estimates the structure of heteroskedasticity and autocorrelation, then uses this estimate for weighting. The xtgls command can implement this.
xtgls y x1 x2, panels(heteroskedastic) corr(ar1)FGLS is more efficient than OLS + clustered standard errors when the variance structure is correctly specified. But if you guess the variance structure wrong, FGLS standard errors can be severely underestimated—you will be "overly significant."
Therefore, in empirical economics, OLS/FE + cluster-robust standard errors is the absolute mainstream. FGLS is more common when T is large and N is small (e.g., macro panels—20 countries, 50 years of data).
6. Cross-Sectional vs. Panel—Quick Reference for Heteroskedasticity Solutions
| Cross-sectional data | Panel data | |
|---|---|---|
| Typical manifestation of heteroskedasticity | Var(εᵢ) varies with Xᵢ or Ŷᵢ (megaphone shape) | Groupwise heteroskedasticity + within-group serial correlation (dual structure) |
| Preferred test | Breusch-Pagan (estat hettest) |
Modified Wald (groupwise) + Wooldridge (serial correlation) |
| Preferred solution | OLS + robust standard errors (robust) |
FE + clustering at the individual level (cluster(id)) |
| Common alternative | Taking ln (sometimes naturally alleviates heteroskedasticity) | FGLS (more common when T is large and N is small) |
| Almost always needed? | Firm/income/size data → almost always | Panel data → clustered standard errors almost always needed |
| One-line Stata command | reg y x, robust |
xtreg y x, fe cluster(id) |
7. Common Misconceptions
7.1 Misconception One: Heteroskedasticity Causes Biased Coefficients
No. Heteroskedasticity only affects the estimation of standard errors—it does not affect the unbiasedness of coefficients. Under the assumption Cov(X, ε) = 0, OLS remains unbiased and consistent even when heteroskedasticity is present. You do not need to "correct" the coefficients—you only need to "correct" the standard errors.
This is also why, after using robust standard errors, the Coefficient column in the regression table remains completely unchanged—only Std. Err., t, p, and CI change.
7.2 Misconception Two: BP Test Not Significant → No Need for Robust Standard Errors
A nonsignificant BP test only means you did not detect a linear form of heteroskedasticity—it does not necessarily mean homoskedasticity holds. When the sample size is not particularly large, the power of the BP test is limited. In empirical work, if your data type is naturally prone to heteroskedasticity (firm data, income data, grouped data, 0/1 dependent variables), using robust standard errors even when BP is not significant is a good practice accepted by reviewers.
7.3 Misconception Three: In Panel Data, Fixed Effects Already Solve Heteroskedasticity
Fixed effects eliminate time-invariant individual heterogeneity (uᵢ is removed). They do not eliminate heteroskedasticity in —different individuals may still have different error variances after removing fixed effects (groupwise heteroskedasticity), and errors of the same individual across periods may still be correlated (within-group serial correlation). Clustered standard errors are still needed after FE.
7.4 Misconception Four: Clustered Standard Errors Are Also Valid When the Number of Clusters Is Too Small
The asymptotic theory of clustered standard errors relies on "the number of clusters → ∞." If the number of clusters is too small (e.g., only 10 provinces), clustered standard errors will severely underestimate the true standard errors. Rule of thumb: number of clusters < 20 → use clustered standard errors with caution; number of clusters < 10 → consider using wild bootstrap or more conservative inference methods.
8. Summary
Six core pieces of knowledge about heteroskedasticity:
-
Heteroskedasticity is the conditional variance of ε varying with X—not the variance of Y, not the variance of X. It says that "after controlling for X, the volatility of the remaining noise is not uniform."
-
You do not need to wait for test results to know heteroskedasticity exists. If your data involve income, firm size, cross-country comparisons, group-level aggregation, or Y is 0/1—heteroskedasticity is almost certainly present from theory and logic.
-
Cross-sectional data: BP test + robust standard errors. This is the most standard combination in empirical work—the test confirms the existence of heteroskedasticity, and
robustcorrects the standard errors. Coefficients unchanged, inference becomes reliable. -
Panel data: groupwise heteroskedasticity + within-group serial correlation = a dual problem. The standard solution is cluster-robust standard errors at the individual level (
cluster(id))—allowing arbitrary correlation and arbitrary heteroskedasticity within each individual's errors. -
OLS + robust/clustered standard errors > WLS/FGLS (in most empirical settings). Robust standard errors do not require you to know the specific form of heteroskedasticity—you do not need to guess "the variance is proportional to which power of which X."
-
Heteroskedasticity does not cause bias—it only makes standard errors unreliable. You do not need to "correct the coefficients"—you only need to make your inference honest.
One-sentence closing:
"Heteroskedasticity is not a 'defect' of your data—it is an honest reflection of a fact naturally present in your data: 'uncertainty is not equal across locations.' The rich have larger income fluctuations than the poor, large firms have larger profit fluctuations than small firms, large countries have larger economic fluctuations than small countries—this is not a problem with the model; this is the way the world is. What you need to do is not 'eliminate' it, but use robust standard errors to tell your readers: I have accounted for this unequal uncertainty, and my inference remains honest."
9. Presentation Suggestions for Bilibili/WeChat Official Account
- Bilibili video: Recommend using the "megaphone" as the visual metaphor running through the entire video. Opening: a scatter plot—X-axis is years of education, Y-axis is income. The data points form a megaphone shape—at the low-education end, they are tightly clustered at the bottom; at the high-education end, they spread out into a large megaphone opening. Voiceover: "The homoskedasticity assumption says—regardless of how many years of education you have, the volatility of the 'unexplainable' part of your income is the same. This graph says—clearly not." Act One "Whose variance?": three curves on screen—the variance curve of Y (rising with X—this is not heteroskedasticity, this is regression at work), the variance curve of X (not varying with X—this is not heteroskedasticity), the variance curve of ε (rising with X—this is it!). Highlight the third one. Voiceover: "Heteroskedasticity is not that the variance of Y differs, not that the variance of X differs—it is that after you control for X, the volatility of the remaining noise differs at different values of X." Act Two "Cross-section vs. panel": left side—megaphone-shaped scatter plot of cross-sectional data, annotated "BP test +
robust." Right side—a three-dimensional plot of panel data (individual × time × Y), with each individual's data points across periods enclosed in a colored bubble. Bubbles vary in size (groupwise heteroskedasticity), and points within a bubble are close to each other (within-group serial correlation). Annotated "Clustered standard errors = 'arbitrary heteroskedasticity + arbitrary autocorrelation' with the individual as the unit." Act Three "How to solve": a toolbox animation—robust(sandwich icon), clustered standard errors (a cluster of data points framed together), taking ln (a logarithmic curve compressing values), WLS (a scale with weights on one end). The first three tools light up, voiceover: "The first two are the workhorses in empirical work—no need to guess the form of heteroskedasticity." - WeChat Official Account: The "three 'it is not' statements" about heteroskedasticity (not the variance of Y, not the variance of X, but the conditional variance of ε) are recommended to be made into an illustrative diagram. The comparison table of tests + solutions for cross-section vs. panel should be made into a core infographic. The principle of clustered standard errors ("each individual is a cluster, arbitrary within-cluster correlation, independent across clusters") is recommended to be visualized with a simplified data matrix of five individuals and three time periods. The four lines of logic (Y's own value constraints / large differences in observational unit sizes / group-level aggregated data / 0/1 dependent variable) are recommended to be made into "scenario inference cards." Misconception Four should be made into a warning card. Stata command quick reference (cross-section:
reg, robust+estat hettest; panel:xtreg, fe cluster(id)+xttest3+xtserial) should be formatted as code block cards. - Recommended titles:
- Main title: 《Heteroskedasticity: Whose Variance Differs?—How to Detect and Solve It in Cross-Sectional and Panel Data?》
- Alternative title: 《The Rich Have Larger Income Fluctuations Than the Poor—This Is Heteroskedasticity, Not Bad Data》
- New media title: 《Are Your Residuals Megaphone-Shaped?—A Complete Guide to Heteroskedasticity from Theoretical Judgment to Testing》
- Key quotes:
"Heteroskedasticity is not a problem with the model—it is the way the world is. The rich simply have larger income fluctuations than the poor, and large firms simply have larger profit fluctuations than small firms. What you need to do is not pretend this difference does not exist, but honestly tell your readers with robust standard errors: I have accounted for it."
"Robust standard errors do not change the coefficients—they change your 'confidence' in the coefficients. The coefficient is still the same coefficient, but now you have paired it with a more honest standard error."
"Heteroskedasticity in panel data has two layers—different individuals have different fluctuation magnitudes (groupwise heteroskedasticity), and the fluctuations of the same individual across periods are intertwined (within-group serial correlation). Clustered standard errors respond to both layers in one sentence: 'I take the individual as the unit and allow arbitrary chaos within.'"
"A nonsignificant Breusch-Pagan test does not mean homoskedasticity holds—it may just be that your sample size is not yet large enough for the test to detect it. In income, firm, and cross-country data, treat
robustas the default option—it is not overcautious; it is honest."