Tutorials › Econometrics (Graduate) › Nested and Crossed Cluster Structures

Clustered and Dependent Errors · Tutorial 133 of 952

Nested and Crossed Cluster Structures

Distinguish nested from crossed clustering and match the covariance estimator to the way observations may share dependence.

Advanced 12 min read

What You'll Learn

  • Identify when units such as students and teachers are nested within schools, and when clustering dimensions are crossed.
  • State the dependence assumptions behind one-way and two-way cluster-robust covariance estimators.
  • Calculate a one-way cluster-robust standard error from cluster score sums.
  • Apply the inclusion–exclusion formula for two-way clustering.
  • Recognize why clustering only on a nested subgroup or only one crossed dimension can miss dependence.

Why the Clustering Structure Matters

Cluster-robust inference allows observations within a cluster to have dependent errors. But “cluster” is not just a label to attach to a data set: the covariance estimator must reflect which observations can share shocks. Students in the same school may share school-level conditions, while students taught by the same teacher may share instructional conditions. If teachers each work at one school, teacher membership is nested within school. If teachers work across multiple schools, school and teacher memberships are crossed.

These distinctions determine which score contributions are grouped together in a covariance estimator. Clustering at too narrow a level can omit dependence shared by a larger unit. Conversely, treating crossed dimensions as if one were nested within the other can omit dependence along the dimension that was not used. The regression coefficients need not change, but their estimated uncertainty can.

Definition: A clustering dimension is nested within another when every unit in the first dimension belongs to exactly one unit in the second. Dimensions are crossed when neither dimension is nested within the other: membership in either dimension does not uniquely determine membership in the other; units can be linked across the dimensions in multiple combinations.

Regression Scores and One-Way Clustering

