Day 29. OLS Asymptotics & Robust (Sandwich) Variance
Large-sample theory for OLS without normality or homoskedasticity, and the heteroskedasticity- and cluster-robust standard errors applied work relies on.
- ●Prove consistency of OLS using the law of large numbers and the continuous mapping theorem.
- ●Derive the asymptotic sandwich variance and show when it collapses to σ²Q⁻¹.
- ●Compute HC0/HC1 and cluster-robust variances and explain the Moulton problem.
- ●Run Wald tests of joint hypotheses with a robust covariance matrix.
Theory
Assumptions for large samples
Drop normality and homoskedasticity. Assume iid observations with
Consistency
by the LLN applied to each average and the continuous mapping theorem (continuous functions preserve convergence in probability).
Asymptotic normality: the sandwich
By the CLT, with . By Slutsky's theorem,
"Bread–meat–bread". Its sample analogue is the heteroskedasticity-robust (HC0, White) estimator
with HC1 multiplying by (Stata's robust). Under homoskedasticity, , so and the sandwich collapses to , the classical formula.
Clustered data
If errors are correlated within clusters but independent across them,
Its reliability depends on the number of clusters , not the number of observations. With few clusters (say under 30–50), use small-sample corrections or the wild cluster bootstrap.
Causal link. Treatment is often assigned at the cluster level (schools, villages, states). Inference must then be clustered at the level of assignment, or standard errors can be badly understated.
Part 1 · Warm-up
Exercise 1 · A scalar sandwich
In a no-intercept regression , write the classical and the HC0 variance of .
Show solution
Step 1. Classical: .
Step 2. HC0: .
Step 3. The robust version weights each squared residual by its .
Exercise 2 · Numbers
Take and residuals (no intercept, ). Compute both variances.
Show solution
Step 1. .
Step 2. Classical: , so .
Step 3. HC0: , so .
Answer: 0.0536 (classical) versus 0.0332 (robust). (These residuals satisfy , as OLS residuals must.)
Exercise 3 · HC1
Apply the HC1 correction to Exercise 2.
Show solution
: .
Exercise 4 · When do they agree?
Under what condition do classical and robust SEs agree in large samples, and what does a large gap suggest?
Show solution
Under homoskedasticity (more precisely, when is uncorrelated with ). A large gap signals heteroskedasticity, or sometimes model misspecification.
Exercise 5 · Counting clusters
A study has 10,000 pupils in 20 schools, with treatment assigned by school. How much information is there for inference on the treatment effect?
Show solution
Effectively 20 clusters (10 treated, 10 control). Cluster-robust inference treats each school as one draw; with so few, use a reference distribution or the wild cluster bootstrap.
Part 2 · Proofs
Exercise 6 · Consistency
Prove under the assumptions above.
Show solution
Step 1. Substitute into :
Step 2. LLN, applied entry by entry: .
Step 3. LLN again: .
Step 4. Matrix inversion is continuous at the invertible , so by the continuous mapping theorem the product converges to .
Step 5. Note what was not needed: normality, homoskedasticity, or even ; only .
Exercise 7 · The sandwich
Derive .
Show solution
Step 1. Scale Step 1 of Exercise 6 by : , with .
Step 2. The vectors are iid with mean 0 and covariance . The multivariate CLT gives .
Step 3. (Exercise 6).
Step 4. Slutsky: with .
Step 5. By Day 22, ( is symmetric). So the limit is .
Exercise 8 · Homoskedasticity collapses the sandwich
Show that if then .
Show solution
By the LIE, . So .
Exercise 9 · The linear probability model is heteroskedastic
For a binary outcome with , show .
Show solution
Step 1. and is Bernoulli(), so , which varies with .
Step 2. Robust SEs are mandatory for linear probability models.
Exercise 10 · Robust SE of a difference in means
In , show that the HC0 variance of equals with plug-in (divide-by-) group variances.
Show solution
Step 1. By FWL (Day 28), the slope uses the demeaned treatment , where : . Its HC0 variance is .
Step 2. Ingredients: for treated and for controls; (deviation from own group mean); .
Step 3. Numerator, writing : .
Step 4. Divide by and use , :
Answer: the robust SE of a regression on a treatment dummy is Neyman's unequal-variance SE from Day 9.
Part 3 · Applied
Exercise 11 · Consumption, income and heteroskedasticity
In household data, consumption varies much more among high-income than low-income households. Model this as with (income standardised). Predict whether classical SEs for the marginal propensity to consume over- or under-state its uncertainty, and check by simulation (code below).
Show solution
Step 1. The slope is driven by households far from mean income, where is large.
Step 2. Here the error variance is largest exactly for those households.
Step 3. The classical formula uses one average error variance for everyone, so it ignores that the influential observations are also the noisiest.
Answer: classical SEs understate the uncertainty. In the simulation, classical 95% intervals cover only about 76% of the time, while HC1 robust intervals cover about 94.5%.
Exercise 12 · The Moulton factor
The regressor is constant within clusters of size and the error's intra-cluster correlation is 0.1. By how much are classical SEs too small?
Show solution
Step 1. Moulton factor for the variance: .
Step 2. SE factor: .
Answer: classical SEs are about 2.4 times too small: a reported might really be .
Exercise 13 · A joint Wald test
Two coefficients are estimated at with robust covariance . Test that both are zero.
Show solution
Step 1. with , so .
Step 2. .
Step 3. Reference: , 5% critical value 5.99.
Answer: : reject that both coefficients are zero. In general with degrees of freedom.
Exercise 14 · Few clusters
A state-level policy is studied with 6 treated and 44 control states. Why can cluster-robust SEs mislead, and what do practitioners do?
Show solution
Step 1. The cluster-robust "meat" is a sum over clusters; it is reliable only with many clusters, especially many treated ones.
Step 2. With 6 treated states, those few clusters' residuals dominate, so the variance estimate is noisy and typically biased downward.
Step 3. Remedies: the wild cluster bootstrap (with restricted residuals), randomisation inference across states, or synthetic-control methods (Phase 6).
Answer: standard cluster-robust SEs are too small with few treated clusters; use one of the remedies.
Exercise 15 · Exogeneity versus orthogonality
The asymptotic results need only . Why does causal interpretation usually require the stronger ?
Show solution
Step 1. For the best linear predictor of given , the error is defined so that ; OLS always estimates those projection coefficients consistently.
Step 2. A causal reading needs a structural error: all other causes of .
Step 3. for that error says the regressors are unrelated to every omitted cause: the identifying assumption.
Answer: asymptotic theory delivers precision for whatever estimates; whether that is a causal effect depends on identification.
Verify in Python
import numpy as np
rng = np.random.default_rng(29)
n, reps, beta = 200, 4000, 1.0
cover_cl = cover_hc = 0
for _ in range(reps):
x = rng.normal(size=n); y = 1 + beta * x + np.abs(x) * rng.normal(size=n)
X = np.column_stack([np.ones(n), x]); XtXi = np.linalg.inv(X.T @ X)
b = XtXi @ X.T @ y; e = y - X @ b
v_cl = (e @ e / (n - 2)) * XtXi[1, 1]
v_hc = (XtXi @ (X.T * e**2) @ X @ XtXi)[1, 1] * n / (n - 2) # HC1
cover_cl += abs(b[1] - beta) <= 1.96 * np.sqrt(v_cl)
cover_hc += abs(b[1] - beta) <= 1.96 * np.sqrt(v_hc)
print(f"95% CI coverage: classical {cover_cl / reps:.3f}, robust HC1 {cover_hc / reps:.3f}")
x = np.array([1, 2, 3.]); e = np.array([0.5, -1, 0.5])
print("classical:", round((e @ e / 2) / (x @ x), 4), " HC0:", round((x**2 * e**2).sum() / (x @ x)**2, 4))
print("Wald:", 0.3**2 / 0.01 + 0.2**2 / 0.01, " Moulton SE factor:", round(np.sqrt(1 + 49 * 0.1), 2))
Key takeaways
- OLS is consistent and asymptotically normal under weak conditions; its variance is a sandwich.
- Use heteroskedasticity-robust SEs by default, and cluster at the level of treatment assignment.
- Asymptotic theory tells you how precise is, not whether it is causal.
Simulation Lab: Heteroskedasticity & Robust Standard Errors
Open full screen →Fan-shaped errors make classical intervals under-cover; robust (sandwich) intervals restore 95%.
Errors have sd √(0.25 + δx²): they fan out at extreme x, exactly where the slope is decided. 1,500 simulated samples compare the average reported SE with the true sampling sd of β̂₁, and the coverage of 95% intervals.