The Problem: Standard OLS assumes homoskedasticity (constant variance)
\[\text{Var}(\varepsilon_i | X) = \sigma^2 \text{ for all } i\]
Reality: Often \(\text{Var}(\varepsilon_i | X) = \sigma_i^2\) varies across observations
Solution:Heteroskedasticity-robust standard errors (also called “sandwich” or “Huber-White” standard errors) remain valid even when variances differ
The Problem: Heteroskedasticity
What is Heteroskedasticity?
Heteroskedasticity: The variance of errors depends on \(X\)\[\text{Var}(\varepsilon_i | X_i) = \sigma_i^2 \neq \sigma^2\]
Visualizing Heteroskedasticity
Right panel: The spread increases as X increases
Why Does Heteroskedasticity Matter?
Good news: OLS estimator \(\hat{\beta}\) is still unbiased and consistent
Bad news: The usual standard error formula is wrong!
Standard OLS variance formula assumes: \[\text{Var}(\hat{\beta}) = \sigma^2(X^TX)^{-1}\]
Problem: This formula assumes constant \(\sigma^2\), but we have varying \(\sigma_i^2\)
Consequences of Using Wrong SE
Using standard SEs with heteroskedasticity leads to:
Invalid hypothesis tests (wrong p-values)
Invalid confidence intervals (wrong coverage)
Misleading inference (false positives or negatives)
The coefficient is fine, but we can’t trust our uncertainty estimates!
The Solution: Robust Standard Errors
The Correct Variance Formula
With heteroskedasticity, the true variance of \(\hat{\beta}\) is: \[\text{Var}(\hat{\beta}) = (X^TX)^{-1} \left(\sum_{i=1}^n X_i X_i^T \sigma_i^2\right) (X^TX)^{-1}\]
Problem: We don’t know the true \(\sigma_i^2\)
Solution: Estimate each \(\sigma_i^2\) with the squared residual \(\hat{\varepsilon}_i^2\)
Called the “sandwich” because of its structure: \[\underbrace{(X^TX)^{-1}}_{\text{bread}} \underbrace{\left(\sum X_i X_i^T \hat{\varepsilon}_i^2\right)}_{\text{meat}} \underbrace{(X^TX)^{-1}}_{\text{bread}}\]
Why “Robust”?
This estimator is robust to heteroskedasticity:
If errors are homoskedastic: Robust SE ≈ Standard SE (asymptotically)
If errors are heteroskedastic: Robust SE is correct, Standard SE is wrong
Big picture: Robust SEs work whether or not you have heteroskedasticity
Variants of Robust Standard Errors
Several versions exist, with different finite-sample adjustments:
WLS distribution is tighter (has smaller variance)
When is Inference Valid?
Validity of WLS Inference
WLS inference is valid when:
Weights are correctly specified:\(w_i = \sigma_i^2/\sigma^2\) exactly
Other assumptions hold: Linearity, independence, etc.
Problem: If weights are wrong, WLS inference is invalid
Validity of WLS Inference
Example: Using \(w_i = x_i\) when true variance is \(\sigma_i^2 = \exp(x_i)\)
WLS estimator is still consistent but not efficient
Standard errors are wrong
Hypothesis tests maybe wrong
When Weights Are Wrong
# True variance structure: exponential in xset.seed(1)x <-runif(100, 0, 2)true_var <-exp(x)y <-2+3*x +rnorm(100, sd =sqrt(true_var))# Wrong weights: linear in xwrong_weights <- x# Fit WLS with wrong weightsmodel_wrong_wls <-lm(y ~ x, weights =1/wrong_weights)# Standard SEs are wrong!summary(model_wrong_wls)$coefficients
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.609030 0.1725209 9.326583 3.504868e-15
x 3.383816 0.2432085 13.913230 6.153096e-25
These standard errors are not reliable because weights are misspecified
Validity of Robust SE Inference
Robust SE inference is valid when:
Large sample size: Robust SEs are asymptotically valid
Correct model specification: Need correct \(E[Y|X]\)
Independence: Observations are independent
No severe leverage points: Extreme \(X\) values can cause problems
Key advantage: Don’t need to know variance structure!
Asymptotic Validity
Important caveat: Robust SEs are asymptotically valid
Need “large enough” sample size
Can underestimate uncertainty in small samples
Various corrections (HC2, HC3) help with small samples
Why Prefer Robust SEs Despite Lower Efficiency?
Reason 1: Unknown Variance Structure
In practice, we rarely know the true weights!
Problem with WLS:
Need to model \(\sigma_i^2\) as function of \(X\)
If model is wrong, inference is invalid
Hard to know if model is correct
Reason 1: Unknown Variance Structure
In practice, we rarely know the true weights!
Robust SEs:
No need to model variance structure
Valid for any heteroskedasticity pattern
Example: Modeling the Variance
Suppose we think variance depends on \(x\), so we try: \[\sigma_i^2 = \exp(\alpha_0 + \alpha_1 x_i)\]
Steps to implement WLS:
Fit OLS and get residuals \(\hat{\varepsilon}_i\)
Regress \(\log(\hat{\varepsilon}_i^2)\) on \(x\) to estimate \(\alpha_0, \alpha_1\)