Clustered standard errors

From HandWiki

Clustered standard errors (or Liang-Zeger standard errors)[1] are measurements that estimate the standard error of a regression parameter in settings where observations may be subdivided into smaller-sized groups ("clusters") and where the sampling and/or treatment assignment is correlated within each group.[2][3] Clustered standard errors are widely used in a variety of applied econometric settings, including difference-in-differences[4] or experiments.[5] Analogous to how Huber-White standard errors are consistent in the presence of heteroscedasticity and Newey–West standard errors are consistent in the presence of accurately-modeled autocorrelation, clustered standard errors are consistent in the presence of cluster-based sampling or treatment assignment. Clustered standard errors are often justified by possible correlation in modeling residuals within each cluster; while recent work suggests that this is not the precise justification behind clustering,[6] it may be pedagogically useful.

Intuitive motivation

Clustered standard errors are often useful when treatment is assigned at the level of a cluster instead of at the individual level. For example, suppose that an educational researcher wants to discover whether a new teaching technique improves student test scores. She therefore assigns teachers in "treated" classrooms to try this new technique, while leaving "control" classrooms unaffected. When analyzing her results, she may want to keep the data at the student level (for example, to control for student-level observable characteristics). However, when estimating the standard error or confidence interval of her statistical model, she realizes that classical or even heteroscedasticity-robust standard errors are inappropriate because student test scores within each class are not independently distributed. Instead, students in classes with better teachers have especially high test scores (regardless of whether they receive the experimental treatment) while students in classes with worse teachers have especially low test scores. The researcher can cluster her standard errors at the level of a classroom to account for this aspect of her experiment.[7]

While this example is very specific, similar issues arise in a wide variety of settings. For example, in many panel data settings (such as difference-in-differences) clustering often offers a simple and effective way to account for non-independence between periods within each unit (sometimes referred to as "autocorrelation in residuals").[4] Another common and logically distinct justification for clustering arises when a full population cannot be randomly sampled, and so instead clusters are sampled and then units are randomized within cluster. In this case, clustered standard errors account for the uncertainty driven by the fact that the researcher does not observe large parts of the population of interest.[8]

Mathematical motivation

A useful mathematical illustration comes from the case of one-way clustering in an ordinary least squares (OLS) model. Consider a simple model with N observations that are subdivided in C clusters. Let [math]\displaystyle{ Y }[/math] be an [math]\displaystyle{ n \times 1 }[/math] vector of outcomes, [math]\displaystyle{ X }[/math] a [math]\displaystyle{ n \times m }[/math] matrix of covariates, [math]\displaystyle{ \beta }[/math] an [math]\displaystyle{ m \times 1 }[/math] vector of unknown parameters, and [math]\displaystyle{ e }[/math] an [math]\displaystyle{ n \times 1 }[/math] vector of unexplained residuals:

[math]\displaystyle{ Y = X\beta + e }[/math]

As is standard with OLS models, we minimize the sum of squared residuals [math]\displaystyle{ e }[/math] to get an estimate [math]\displaystyle{ \hat{\beta} }[/math]:

