Tutorials › Econometrics (Graduate) › Unit-Clustered Sandwich Inference in Short Panels

Panel Dependence and Inference · Tutorial 322 of 952

Unit-Clustered Sandwich Inference in Short Panels

Learn how to aggregate panel scores by unit, construct the clustered sandwich covariance estimator, and interpret its assumptions and large-unit justification.

Advanced 12 min read

What You'll Learn

  • Define unit-level estimating-equation scores by summing contributions over time.
  • Derive the unit-clustered sandwich covariance estimator from a first-order expansion.
  • Identify the independence and moment conditions needed for its large-unit justification.
  • Calculate clustered standard errors for scalar and vector panel estimators.
  • Explain why clustering accommodates within-unit dependence but not unrestricted cross-unit dependence.
  • Distinguish asymptotic justification from the reliability of inference with few units.

Why Cluster at the Unit Level?

In a panel, repeated observations from the same unit need not provide independent pieces of information. A household’s unobserved circumstances, for example, may affect its outcome in several periods. Treating every unit-period observation as independent can then understate uncertainty, even if the point estimate is unchanged. Unit-clustered inference addresses this by making the unit, rather than the individual observation, the basic contribution to the covariance calculation.

The key operation is to add the estimating-equation contributions over time within each unit, and then form the covariance from those unit-level sums. This allows unrestricted dependence among a unit’s period-specific scores. The usual large-sample justification still needs a condition across units: in the standard version developed here, units are independent, with the average covariance of their scores converging to a finite limit. Clustering by unit does not itself allow arbitrary dependence across units.

Definition: Let \(i=1,\ldots,N\) index units and \(t=1,\ldots,T_i\) index observed periods. If \( \psi_{it}(\theta) \) is the period-specific contribution to an estimating equation for parameter vector \( \theta \), define the unit-level score or estimating function as \( g_i(\theta)=\sum_{t=1}^{T_i}\psi_{it}(\theta) \). The estimator \( \hat{\theta} \) solves \( \sum_{i=1}^N g_i(\hat{\theta})=0 \). Unit clustering forms the covariance estimate from the \(N\) unit-level vectors \(g_i(\hat{\theta})\), not from the separate period-level contributions.

The Unit-Clustered Sandwich

Suppose the true parameter is \( \theta_0 \), of dimension \(k\), and \(E[g_i(\theta_0)]=0\). Define the sensitivity matrix and the covariance of the unit-level estimating functions by

