The full academy launches January 2027. Join the waitlist for the $179 founding price.
Waldbauer Academy of Economics

Courses › Graduate Econometrics

Graduate · Module 5 of 15

Clustering, dependence, and the bootstrap

Cluster-robust variance and the Moulton factor, choosing the level of clustering, few clusters and the wild cluster bootstrap, HAC standard errors, and the theory and practice of the bootstrap.

By Maximus S. Waldbauer · About 5 to 6 hours, including the problem set and quiz.

Module 4’s robust standard errors assume independent observations. Economic data are rarely that tidy. Customers of the same café share its staff and its neighbourhood; students in a class share a teacher; months of one city’s rents share local shocks. When observations are correlated, the effective amount of information is smaller than the sample size suggests, and default standard errors can be wildly too small.

This module covers the main fixes: cluster-robust variance estimators and the logic of choosing the clustering level, what to do with few clusters, heteroskedasticity-and-autocorrelation-consistent (HAC) standard errors for time series, and the bootstrap, a general way to approximate sampling distributions by resampling the data you have.

By the end of this module you will be able to

What this module covers

  1. Clustered errors and the cluster-robust variance
  2. Choosing the level of clustering
  3. When there are few clusters
  4. Serial correlation and HAC standard errors
  5. The bootstrap
  6. Problem set with step-by-step solutions
  7. Module quiz

Lesson 5.1 Free lesson

Clustered errors and the cluster-robust variance

Index observations by cluster g = 1, …, G and member i within the cluster. Stack cluster g’s data as yg = Xgβ + ug. The key assumption is that clusters are independent of each other, while errors within a cluster may be correlated in any way. OLS is unchanged, β̂ − β = (X′X)−1ΣgXg′ug, but the meat of the sandwich must now add up whole clusters:

V̂CR = (X′X)−1 ( Σg Xg′êgêg′Xg ) (X′X)−1

This is the cluster-robust variance estimator (Liang and Zeger, 1986; Arellano, 1987). The outer product êgêg′ keeps every cross-product of residuals within a cluster, so it captures any pattern of within-cluster correlation and any heteroskedasticity. With one observation per cluster it reduces to HC0. Software usually multiplies by c = [G/(G − 1)][(N − 1)/(N − k)], a small-sample correction.

The asymptotics change accordingly. Consistency of V̂CR requires the number of clusters G to grow, not just N. A sample of 1,000,000 people in 10 regions has, for many purposes, about 10 independent pieces of information.

The Moulton factor

How large is the problem? Moulton (1986) worked out a clean case: equal cluster size m, a single regressor with within-cluster correlation ρx, and errors with within-cluster correlation ρu. Then the true variance of the slope relative to the default formula is approximately

Vartrue / Vardefault ≈ 1 + (m − 1) ρx ρu

Both correlations must be present. If the regressor varies freely within clusters (ρx ≈ 0), correlated errors barely matter, because comparisons within clusters difference out the shared shock. If the regressor is constant within clusters (ρx = 1, a policy that applies to the whole school, café or state), the inflation is 1 + (m − 1)ρu, which grows with cluster size.

Worked example: A class-level tutoring program

A tutoring program is assigned to whole classes: 80 classes of 25 students, 2,000 students in all. Test scores of classmates share a correlation of ρu = 0.2, and treatment is constant within class (ρx = 1).

Variance inflation: 1 + 24 × 0.2 = 5.8. The correct SE is √5.8 ≈ 2.41 times the default one.

Effective sample size: 2,000/5.8 ≈ 345 independent students. A default t-statistic of 3 becomes about 1.25 once clustering is accounted for: a “highly significant” effect becomes noise.

The full module has an interactive graph here that you can move yourself.

Key ideas

  • Cluster-robust SEs add residual cross-products within clusters; clusters must be independent of each other.
  • Their validity rests on many clusters, not many observations.
  • Moulton factor: variance inflation ≈ 1 + (m − 1)ρxρu; both correlations are needed.

Practice questions: Clustering, dependence, and the bootstrap

Try these, then open each answer to check your work.

  1. 1.Cluster size is 21, treatment is assigned by cluster, and the within-cluster error correlation is 0.1. By what factor does the correct SE exceed the default SE?
    1. 1.00
    2. 1.41
    3. 1.58
    4. 1.73
    Show answer

    Answer: D. Variance factor 1 + 20 × 1 × 0.1 = 3, so the SE factor is √3 ≈ 1.73.

  2. 2.The usual rule for choosing the level of clustering is to cluster
    1. at the level where treatment is assigned or sampling is clustered
    2. at the individual level in every application
    3. at the largest level available in the data
    4. only when the errors are heteroskedastic
    Show answer

    Answer: A. Clustered assignment and clustered sampling are the two design reasons to cluster (Abadie, Athey, Imbens and Wooldridge).

  3. 3.A study has 8 clusters. What is the main concern with cluster-robust t-tests using normal critical values?
    1. They under-reject badly, making tests too conservative
    2. They over-reject; use t(G − 1), CR2 or a wild cluster bootstrap
    3. They cannot be computed with fewer than ten clusters
    4. They are identical to HC0 when clusters are few
    Show answer

    Answer: B. The cluster-robust estimator needs many clusters; with few, it is biased down and noisy, so tests reject too often.

Problems with step-by-step solutions

  1. 4.Classes of 30 students, treatment assigned by class, and a within-class error correlation of 0.05. Find the Moulton variance and SE inflation.
    Show step-by-step solution
    1. 1 + (m − 1)ρxρu = 1 + 29 × 1 × 0.05 = 2.45.
    2. SE inflation = √2.45 ≈ 1.57. Even a small correlation matters when clusters are large.
  2. 5.In Problem 1, treatment is instead assigned to individual students at random within classes (ρx ≈ 0). What is the inflation?
    Show step-by-step solution
    1. 1 + 29 × 0 × 0.05 = 1: none.
    2. Each class contains both treated and control students, so class-level shocks cancel in the comparison.

Get the full module

The complete module adds every lesson, interactive graphs, a full problem set with step-by-step solutions, and a quiz. The academy opens in January 2027: join the waitlist for the founding price (lifetime access for $179).

Join the waitlist Try a full module free

More practice: free practice questions for this course.