01 / 21

Sandwich Variance
& Robust SE

Understand why classical standard errors fail under heteroskedasticity and how the sandwich estimator provides robust inference without assuming a specific error structure.

Statistics Econometrics

Why Do We Need Robust Standard Errors?

In ordinary least squares (OLS), we estimate \(\hat{\beta} = (X'X)^{-1}X'y\). The classical variance formula assumes homoskedastic errors:

\(\text{Var}(\hat{\beta}) = \sigma^2 (X'X)^{-1}\)

Homoskedasticity vs Heteroskedasticity

Homoskedastic
\(\text{Var}(\varepsilon_i \mid X) = \sigma^2\) for all \(i\). Error variance is constant. Classical SE is valid.
Heteroskedastic
\(\text{Var}(\varepsilon_i \mid X) = \sigma_i^2\). Error variance changes with \(x_i\). Classical SE is biased.
Homoskedastic Heteroskedastic x x

The True Variance of \(\hat{\beta}\)

Without assuming homoskedasticity, the variance of the OLS estimator is:

\(\text{Var}(\hat{\beta}) = (X'X)^{-1} \, X' \Omega \, X \, (X'X)^{-1}\)

where \(\Omega = \text{Var}(\varepsilon \mid X)\) is the \(n \times n\) covariance matrix of errors. Under homoskedasticity, \(\Omega = \sigma^2 I\) and this reduces to the classical form. Otherwise, we need the full sandwich.

Anatomy of the Sandwich

Bread
\((X'X)^{-1}\)
Model structure Meat
\(X' \text{diag}(e_i^2)\, X\)
Empirical variance from squared residuals Bread
\((X'X)^{-1}\)
Model structure
\(B \cdot M \cdot B\)

The HC0 Estimator (White, 1980)

Halbert White proposed replacing \(\Omega\) with a diagonal matrix of squared OLS residuals:

\(\hat{V}_{\text{HC0}} = (X'X)^{-1} \left( \sum_{i=1}^{n} e_i^2 \, x_i x_i' \right) (X'X)^{-1}\)
1
No distributional assumption: works regardless of the form of heteroskedasticity.
2
Consistent: as \(n \to \infty\), \(\hat{V}_{\text{HC0}}\) converges to the true variance.
3
Finite-sample bias: HC0 tends to underestimate the variance in small samples.

HC Estimator Variants

Several corrections improve finite-sample performance by adjusting the squared residuals \(e_i^2\):

Variant Residual Weight Key Idea
HC0 \(e_i^2\) No correction
HC1 \(\frac{n}{n-k}\,e_i^2\) Degrees-of-freedom correction
HC2 \(\frac{e_i^2}{1-h_{ii}}\) Leverage-based correction
HC3 \(\frac{e_i^2}{(1-h_{ii})^2}\) Jackknife-like (most conservative)

Classical vs Robust SE

Feature Classical SE Robust SE
Assumes \(\text{Var}(\varepsilon_i) = \sigma^2\) No restriction on \(\text{Var}(\varepsilon_i)\)
Formula \(\hat{\sigma}^2(X'X)^{-1}\) \((X'X)^{-1}\hat{M}(X'X)^{-1}\)
If homoskedastic Efficient, correct Correct, slightly less efficient
If heteroskedastic Biased, invalid tests Consistent, valid tests
Small-sample Exact (under normality) Approximate: improves with \(n\)

How to Apply Robust SE

1
Fit OLS as usual: Obtain \(\hat{\beta}\) and residuals \(e_i = y_i - x_i'\hat{\beta}\).
2
Choose an HC variant: HC1 for quick adjustment, HC3 for small samples or high-leverage data.
3
Compute the meat: \(\hat{M} = \sum_{i=1}^{n} \tilde{e}_i^2 \, x_i x_i'\), where \(\tilde{e}_i\) is the adjusted residual for your chosen variant.
4
Assemble the sandwich: \(\hat{V} = (X'X)^{-1}\hat{M}(X'X)^{-1}\). Take \(\sqrt{\text{diag}(\hat{V})}\) for robust SE.
5
Use robust SE in inference: Replace classical SE in \(t\)-statistics, confidence intervals, and \(F\)-tests.

Example: Simple Regression

Suppose we regress income on education with \(n=5\) observations and \(k=2\) (intercept + slope). OLS gives \(\hat{\beta}_1 = 2.3\) with residuals:

\(i\) \(x_i\) \(e_i\) \(e_i^2\)
110-1.21.44
2120.80.64
3141.83.24
4162.14.41
518-3.512.25

Example: Computing HC1

Using HC1 with the degree-of-freedom correction \(\frac{n}{n-k} = \frac{5}{3}\):

\(\hat{V}_{\text{HC1}} = \frac{n}{n-k}(X'X)^{-1}\left(\sum_{i=1}^{5} e_i^2 \, x_i x_i'\right)(X'X)^{-1}\)
1
Classical SE for \(\hat{\beta}_1\): 0.42 (assumes \(\sigma^2\) constant).
2
HC1 Robust SE for \(\hat{\beta}_1\): 0.68 (accounts for growing spread).
3
Implication: the classical \(t\)-stat is \(2.3/0.42 = 5.48\), but the robust \(t\)-stat is \(2.3/0.68 = 3.38\). The effect is still significant, but less overwhelmingly so.

Example: When SE Flips

Robust SE can be larger or smaller than classical SE depending on the pattern of heteroskedasticity:

Robust > Classical
When high-leverage observations have large residuals. Classical SE is too optimistic: you overstate significance.
Robust < Classical
When high-leverage observations have small residuals. Classical SE is too conservative: you understate significance.

Beyond HC: Clustered Robust SE

When observations are grouped (students within schools, patients within hospitals), errors may be correlated within clusters even if uncorrelated across clusters:

\(\hat{V}_{\text{cluster}} = (X'X)^{-1}\left(\sum_{g=1}^{G} X_g' \hat{e}_g \hat{e}_g' X_g\right)(X'X)^{-1}\)
HC (White)
Handles heteroskedasticity only. Assumes independent errors across all \(i\).
Clustered SE
Handles both heteroskedasticity and within-cluster correlation. Meat sums over cluster-level outer products.

The General Principle

Sandwich Form
\(A^{-1} B \, A^{-1}\)
OLS: HC0-HC3 Heteroskedasticity Clustered SE Within-group correlation HAC (Newey-West) Autocorrelation + heterosk. MLE Sandwich (Huber) Misspecified likelihood models

Common Mistakes

✕ Thinking robust SE fixes the model
Robust SE corrects inference (SE, tests) but does not change \(\hat{\beta}\). If your model is misspecified, the coefficients themselves may still be biased.
✕ Always expecting larger SE
Robust SE can be smaller than classical SE when high-leverage points happen to have small residuals. Don't assume it is always more conservative.
✕ Using HC0 with small \(n\)
HC0 is biased downward in small samples. Use HC2 or HC3 when \(n\) is small or leverage varies widely.
✕ Forgetting to cluster
If data has a natural grouping (panel, multi-level), using HC instead of clustered SE ignores within-group correlation and understates uncertainty.

Summary and Quick Reference

Concept Key Formula / Idea
Sandwich form \((X'X)^{-1}(X'\hat{\Omega}X)(X'X)^{-1}\)
HC0 (White) Meat uses \(e_i^2\): no correction
HC1 Multiply by \(\frac{n}{n-k}\): d.f. correction
HC2 Divide \(e_i^2\) by \(1-h_{ii}\): leverage
HC3 Divide \(e_i^2\) by \((1-h_{ii})^2\): jackknife-like
Clustered SE Sum meat over clusters \(g\)
When to use Default in applied work; essential when heteroskedasticity is suspected

Question 1 of 5

In the sandwich variance estimator \((X'X)^{-1}\hat{M}(X'X)^{-1}\), the "meat" \(\hat{M}\) primarily captures information about:

Question 2 of 5

Under homoskedasticity, what happens when you use robust (HC) standard errors instead of classical SE?

Question 3 of 5

Which HC variant is recommended for small samples with observations that have varying leverage?

Question 4 of 5

A researcher runs OLS and finds that the robust standard error for \(\hat{\beta}_1\) is smaller than the classical SE. Which of the following is the best interpretation?

Question 5 of 5

When should you use clustered standard errors instead of heteroskedasticity-robust (HC) standard errors?