$$ A_N=-\frac{1}{N}\sum_{i=1}^N E\!\left[\frac{\partial g_i(\theta_0)}{\partial\theta'}\right], \qquad \Omega_N=\frac{1}{N}\sum_{i=1}^N E[g_i(\theta_0)g_i(\theta_0)']. $$

For the standard independent-unit result, assume that units are independent, the estimating functions have mean zero and finite moments sufficient for a central limit theorem and consistent covariance estimation, and the estimator is consistent. Also assume that \(A_N\) converges to a nonsingular matrix \(A\), and that \( \Omega_N\) converges to a finite matrix \( \Omega\). A convenient special case is independent and identically distributed units with finite second moments. For independent but non-identically distributed units, convergence of the average score covariance is an additional condition, not an automatic consequence of independence.

Time-period scores within a unit can be dependent and can have different variances across periods. Their joint effect is contained in \(g_i g_i'\). Short-panel asymptotics typically let the number of units grow while the number of periods per unit is fixed or bounded; they do not require the period-level errors within a unit to be independent.

$$ \widehat{A}=-\frac{1}{N}\sum_{i=1}^N \frac{\partial g_i(\hat{\theta})}{\partial\theta'}, \qquad \widehat{\Omega}=\frac{1}{N}\sum_{i=1}^N g_i(\hat{\theta})g_i(\hat{\theta})'. $$

The estimated covariance matrix of \( \hat{\theta} \) is

$$ \widehat{\operatorname{Var}}(\hat{\theta}) =\frac{1}{N}\widehat{A}^{-1} \widehat{\Omega} \widehat{A}^{-1'}, $$

where \( \widehat{A}^{-1'}\) means the transpose of \( \widehat{A}^{-1}\). The matrix \( \widehat{\Omega}\) is the clustered “meat”; the two sensitivity matrices are the “bread.” The estimated standard error for a component is the square root of its diagonal entry. Some presentations combine the factor \(1/N\) with the meat; the formula is equivalent if the scaling is applied consistently. Small-sample multiplicative adjustments are distinct from this basic large-\(N\) estimator.

Why the Formula Works

The justification is a first-order expansion of the estimating equation around \( \theta_0\). The argument uses the covariance of the sum of unit scores. Under independence across units, cross-unit covariance terms vanish. The within-unit covariance terms do not vanish and are retained by the outer product of each summed score.

1
Linearize the estimating equation.
Expand \(N^{-1}\sum_i g_i(\hat{\theta})=0\) around \( \theta_0\). With the stated sign convention for \(A_N\), this gives \( \sqrt{N}(\hat{\theta}-\theta_0)=A^{-1}N^{-1/2}\sum_i g_i(\theta_0)+o_p(1)\), when the derivative average converges and the remainder is negligible.
2
Use the independent-unit central limit theorem.
Under the moment and regularity conditions, \(N^{-1/2}\sum_i g_i(\theta_0)\) has limiting covariance \( \Omega\), because the average of the unit score covariance matrices converges to \( \Omega\).
3
Transform by the sensitivity matrix.
The limiting covariance of \( \sqrt{N}(\hat{\theta}-\theta_0)\) is \(A^{-1}\Omega A^{-1'}\). Therefore the covariance of \( \hat{\theta}\) is approximately \(N^{-1}A^{-1}\Omega A^{-1'}\).
4
Estimate the unknown covariance.
Replace the sensitivity by its sample estimate and \( \Omega\) by the average outer product of the estimated unit scores. Under the stated conditions, these substitutions yield the displayed clustered sandwich estimator.

The crucial covariance statement is for the unit-level scores. If units are weakly dependent rather than independent, cross-unit covariances can contribute to the limiting covariance of \(N^{-1/2}\sum_i g_i\). In that setting, \(N^{-1}\sum_i E[g_i g_i']\) alone is generally not the correct limiting covariance. A different covariance estimator must account for the relevant cross-unit dependence; the ordinary unit-clustered formula does not do so.

Worked Calculations

Worked Example: A Scalar Regression With Two Periods per Unit

Consider the hypothetical regression \(y_{it}=\beta x_{it}+u_{it}\), with no intercept, estimated by pooled least squares. For three units with two observations each, suppose the data are:

Unit\(x_{i1},x_{i2}\)\(y_{i1},y_{i2}\)
11, 12, 0
21, 21, 3
32, 10, 2

The pooled estimate is \( \hat{\beta}=\sum_{i,t}x_{it}y_{it}/\sum_{i,t}x_{it}^2\). Here \( \sum x_{it}y_{it}=2+7+2=11\) and \( \sum x_{it}^2=2+5+5=12\), so \( \hat{\beta}=11/12=0.9167\). The unit score is \(g_i(\hat{\beta})=\sum_t x_{it}(y_{it}-\hat{\beta}x_{it})\). The three scores are

$$ g_1=\frac{1}{6},\qquad g_2=\frac{29}{12},\qquad g_3=-\frac{31}{12}. $$

They sum to zero, as required by the fitted estimating equation. The estimated sensitivity is \( \widehat{A}=N^{-1}\sum x_{it}^2=12/3=4\). The estimated meat is

$$ \widehat{\Omega} =\frac{1}{3}\left[\left(\frac{1}{6}\right)^2+ \left(\frac{29}{12}\right)^2+ \left(-\frac{31}{12}\right)^2\right] =\frac{301}{72}=4.1806. $$

Thus \( \widehat{\operatorname{Var}}(\hat{\beta})=(1/3)(1/4^2)(301/72)=301/3456=0.08710\), and the unit-clustered standard error is \( \sqrt{0.08710}=0.2951\). The computation sums the two period scores within each unit before squaring. With only three units, this example illustrates the formula rather than establishing that a normal approximation is reliable.

Worked Example: Within-Unit Dependence Changes the Meat

Suppose a hypothetical intercept-only panel has three units and two periods per unit, with observations \( (5,7)\), \( (4,4)\), and \( (6,8)\). The estimate of the common mean is \( \hat{\mu}=34/6=17/3\). Each period contributes \(y_{it}-\mu\), so the unit score is the sum of its two residuals. These scores are \(2/3\), \(-10/3\), and \(8/3\), which add to zero. The sensitivity is \( \widehat{A}=2\), because each unit contributes two derivatives of \(-1\). Therefore

$$ \widehat{\Omega} =\frac{1}{3}\left[\left(\frac{2}{3}\right)^2+ \left(-\frac{10}{3}\right)^2+ \left(\frac{8}{3}\right)^2\right] =\frac{56}{9}, \qquad \widehat{\operatorname{Var}}(\hat{\mu}) =\frac{1}{3}\left(\frac{1}{2}\right)^2\frac{56}{9} =\frac{14}{27}=0.5185. $$

For comparison, treating the six observations as independent would use the sum of squared observation-level residuals, \(40/3\), and divide by \(6^2\), giving \(10/27=0.3704\). That calculation omits the within-unit cross-products when the two residuals in each unit are added. The clustered calculation includes them through \(g_i^2\). The difference here is illustrative; neither estimate should be treated as precise inference from just three units.

Worked Example: A Two-Parameter Clustered Regression

For a second hypothetical dataset, there are four units, each observed twice. In both periods of unit \(i\), the regressor is \(x_i\), and the outcome is \(y_{it}=1+2x_i+v_i\). Take \(x_i=(-1,0,1,2)\) and \(v_i=(1,-3,3,-1)\). The residual pattern is orthogonal to both the intercept and regressor because \( \sum_i v_i=0\) and \( \sum_i x_i v_i=0\). Thus pooled least squares gives \( \hat{\beta}=(1,2)'\), where the first component is the intercept.

For \(z_i=(1,x_i)'\), the unit score is \(g_i=\sum_t z_i e_{it}=2v_i z_i\). In order, the scores are \( (2,-2)'\), \( (-6,0)'\), \( (6,6)'\), and \( (-2,-4)'\). Their outer products sum to

$$ \sum_i g_i g_i' = \begin{pmatrix} 80&40\\ 40&56 \end{pmatrix}, \qquad \widehat{\Omega} = \begin{pmatrix} 20&10\\ 10&14 \end{pmatrix}. $$

The sensitivity is \( \widehat{A}=N^{-1}\sum_{i,t}z_i z_i'=\begin{pmatrix}2&1\\1&3\end{pmatrix}\), whose inverse is \( \frac{1}{5}\begin{pmatrix}3&-1\\-1&2\end{pmatrix}\). Substitution into the sandwich gives

$$ \widehat{\operatorname{Var}}(\hat{\beta}) =\frac{1}{4}\widehat{A}^{-1}\widehat{\Omega}\widehat{A}^{-1'} = \begin{pmatrix} 1.34&-0.18\\ -0.18&0.36 \end{pmatrix}. $$

The estimated standard errors are \( \sqrt{1.34}=1.158\) for the intercept and \( \sqrt{0.36}=0.600\) for the slope. The off-diagonal entry records estimated covariance between the two coefficient estimates. This calculation also shows why the meat is a matrix of unit-score outer products: it retains cross-products between the intercept and slope scores as well as dependence across the two periods.

Interpretation, Scope, and a Common Pitfall

With many independent units and the stated regularity conditions, the sandwich estimates the sampling covariance of the estimator under the specified estimating equations, even if the working model does not correctly describe the within-unit covariance matrix. It does not make coefficients causal: that interpretation requires a suitable identification strategy and assumptions. Nor does it correct bias in the point estimator or protect against misspecified moment conditions.

  • Wrong reasoning: “There are many unit-period observations, so an observation-level standard error is adequate.” Repeated observations from one unit may have correlated scores, so the number of rows can overstate the amount of independent information.
  • Correction: Form \(g_i\) by summing scores within each unit, then use the outer products \(g_i g_i'\). The large-sample argument is based on the number of independent units \(N\), not the total number of rows.
  • Wrong reasoning: “Clustering by unit permits any dependence in the panel.” The usual estimator allows arbitrary dependence within a unit, not arbitrary dependence across units.
  • Correction: State the cross-unit assumption explicitly. Under independent units, the average unit-score covariance supplies the meat. Under cross-unit dependence, covariances between different units may also contribute and require a method that accounts for them.

A large number of observations is not a substitute for a large number of independent units. When the number of clusters is small, conventional cluster-robust standard errors and normal or large-sample \(t\)-based approximations can be inaccurate. The large-\(N\) derivation here does not resolve that issue; it is a separate finite-cluster problem.

Key takeaway: Unit-clustered sandwich inference aggregates period-level estimating functions within each unit, then estimates the covariance from those unit sums. It accommodates arbitrary within-unit dependence under appropriate moment conditions, while its standard justification requires independent units and convergence of their average score covariance.

Check Your Understanding

Use the definitions and formulas in this tutorial to answer the following.

  1. For a panel estimating equation, what is the unit-level score, and why is it formed before taking outer products?
  2. Which assumptions permit the average of \(g_i g_i'\) to estimate the limiting score covariance in the standard unit-clustered result?
  3. In a scalar estimating equation with \(N\) units, explain the roles of \(A\), \(\Omega\), and the factor \(1/N\) in the estimated covariance.
  4. Why can an observation-level covariance calculation differ from one based on unit-level score sums?
  5. If adjacent unit scores are correlated, why may the ordinary unit-clustered meat fail to estimate the limiting covariance of the normalized score sum?
Clinical Biostats