Consider the linear regression model \(y=X\beta+u\), estimated by ordinary least squares (OLS), with \(n\) observations and \(k\) regressors. Write \(x_i\) for the \(k\)-vector of regressors for observation \(i\), and \(\hat{u}_i=y_i-x_i'\hat{\beta}\) for its OLS residual. The observation’s score contribution for the full coefficient vector is the \(k\)-vector \(s_i=x_i\hat{u}_i\). For a cluster \(g\), its score sum is \(S_g=\sum_{i\in g}s_i\).

The one-way cluster-robust covariance estimator groups the score contributions by cluster and takes an outer product of each cluster sum. Let \(G\) denote the number of clusters. Its uncorrected form, often called CR0, is:

$$ \widehat{\mathrm{Var}}_{\mathrm{CR0}}(\hat{\beta}) = (X'X)^{-1} \left(\sum_{g=1}^{G} S_gS_g'\right) (X'X)^{-1}. $$

The sandwich’s middle term allows arbitrary covariance among observations in the same cluster; the cluster sums retain products between all their score contributions. The estimator relies on a suitable asymptotic argument with many independent clusters and regularity conditions, including that no cluster dominates the information. Finite-sample corrections and degrees-of-freedom choices can matter, particularly when the number of clusters is small; the formula above is used here to show the covariance structure and arithmetic.

Worked Example: Students Nested Within Teachers and Schools

Suppose a hypothetical intercept-only regression records test scores for eight students: School A has scores 2, 4, 5, and 7; School B has scores 8, 10, 11, and 13. In each school, the first two students share one teacher and the last two share another. Assume students may have dependent errors throughout a school, including across its teachers, while schools are independent. Which clustering level is appropriate, and what is the CR0 standard error of the intercept?

Choose the level. Teachers are nested within schools, but the stated dependence assumption permits school-wide dependence. Clustering by school allows that dependence. Clustering only by teacher would not allow residual dependence between the two teachers’ students in the same school.

For an intercept-only regression, \(\hat{\beta}=\bar{y}=60/8=7.5\), \(X'X=8\), and the residuals in score order are \(-5.5,-3.5,-2.5,-0.5,0.5,2.5,3.5,5.5\). The school score sums equal the school residual sums because each \(x_i=1\):

$$ S_A=-5.5-3.5-2.5-0.5=-12,\qquad S_B=0.5+2.5+3.5+5.5=12. $$

Thus the meat is \((-12)^2+12^2=288\), and the estimated variance and standard error of the intercept are:

$$ \widehat{\mathrm{Var}}_{\mathrm{CR0}}(\hat{\beta}) =\frac{288}{8^2}=4.5, \qquad SE_{\mathrm{CR0}}(\hat{\beta})=\sqrt{4.5}=2.121. $$

The intercept is the mean test score, measured in score points; its estimated standard error is 2.121 score points. There are only two schools, so this calculation illustrates the estimator rather than supporting reliable large-cluster inference.

Crossed Dimensions and Multiway Clustering

Suppose each observation belongs to one cluster in dimension A and one in dimension B, and neither dimension is nested within the other. A standard two-way clustering assumption allows error dependence between observations that share an A cluster or share a B cluster, with dependence restricted across pairs that share neither. As with one-way clustering, consistent inference needs suitable asymptotics and regularity conditions; in a common two-way framework, both dimensions must have enough clusters.

For each A cluster \(a\), define \(S_a=\sum_{i\in a}s_i\); define \(S_b\) for each B cluster \(b\). An intersection \(a\cap b\) contains observations belonging to both clusters. The two-way CR0 covariance estimator uses inclusion–exclusion:

$$ \widehat{\mathrm{Var}}_{\mathrm{2way}}(\hat{\beta}) = (X'X)^{-1} \left[ \sum_a S_aS_a' +\sum_b S_bS_b' -\sum_{a,b} S_{a\cap b}S_{a\cap b}' \right] (X'X)^{-1}. $$

The A-cluster term counts score products for pairs sharing A; the B-cluster term counts pairs sharing B. Pairs sharing both dimensions appear in both sums, so the intersection term subtracts their duplicate count. The formula includes diagonal products as well: an observation shares both of its own cluster memberships with itself.

Worked Example: Students, Schools, and Teachers on a Crossed Assignment

In a hypothetical program, two students from each of two schools are taught by each of two teachers. Both teachers teach in both schools, so teacher membership is not nested within school. Consider an intercept-only regression with scores laid out by school (rows) and teacher (columns): School A has scores 10 and 12; School B has scores 13 and 15. Assume errors may be dependent within school and within teacher, as described by two-way clustering.

The mean is \(\hat{\beta}=50/4=12.5\), so the residuals by cell are \(-2.5,-0.5,0.5,2.5\). Here \(X'X=4\). School score sums are \(-3\) and \(3\), giving a school meat of \(9+9=18\). Teacher score sums are \(-2\) and \(2\), giving a teacher meat of \(4+4=8\). Each school-teacher intersection has one observation, so its score sums are the four residuals; the intersection meat is:

$$ (-2.5)^2+(-0.5)^2+(0.5)^2+(2.5)^2=13. $$

The two-way meat is \(18+8-13=13\). Therefore:

$$ \widehat{\mathrm{Var}}_{\mathrm{2way}}(\hat{\beta}) =\frac{13}{4^2}=0.8125, \qquad SE_{\mathrm{2way}}(\hat{\beta})=\sqrt{0.8125}=0.9014. $$

The estimated standard error of the mean score is 0.9014 score points. There are only two clusters in each dimension, so this is an arithmetic illustration, not a setting in which large-cluster approximations should be trusted.

Choosing the Dimensions: A Decision Procedure

1
Describe the units and memberships.
State what each regression observation represents and list every grouping that could create shared shocks. For example, a student record has a school and a teacher assignment.
2
Check whether one membership is nested.
If every teacher works in exactly one school, teacher is nested within school. If a teacher works in multiple schools, the dimensions are crossed. Verify the actual assignment rather than inferring it from variable names.
3
Match the estimator to the allowed dependence.
For school-wide dependence with independent schools, use one-way school clustering. For dependence along both crossed school and teacher dimensions, use two-way clustering. State the assumptions that justify the choice.
4
Assess whether the asymptotics are credible.
Count clusters in the relevant dimensions and examine whether a few clusters dominate. A correct covariance formula does not by itself guarantee reliable finite-sample inference.

Worked Example: Firms Observed in Multiple Time Periods

A hypothetical panel records one outcome for each of two firms in each of two years. The observed outcomes are Firm A: 8 and 9; Firm B: 11 and 12. Consider an intercept-only regression and allow dependence among observations from the same firm as well as dependence among observations in the same year. Firms and years are crossed: each firm appears in both years, and each year contains both firms.

The mean is \(10\), so the residual table is \((-2,-1)\) for Firm A and \((1,2)\) for Firm B. With \(X'X=4\), the firm score sums are \(-3\) and \(3\), and their squared sum is \(18\). The year score sums are \(-1\) and \(1\), and their squared sum is \(2\). The four firm-year intersections each contain one observation, so their squared score sum is \(4+1+1+4=10\). Consequently:

$$ \widehat{\mathrm{Var}}_{\mathrm{2way}}(\hat{\beta}) = \frac{18+2-10}{4^2} = \frac{10}{16} = 0.625, \qquad SE_{\mathrm{2way}}(\hat{\beta})=\sqrt{0.625}=0.7906. $$

The standard error is 0.7906 outcome units. Firm-only clustering would give \(\sqrt{18/16}=1.061\), while year-only clustering would give \(\sqrt{2/16}=0.3536\); neither includes both dimensions of the assumed dependence. With only two firms and two years, none of these calculations warrants routine large-cluster inference. The example shows how the covariance formula reflects the stated structure, not how to solve the few-cluster problem.

Nested Clusters and Intersections

If teachers are nested within schools, two-way clustering by school and teacher does not generally add a new dependence dimension beyond school clustering. Each teacher cluster is contained in a school cluster, and the school-teacher intersections are exactly the teacher clusters. Thus the two-way meat simplifies algebraically:

$$ \sum_{\text{schools}} S_gS_g' + \sum_{\text{teachers}} S_hS_h' - \sum_{\text{school-teacher intersections}}S_{g\cap h}S_{g\cap h}' = \sum_{\text{schools}} S_gS_g'. $$

This identity does not imply that teacher-level clustering is adequate when school-wide dependence is plausible. It shows that adding a nested dimension to school clustering does not create a separate crossed dimension in the two-way inclusion–exclusion estimator. With a hierarchy of dependence, choose a level that permits the dependence of concern; clustering at an upper level allows arbitrary dependence among its lower-level units.

Common Mistake and Practical Interpretation

Mistake: “Teachers are the smallest groups, so I should cluster by teacher.” That reasoning assumes errors are independent across teachers. If students taught by different teachers still share school shocks, teacher-only clustering excludes those cross-teacher covariances. Correction: identify the shocks that can jointly affect errors, then choose a covariance estimator whose grouping structure retains the corresponding score cross-products.

A second error is to use a two-way estimator merely because two group identifiers are present. Two-way clustering represents dependence along two crossed dimensions; it is not a general remedy for every hierarchical or complex dependence pattern. State the proposed dependence assumptions, check whether the dimensions are nested or crossed, and then check the cluster counts. For a coefficient contrast, use the relevant quadratic form of the estimated covariance matrix, \(c'\widehat{\mathrm{Var}}(\hat{\beta})c\); the observation score \(x_i\hat{u}_i\) itself is a vector contribution for the full coefficient vector.

The central practical point is that clustering is a statement about the error structure, not just about the sampling frame. One-way clustering is appropriate when independent top-level clusters contain the possible dependence. Crossed clustering is appropriate when more than one nonnested grouping can link observations. In both cases, a covariance estimate can be computed even when the number of clusters is too small for its usual approximation to be dependable.

Check Your Understanding

Answer each question by identifying the dependence structure and the implication for covariance estimation.

  1. Students are assigned to exactly one teacher, and each teacher works at exactly one school. Which grouping contains the other, and what does school clustering allow that teacher-only clustering may not?
  2. Two teachers teach in multiple schools. Are teacher and school dimensions nested or crossed? If errors may share shocks along either dimension, what covariance estimator matches that assumption?
  3. In two-way clustering, why is the intersection-cluster meat subtracted?
  4. For an intercept-only regression, cluster residual sums are \(-2\) and \(2\), and \(X'X=4\). Calculate the one-way CR0 variance and standard error.
  5. Why can a correctly specified cluster-robust covariance formula still yield unreliable inference when there are very few clusters?
Clinical Biostats