Why Cluster-Robust Inference Matters in DiD
A DiD data set can contain many observations without containing many independent pieces of information. For example, thousands of patients may be observed in a small number of hospitals, while treatment is assigned at the hospital level. Outcomes for patients in the same hospital may share shocks, policies, or measurement practices. Treating all patients as independent can therefore make a DiD estimate appear more precise than the design supports.
Cluster-robust inference addresses this dependence by allowing observations within a cluster to be correlated. It does not change the DiD regression coefficient, determine which population is being averaged over, or establish a causal effect. Those are separate questions: the coefficient depends on the regression and its weighting, causal interpretation depends on identifying assumptions such as parallel trends, and the cluster-robust variance estimates uncertainty under a specified dependence structure.
In DiD, a useful default is to cluster at the level at which treatment is assigned, or at a broader level at which relevant shocks may be shared. If policy adoption is determined by state, for example, individuals or counties in the same state are not automatically independent sources of treatment variation. The exact choice still requires a design-based argument: clustering cannot protect against dependence that crosses the chosen cluster boundaries.
The DiD Regression and Its Clustered Variance
For a two-period DiD, a familiar regression is
Here \(Y_{it}\) is the outcome for unit \(i\) at time \(t\); \(Post_t\) indicates the post-intervention period; and \(Treat_i\) indicates membership in the treated group. In this specification, the coefficient \(\hat{\tau}\) on the interaction is the regression DiD estimate. In repeated-period or covariate-adjusted specifications, the design matrix \(X\) contains the corresponding terms, and the same cluster-robust construction applies to the fitted regression.
Let \(g=1,\ldots,G\) index clusters. Write \(X_g\) for the rows of the regression design matrix belonging to cluster \(g\), and \(\hat{u}_g\) for the vector of OLS residuals in that cluster. The unadjusted cluster-robust, or CR0, covariance estimator is
The middle term is often called the “meat” of the sandwich. Each cluster contributes its whole score product \(X_g'\hat{u}_g\hat{u}_g'X_g\), including cross-products between observations in that cluster. Those cross-products are precisely what would be lost by treating each row as independent. The estimated variance of \(\hat{\tau}\) is the diagonal entry of \(\widehat{V}_{CR0}\) corresponding to the interaction coefficient; its standard error is the square root of that entry.
A common finite-sample adjustment is CR1:
where \(N\) is the number of regression observations and \(K\) is the number of estimated regression coefficients, including the intercept. This is one common convention, not a universal definition: software may use different corrections or degrees-of-freedom rules. The adjustment scales the estimated covariance matrix; it does not alter the OLS coefficients or make a small number of clusters behave like a large one.
Why the Number of Clusters Matters
The sandwich is built from \(G\) cluster-level score contributions, not from \(N\) independent contributions. When there are many observations per cluster but few clusters, the apparent sample size \(N\) can be large while the information relevant to the cluster-robust approximation remains limited. A large number of rows does not, by itself, justify using a normal approximation for a cluster-robust test.
For large-cluster inference, a coefficient is commonly tested using a Wald statistic: subtract the null value from the estimate and divide by its cluster-robust standard error. Reference distributions and degrees-of-freedom conventions vary; a \(t\) reference with \(G-1\) degrees of freedom is one common choice. Whatever convention is used, the number of independent clusters should be reported and considered. A CR1 multiplier is a modest correction, not a remedy for a very small \(G\). In that setting, specialized small-cluster inference is needed.
Worked Example: Computing a DiD Interaction
Suppose a hypothetical program is introduced in one set of districts. The average outcome is 50 points before and 56 points after in treated districts, and 48 points before and 51 points after in comparison districts. The two-period, two-group regression includes the treatment indicator, the post indicator, and their interaction. What is the interaction estimate?
The treated group changes by \(56-50=6\) points. The comparison group changes by \(51-48=3\) points. Therefore,
In this saturated two-by-two regression, the interaction coefficient equals this difference in changes. It is a causal effect only under the relevant DiD identification assumptions, including parallel trends in the absence of treatment and no anticipation over the periods used. Cluster-robust standard errors address the dependence structure used for inference; they do not establish those assumptions.
Clustering Does Not Choose the Estimand
The clustering level and the weighting in the regression answer different questions. Clustering specifies which observations may have correlated errors for the variance calculation. Weighting determines how observations or groups contribute to the point estimate. Changing the cluster variable while holding the regression and sample fixed ordinarily leaves its OLS coefficient unchanged, although its standard error may change. Changing weights or the regression specification can change the coefficient and thus the estimand.
For example, an unweighted regression on individual records generally gives more total influence to larger clusters than to smaller ones. A regression using one equally weighted observation per cluster instead targets a different average when cluster sizes differ. Merely declaring clusters for the variance calculation does not convert the first regression into the second.
Worked Example: Unequal Cluster Sizes and Different Averages
Consider hypothetical cluster-level outcome changes, measured in points. Three treated clusters have changes \(2,2,8\), and three comparison clusters each have a change of \(0\). Suppose the treated clusters contain \(10,10,\) and \(100\) individuals, respectively, while the comparison clusters together contain 40 individuals, all with change \(0\). Compare an equal-cluster contrast with an individual-weighted contrast.
With equal weight for each cluster, the treated mean change is \((2+2+8)/3=4\) points, and the comparison mean is \(0\). The equal-cluster contrast is therefore \(4-0=4\) points.
If instead the treated change is averaged over individuals, the weighted treated mean is
The individual-weighted comparison mean remains \(0\), so this contrast is \(7\) points. The difference arises from weighting: the large treated cluster has more influence in the individual-weighted calculation. A cluster-robust variance calculation does not decide between these two targets. The small number of clusters here also means that this example should not be taken as support for conventional large-cluster inference.
A Short Derivation and a Numerical Variance Calculation
The sandwich formula follows from the OLS score representation. Conditional on the design matrix, write \(A=X'X\). The OLS estimation error is
If cluster errors have mean zero conditional on \(X\), and distinct clusters are independent, the variance of the sum is the sum of its cluster variances. Thus
This step does not require independent errors within a cluster: \(\operatorname{Var}(\varepsilon_g\mid X)\) may have nonzero off-diagonal entries. Replacing the unknown errors by OLS residuals gives the CR0 estimator. The large-\(G\) justification is that the aggregate variation in the independent cluster score contributions can be estimated from their observed counterparts, subject to regularity conditions and no cluster dominating the total information.
Worked Example: Cluster-Robust Standard Error for a DiD Contrast
For a transparent calculation, suppose each of eight independent hypothetical clusters contributes one outcome change, measured in points. Four treated-cluster changes are \(3,4,2,3\), and four comparison-cluster changes are \(1,0,2,1\). Regressing the cluster changes on an intercept and a treated-cluster indicator gives the difference in the two group means.
The treated mean is \((3+4+2+3)/4=3\) points; the comparison mean is \((1+0+2+1)/4=1\) point. Hence the estimated contrast is \(\hat{\tau}=3-1=2\) points. The residuals within each group are \(0,1,-1,0\), so the residual sum of squares in each group is \(2\).
For this intercept-and-indicator regression, the CR0 variance for the difference in means is the treated residual sum of squares divided by the square of the treated cluster count, plus the corresponding comparison term:
Thus \(SE_{CR0}(\hat{\tau})=\sqrt{1/4}=0.5000\) points. Here \(N=G=8\) and \(K=2\), so the stated CR1 convention multiplies the variance by
The adjusted variance is \((4/3)(1/4)=1/3\text{ points}^2\), and the adjusted standard error is \(\sqrt{1/3}\approx0.5774\) points. This calculation illustrates the mechanics, not a reliable large-cluster test: eight clusters are few for standard cluster-asymptotic inference. It also shows why the CR1 adjustment must be applied to the unrounded variance, rather than by multiplying rounded intermediate values.
Practical Choices and a Common Pitfall
Before reporting a clustered DiD result, make the dependence argument explicit. Ask what units receive treatment, which units share shocks that could induce residual dependence, and whether the proposed clusters can reasonably be treated as independent. Then report the number of clusters, the clustering level, the coefficient, and the standard error. If treatment is assigned at the state level, for instance, the number of individual records is not a substitute for the number of states when describing the basis of the cluster-robust approximation.
Common mistake: “There are 5,000 individual observations, so the cluster-robust standard error is based on a large sample.” This reasoning counts rows as if they supplied independent cluster information. If those records are nested in 12 states and the relevant dependence is within state, the sandwich aggregates scores into only 12 contributions. The correction is to report and evaluate the cluster count itself, and not to interpret the number of rows as the number of independent units for clustered inference.
A second mistake is to say that clustering at a different level “changes the DiD effect.” Holding the fitted OLS regression and observations fixed, changing the variance estimator changes uncertainty estimates, not the OLS interaction coefficient. If the point estimate changes, then something else has changed too, such as the weights, sample, or regression specification. Neither a small standard error nor a large cluster count repairs a failure of parallel trends; those are distinct inferential and causal questions.
Check Your Understanding
Answer each question by distinguishing the regression estimate, the dependence assumptions, and the causal interpretation.
- In a DiD regression with 2,000 individuals nested in 10 states, why is the number 2,000 not the relevant count for the cluster-level approximation if errors may be dependent within state?
- What part of the cluster-robust sandwich allows arbitrary error correlation within a cluster?
- A researcher changes only the clustering variable while keeping the regression fixed. Which quantities may change, and which OLS quantity does not?
- In the unequal-size example, why did the individual-weighted contrast differ from the equal-cluster contrast?
- Does a cluster-robust standard error establish parallel trends? Explain why or why not.