Tutorials › Propensity Score Matching and Instrumental Variables › Cluster-Robust 2SLS Inference

Two-Stage Least Squares · Tutorial 493 of 699

Cluster-Robust 2SLS Inference

Build cluster-robust 2SLS standard errors from cluster-level score contributions and use them for inference when observations may be dependent within groups.

Advanced 13 min read

What You'll Learn

  • State the rank conditions needed to define the 2SLS estimator and its variance.
  • Construct each cluster’s 2SLS score contribution from instrument moments.
  • Calculate a cluster-robust variance, standard error, test statistic, and p-value.
  • Explain why independent clusters, rather than independent observations, determine the relevant asymptotics.
  • Distinguish cluster-robust inference from heteroskedasticity-robust inference.
  • Recognize few-cluster, weak-identification, and dominant-cluster warning signs.

Why Cluster the 2SLS Inference?

In instrumental variables analyses, observations may share a source of dependence: patients treated in the same clinic, students in the same school, or repeated records from the same person. Even if the instrument-based estimator is appropriate, treating those observations as independent can understate uncertainty. Cluster-robust 2SLS inference allows errors to be correlated in arbitrary ways within a cluster while relying on independence across clusters.

The key calculation is not to take each observation’s contribution to a fitted-regressor residual and simply group those contributions. Instead, 2SLS first transforms the instrument moments into coefficient-scale contributions. The valid cluster “meat” of the sandwich is formed by summing those transformed contributions within each cluster, then taking their outer products.

Model, Rank Conditions, and Cluster Scores

Let \(y\) be an \(n \times 1\) outcome vector, \(X\) an \(n \times k\) matrix of structural regressors, and \(Z\) an \(n \times L\) matrix of instruments. The structural equation is \(y=X\beta+u\). The columns of \(Z\) include the instruments used for the columns of \(X\), including any exogenous regressors that belong in the instrument set. Partition the observations into \(G\) clusters; \(Z_g\) and \(\hat u_g\) denote the rows for cluster \(g\).