[math]\displaystyle{ \min_\beta (Y-X\beta)^2 }[/math]
[math]\displaystyle{ \Rightarrow X'(Y-X\hat{\beta}) = 0 }[/math]
[math]\displaystyle{ \Rightarrow \hat{\beta} = (X'X)^{-1} X'Y }[/math]

From there, we can derive the classic "sandwich" estimator:

[math]\displaystyle{ V(\hat{\beta}) = V((X'X)^{-1}X'Y) = V(\beta + (X'X)^{-1}X'e) = V((X'X)^{-1}X'e) = (X'X)^{-1}X'ee'X(X'X)^{-1} }[/math]

Denoting [math]\displaystyle{ \Omega \equiv ee' }[/math] yields a potentially more familiar form

[math]\displaystyle{ V(\hat{\beta}) = (X'X)^{-1}X'\Omega X (X'X)^{-1} }[/math]

While one can develop a plug-in estimator by defining [math]\displaystyle{ \hat{e} \equiv Y - X\hat{\beta} }[/math] and letting [math]\displaystyle{ \hat{\Omega} \equiv \hat{e} \hat{e}' }[/math], this completely flexible estimator will not converge to [math]\displaystyle{ V({\hat{\beta}}) }[/math] as [math]\displaystyle{ N \rightarrow \infty }[/math]. Given the assumptions that a practitioner deems as reasonable, different types of standard errors solve this problem in different ways. For example, classic homoskedastic standard errors assume that [math]\displaystyle{ \Omega }[/math] is diagonal with identical elements [math]\displaystyle{ \sigma^2 }[/math], which simplifies the expression for [math]\displaystyle{ V(\hat{\beta}) = \sigma^2 (X'X)^{-1} }[/math]. Huber-White standard errors assume [math]\displaystyle{ \Omega }[/math] is diagonal but that the diagonal value varies, while other types of standard errors (e.g. Newey–West, Moulton SEs, Conley spatial SEs) make other restrictions on the form of this matrix to reduce the number of parameters that the practitioner needs to estimate.

Clustered standard errors assume that [math]\displaystyle{ \Omega }[/math] is block-diagonal according to the clusters in the sample, with unrestricted values in each block but zeros elsewhere. In this case, one can define [math]\displaystyle{ X_c }[/math] and [math]\displaystyle{ \Omega_c }[/math] as the within-block analogues of [math]\displaystyle{ X }[/math] and [math]\displaystyle{ \Omega }[/math] and derive the following mathematical fact:

[math]\displaystyle{ X'\Omega X = \sum_c X'_c \Omega_c X_c }[/math]

By constructing plug-in matrices [math]\displaystyle{ \hat{\Omega}_c }[/math], one can form an estimator for [math]\displaystyle{ V(\hat{\beta}) }[/math] that is consistent as the number of clusters [math]\displaystyle{ c }[/math] becomes large. While no specific number of clusters is statistically proven to be sufficient, practitioners often cite a number in the range of 30-50 and are comfortable using clustered standard errors when the number of clusters exceeds that threshold.

Further reading

References

  1. Liang, Kung-Yee; Zeger, Scott L. (1986-04-01). "Longitudinal data analysis using generalized linear models" (in en). Biometrika 73 (1): 13–22. doi:10.1093/biomet/73.1.13. ISSN 0006-3444. https://academic.oup.com/biomet/article/73/1/13/246001. 
  2. Cameron, A. Colin; Miller, Douglas L. (2015-03-31). "A Practitioner's Guide to Cluster-Robust Inference" (in en). Journal of Human Resources 50 (2): 317–372. doi:10.3368/jhr.50.2.317. ISSN 0022-166X. http://jhr.uwpress.org/content/50/2/317. 
  3. "ARE 212" (in en-US). https://www.fionaburlig.com/teaching/are212. 
  4. 4.0 4.1 Bertrand, Marianne; Duflo, Esther; Mullainathan, Sendhil (2004-02-01). "How Much Should We Trust Differences-In-Differences Estimates?" (in en). The Quarterly Journal of Economics 119 (1): 249–275. doi:10.1162/003355304772839588. ISSN 0033-5533. https://academic.oup.com/qje/article/119/1/249/1876068. 
  5. Yixin Tang (2019-09-11). "Analyzing Switchback Experiments by Cluster Robust Standard Error to prevent false positive results" (in en-US). DoorDash Engineering Blog. https://doordash.engineering/2019/09/11/cluster-robust-standard-error-in-switchback-experiments/. 
  6. Abadie, Alberto; Athey, Susan; Imbens, Guido; Wooldridge, Jeffrey (2017-10-24). "When Should You Adjust Standard Errors for Clustering?". arXiv:1710.02926 [math.ST].
  7. "CLUSTERED STANDARD ERRORS". 2016. https://economictheoryblog.com/2016/09/25/clustered-standard-errors/. 
  8. "When should you cluster standard errors? New wisdom from the econometrics oracle" (in en). https://blogs.worldbank.org/impactevaluations/when-should-you-cluster-standard-errors-new-wisdom-econometrics-oracle.