Standard way to cluster standard errors
Clustering standard errors can make or break papers. In this post, I discuss what are considered standard approaches to clustering standard errors, particularly focusing on asset pricing and corporate settings. I benefited from discussions with Fulin Li.
Why is clustering necessary?
When the residuals are correlated across observations, OLS standard errors can be biased.
For a finance application, this is very reasonable. For example, consider a panel dataset indexed by time \(t\) and asset/firm \(i\). In this case, the residuals will likely be correlated across time (e.g. assets/firms have persistent characteristics) and across firms (e.g. common shocks at time \(t\) that affect different assets/firms heterogeneously)
The Mechanics of Clustering
In a standard derivation of standard errors for OLS estimates, one needs an estimate of \(\Omega\), the variance-covariance matrix of residuals.
Depending on the nature of the regression, more assumptions are imposed on the structure of this matrix. For instance:
- Huber-White standard errors: These are the heteroskedasticity-consistent standard errors where \(\Omega\) is now the diagonal matrix whose diagonal elements are \(\hat{e}_i^2\).
- Newey-West standard errors: In addition to correcting for heteroscedasticity, Newey-West standard errors also correct for autocorrelation.
Clustered standard errors assume \(\Omega\) is block-diagonal according to the clusters in the sample.
Fixed Effects vs. Clustering
It is often assumed that including fixed effects eliminates the need for clustering. This is not entirely True. This point is quite well made in Petersen (2009) which I summarize below.
A. Time FE vs. Clustering by Time
- Fixed Time Effect: If the time effect is fixed, i.e.
\(\epsilon_{it} = \delta_t +\eta_{it}, \quad X_{it} = \zeta_t +\nu_{it}\)
then one can (i) cluster standard errors by time, (ii) add time dummies in the regression, or (iii) use Fama-MacBeth procedure.
- Recall that in the Fama-MacBeth procedure, the researcher runs \(T\) cross-sectional regressions and uses the average of the \(T\) estimates as the coefficient estimate and \(\frac{1}{T}\sum_{t=1}^T\frac{(\hat{\beta}_t-\hat{\beta}_{FM})^2}{T-1}\) as the estimated variance. While this approach is robust to both fixed and temporary time effects, it is not robust to the presence of a firm effect.
- Temporary Time Effect: Now suppose \(Corr(\epsilon_{it}, \epsilon_{jt})\) changes across \((i,j)\) pairs due to a factor structure in residuals: \(\epsilon_{it} = \beta_i\delta_t +\eta_{it}, \quad X_{it} = \zeta_t +\nu_{it}\) then one can (i) cluster standard errors by time or (ii) use Fama-MacBeth procedure. Using time dummies, however, will not produce unbiased standard errors.
B. Firm FE vs. Clustering by Firm
- Fixed Firm Effect: If the firm effect is fixed, i.e. \(\epsilon_{it} = \gamma_i+\eta_{it}, \quad X_{it} = \mu_i+\nu_{it}\) then one can (i) cluster standard errors by firm, and (ii) add firm dummies in the regression.
- Temporary Firm Effect: Now suppose \(Corr(\epsilon_{it}, \epsilon_{it-k})\) declines with \(k\). Then one should cluster standard errors by firm. Using firm dummies, however, will not produce unbiased standard errors.
Two-Way Clustering
How does clustering work in a multi-way clustering setting? This is best explained by this excerpt from Cameron and Miller (2015):

What this post also implies is that one should not create a new variable that has a unique value for each firm-time pair and use one-way clustering on this variable. (See this post for a short discussion).
If \(N\to\infty\) and \(T\to\infty\), then one can always do two-way clustering. However, if \(N\) or \(T\) is small, then two-way clustering may be subject to small sample bias and thus may not necessarily be “better” than one-way clustering.
Implementation Rule of Thumb
- In general, the right level to cluster is at the level at which the “shock” hits.
- Using the notation above, one should think about whether \(\delta_t\) and \(\gamma_i\) is meaningfully large enough to take clustering seriously.
- Theoretically, clustering can make your standard errors larger or smaller, but typically it makes them larger. In fact, clustering can decrease standard errors if the intra-cluster correlations are negative, as explained in this post.
- If you’re dealing with returns, especially in an asset pricing application, you should always cluster by time.
- This is because there is a known factor structure in returns and firm-specific factor loadings. This corresponds to the setup from earlier: \(\epsilon_{it} = \beta_i\delta_t +\eta_{it}, \quad X_{it} = \zeta_t +\nu_{it}\)
- If you cluster at the highest possible level, you are proceeding in a conservative way. In this spirit, it is recommended to use bigger and more aggregate clusters when possible, up to the point at which there is concern about having too few clusters.
- If you cluster at the city level as opposed to state level, then you’re implicitly imposing that across cities within the state the errors are uncorrelated.
- It is useful to check the three types of clustering (by firm, by time, both by firm and time) and see how they compare to White stderr. If one is considerably larger than the other, it points to the presence of that effect. Alternately, one could check the covariance matrix of the fitted residuals. Either approach is informative about the correlation structure of the residuals.
Useful References
- Petersen (2009), “Estimating Standard Errors in Finance Panel Data Sets: Comparing Approaches”
- Cameron and Miller (2015), “A Practitioner’s Guide to Cluster-Robust Inference”