For the formula below, assume \(Z'Z\) is invertible and define \(P_Z=Z(Z'Z)^{-1}Z'\). Also require \(A=X'P_ZX\) to be invertible. This second rank condition is essential: invertibility of \(Z'Z\) alone does not guarantee that the 2SLS coefficient is defined. The estimator and residuals are

$$ \hat\beta=A^{-1}X'P_Zy, \qquad \hat u=y-X\hat\beta. $$

Underidentification or inadequate sample rank can make \(A\) singular. Even when the sample matrices are invertible, weak instruments can make inference unreliable; clustered standard errors do not repair weak identification.

Definition: The uncorrected cluster-robust 2SLS variance estimator is $$ \widehat{\operatorname{Var}}_{\mathrm{CR}}(\hat\beta) =A^{-1}\left(\sum_{g=1}^{G}\hat b_g\hat b_g'\right)A^{-1}, \qquad \hat b_g=X'Z(Z'Z)^{-1}Z_g'\hat u_g. $$ Here \(\hat b_g\) is the \(k \times 1\) cluster score contribution on the coefficient scale. The cluster-robust standard error for coefficient \(j\) is the square root of diagonal entry \(j\) of this variance matrix.

This is a sandwich: \(A^{-1}\) is the “bread,” while the sum of cluster score outer products is the “meat.” The formula is uncorrected for finite-sample adjustments. It is motivated by many-cluster asymptotics, not a guarantee of accurate inference with a small number of clusters.

Why the Cluster Contribution Has This Form

The 2SLS normal equations give \(X'P_Z(y-X\hat\beta)=0\). To see the source of the variance formula, write the estimation error using the structural equation:

$$ \hat\beta-\beta =A^{-1}X'P_Zu =A^{-1}X'Z(Z'Z)^{-1}Z'u =A^{-1}\sum_{g=1}^{G}X'Z(Z'Z)^{-1}Z_g'u_g. $$

This identity expresses the estimation error as a sum of cluster-level contributions premultiplied by \(A^{-1}\). If the clusters are independent, the covariance of that sum is the sum of the cluster contribution covariance matrices. Replacing the unobserved errors with the fitted residuals produces the stated sandwich estimator.

The derivation also explains why the contribution is \(\hat b_g=X'Z(Z'Z)^{-1}Z_g'\hat u_g\). The same global matrix transforms every cluster’s instrument moment into coefficient scale. In general, it is not correct to substitute \(\hat X_g'\hat u_g\), where \(\hat X=P_ZX\), for this score: that expression does not generally reproduce the 2SLS influence contribution for cluster \(g\).

The variance estimator is appropriate when observations can be dependent within a cluster but clusters are independent, and the number of independent clusters is sufficiently large for the approximation to be credible. Standard regularity conditions also require adequate instrument relevance, finite moments, and that no small number of clusters dominate the total information. Within-cluster correlation need not have a particular pattern; it can include unequal variances and arbitrary covariance among observations in the same cluster.

Worked Example: A Scalar IV Estimate With 20 Clusters

Suppose a hypothetical through-the-origin model has one endogenous regressor \(x\), one instrument \(z\), and 20 independent clusters. The following table gives each of four cluster types’ summary moments; there are five distinct clusters of each type. The quantities \(z'x\), \(z'y\), and \(z'z\) are calculated within a cluster.

Cluster typeNumber of clusters\(z'x\)\(z'y\)\(z'z\)
A5252
B5352
C54102
D5582

The totals are \(z'x=5(2+3+4+5)=70\), \(z'y=5(5+5+10+8)=140\), and \(z'z=5(2+2+2+2)=40\). Since \(z'z>0\) and the scalar \(A=x'P_Zx=(z'x)^2/(z'z)\) is positive, the estimator is defined:

$$ \hat\beta=\frac{z'y}{z'x}=\frac{140}{70}=2, \qquad A=\frac{70^2}{40}=122.5. $$

For a cluster, its instrument residual moment is \(z_g'\hat u_g=z_g'y_g-\hat\beta z_g'x_g\). The four type-specific values are \(1,-1,2,-2\). The coefficient-scale multiplier is \(x'z/(z'z)=70/40=1.75\), so the cluster scores are \(1.75,-1.75,3.5,-3.5\), each repeated five times. Therefore,

$$ \sum_g \hat b_g^2 =5(1.75^2+(-1.75)^2+3.5^2+(-3.5)^2) =153.125, \qquad \widehat{\operatorname{Var}}_{\mathrm{CR}}(\hat\beta) =\frac{153.125}{122.5^2}=0.01020. $$

The standard error is \(\sqrt{0.01020}=0.1010\). To test \(H_0:\beta=0\), the large-cluster normal statistic is \(z=2/0.1010=19.80\), with a two-sided normal-reference p-value below \(0.0001\). This is strong evidence against that null under the stated model and approximation. The estimate is in outcome units per one-unit increase in \(x\). The calculation presumes the 20 clusters are independent; a large statistic cannot compensate for a violation of that assumption.

Why Clustering Can Change the Result

Heteroskedasticity-robust 2SLS inference allows unequal observation-level variances but treats the observation-level contributions as independent. Cluster-robust inference instead sums contributions within each cluster before forming outer products. This retains the covariance terms between observations in the same cluster. If those terms are positive, the clustered variance can be larger; it is not guaranteed to be larger in every data set.

Worked Example: Within-Cluster Covariance Matters

Consider a hypothetical just-identified scalar IV calculation with three clusters and two observations per cluster. Suppose the cluster summaries are \(z'x=(1,2,3)\), \(z'y=(3.5,0,5.5)\), and \(z'z\) sums to 6. The sample rank conditions hold because \(z'z=6>0\) and \(x'P_Zx=6^2/6=6>0\). The estimate is \(\hat\beta=9/6=1.5\). The cluster residual instrument moments \(z_g'\hat u_g=z_g'y_g-1.5z_g'x_g\) are \(2,-3,1\), which sum to zero.

Here \(x'z/(z'z)=6/6=1\), so the coefficient-scale cluster scores are also \(2,-3,1\). The clustered meat is \(2^2+(-3)^2+1^2=14\). Thus the variance is \(14/6^2=0.3889\), and the standard error is \(\sqrt{0.3889}=0.6236\).

To illustrate what an observation-level calculation can miss, suppose each cluster’s total score is split equally between its two observations. The six individual scores are then \(1,1,-1.5,-1.5,0.5,0.5\). Their squared sum is \(7\), half the clustered meat of 14. The resulting observation-level variance would be \(7/36=0.1944\), with standard error \(0.4410\). That smaller value omits the within-cluster cross-products. With only three independent clusters, neither large-cluster approximation should be treated as dependable; the numbers illustrate the calculation, not a reliable p-value.

Inference With Several Coefficients

For multiple regressors, the same calculation produces a covariance matrix. The diagonal entries give coefficient variances, while off-diagonal entries represent estimated covariance between coefficient estimates. For a single-coefficient test of \(H_0:\beta_j=\beta_{j,0}\), divide the estimate’s difference from the null value by its cluster-robust standard error. With many independent clusters and suitable regularity conditions, this statistic is approximately standard normal under the null.

Worked Example: A Two-Coefficient Cluster-Robust Test

Suppose a hypothetical 2SLS fit has two coefficients, estimates \(\hat\beta=(0.8,-0.4)'\), and \(A=\begin{pmatrix}100&0\\0&50\end{pmatrix}\). There are 30 independent clusters, with the following three score vectors repeated ten times:

Score patternFirst coefficientSecond coefficient
121
2-12
3-1-3

The three scores sum to zero, as expected from the 2SLS normal equations. Their outer products sum to \(\begin{pmatrix}6&3\\3&14\end{pmatrix}\); repeating the patterns ten times gives meat \(\begin{pmatrix}60&30\\30&140\end{pmatrix}\). Since \(A^{-1}=\begin{pmatrix}0.01&0\\0&0.02\end{pmatrix}\), the variance matrix is

$$ \widehat{\operatorname{Var}}_{\mathrm{CR}}(\hat\beta) = \begin{pmatrix}0.01&0\\0&0.02\end{pmatrix} \begin{pmatrix}60&30\\30&140\end{pmatrix} \begin{pmatrix}0.01&0\\0&0.02\end{pmatrix} = \begin{pmatrix}0.006&0.006\\0.006&0.056\end{pmatrix}. $$

The standard error of the second coefficient is \(\sqrt{0.056}=0.2366\). For \(H_0:\beta_2=0\), the statistic is \(-0.4/0.2366=-1.690\), giving a two-sided standard-normal p-value of approximately \(0.091\). At the 5% level, this test does not reject the null. If the first coefficient measures a treatment effect in outcome units per treatment unit, its standard error is \(\sqrt{0.006}=0.07746\) in those same units. The reported standard errors rely on the independent-cluster approximation.

Diagnostics, Alternatives, and Limitations

Before trusting clustered inference, verify how clusters are defined and whether independence across them is plausible. The relevant cluster should correspond to the dependence structure or sampling and assignment design, not be selected because it produces a preferred standard error. Check the number and sizes of clusters, whether a few clusters dominate the score sum, and whether the model’s rank and instrument-strength conditions are credible. A cluster score table or plot can reveal a small number of clusters contributing unusually large values.

  • Few independent clusters: the large-\(G\) approximation can be poor even if the total number of observations is large. Cluster-robust inference is not automatically reliable simply because a data set has many rows.
  • Dependence across clusters: if clusters share shocks or otherwise remain dependent, the independence justification fails. Clustering at one level does not solve dependence at a different level.
  • Dominant clusters: a handful of very large or influential cluster scores can undermine the many-cluster approximation.
  • Weak instruments or rank failure: cluster-robust standard errors address the covariance structure, not weak identification or a singular \(A\).

Use heteroskedasticity-robust 2SLS inference when observation-level contributions can reasonably be treated as independent but their variances may differ. Use cluster-robust inference when dependence within defined groups is plausible and clusters are independent. Conventional homoskedastic 2SLS inference requires stronger error-variance assumptions. If dependence extends over ordered time or space, the appropriate covariance approach may differ; the name HAC standard errors refers to a distinct approach.

A common mistake is to calculate an observation-level robust variance and then assume that grouping the reported standard errors, or using fitted regressors in the cluster sum, automatically makes it cluster robust. Neither operation forms the required score. The correction is to calculate \(Z_g'\hat u_g\) within each cluster, transform it using \(X'Z(Z'Z)^{-1}\), and then form the sum of cluster score outer products. A second mistake is to interpret a small cluster-robust standard error as proof that the instrument is valid or strong. The covariance estimator cannot establish the IV assumptions.

Key takeaway: Cluster-robust 2SLS inference depends on independent clusters. Form each cluster’s contribution from its instrument residual moment, transform that moment to coefficient scale, and use the resulting outer products in the sandwich variance.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. Why does invertibility of \(Z'Z\) not by itself guarantee that the 2SLS estimator is defined?
  2. In a scalar IV model, suppose \(A=12\) and the cluster score contributions are \(2,-1,-1\). Calculate the uncorrected cluster-robust variance and standard error.
  3. Why can an observation-level heteroskedasticity-robust variance be smaller than the cluster-robust variance?
  4. What is the relevant independence assumption for the large-cluster approximation, and name one warning sign that can make it unreliable.

Solutions. (1) The estimator also requires \(A=X'P_ZX\) to be invertible; \(Z'Z\) can be invertible while \(A\) is singular. (2) The meat is \(2^2+(-1)^2+(-1)^2=6\), so the variance is \(6/12^2=0.04167\), and the standard error is \(\sqrt{0.04167}=0.2041\). (3) Observation-level meat omits cross-products between contributions from observations in the same cluster; positive within-cluster covariance can make the cluster meat larger. (4) Clusters must be independent of one another, while observations within a cluster may be dependent. Few clusters or a few dominant cluster scores are warning signs.

Clinical Biostats