Introduction
In clustered data, observations from the same school, clinic, household, or other group may share influences. Ordinary least squares (OLS) still fits the same regression line or plane to the observed data, but the usual standard-error calculation may treat observations as more independent information than they really are. Cluster-robust standard errors address that uncertainty problem without changing the OLS coefficient estimates.
That distinction matters because a regression coefficient describes the fitted association, while its standard error describes estimated sampling uncertainty. Changing the standard error can change a confidence interval or test statistic even when every fitted value and coefficient remains exactly the same.
What Is Held Fixed, and What Changes?
Suppose observation \(i\) in cluster \(g\) has outcome \(Y_{ig}\) and predictor vector \(\mathbf{x}_{ig}\). The linear regression model for the conditional mean is
Here \(\boldsymbol{\beta}\) is the coefficient vector and \(u_{ig}\) is the error. OLS chooses coefficient estimates to minimize the sum of squared residuals across all observations. The OLS calculation uses the observed outcomes and predictors; it does not use a standard-error formula to choose the coefficients.
The usual homoskedastic OLS variance estimate uses the assumption that errors are uncorrelated across observations and have a common variance. A cluster-robust variance estimate relaxes those within-cluster restrictions: errors in one cluster may have different variances and may covary with one another. It still requires a suitable regression model and, for the usual large-sample justification, independent clusters and enough clusters. It does not allow arbitrary dependence between different clusters.
For \(G\) clusters, one commonly used uncorrected cluster-robust covariance estimate is
Here \(\mathbf{X}_g\) is the design matrix for cluster \(g\), and \(\hat{\mathbf{u}}_g\) is the vector of its OLS residuals. The diagonal entries estimate coefficient variances; their square roots are the cluster-robust standard errors. Some software applies a finite-sample multiplier, so reported values can differ slightly across implementations. The expression above is the uncorrected version.
The key feature is that residual contributions are combined within each cluster before their outer products are summed across clusters. Consequently, residual patterns that move together within a cluster contribute to uncertainty together. By contrast, a conventional calculation that treats each observation as independent does not include those within-cluster covariance contributions.
Worked Example: Coefficients Do Not Depend on the Standard-Error Formula
Suppose a hypothetical OLS fit uses the observed pairs \((x,y)=(0,1),(1,3),(2,5)\). The fitted line is \(\hat{y}=1+2x\): its residuals are all zero, and the line passes through all three observations. The coefficient estimates are an intercept of 1 and a slope of 2.
A conventional standard-error calculation and a cluster-robust calculation use the same observed \(x\)'s, \(y\)'s, and OLS residuals. Neither calculation changes the least-squares minimizer. If the observations are assigned to clusters, the cluster-robust formula changes how residual information contributes to estimated uncertainty; it does not replace the fitted line with a different one.
This example has zero residuals, so both variance calculations are zero and it is not useful for comparing uncertainty estimates. Its purpose is to isolate the coefficient point: the estimate comes from minimizing the sum of squared residuals, not from choosing a standard-error formula. A nonzero-residual example is needed to see how uncertainty estimates can differ.
Why Dependence Changes Uncertainty
A compact way to see the issue is to consider the regression score contribution from a cluster. For cluster \(g\), this contribution is \(\mathbf{X}_g^{\mathsf T}\mathbf{u}_g\): it combines the predictor-weighted errors of that cluster's observations. If clusters are independent, the variance of the sum of these cluster contributions is the sum of their variances. Within a cluster, however, the variance of the sum includes covariance terms between observations.
For two observations in one cluster, for example,
Treating the observations as independent omits the covariance term. If it is positive, the omitted term can make the estimated uncertainty too small; if it is negative, the effect can go in the other direction. Thus cluster-robust standard errors are not automatically larger than conventional ones. They change the estimate to account for within-cluster dependence, and the direction and size of that change depend on the data and regression.
Worked Example: Clustered Observations in an Intercept-Only Regression
Consider six hypothetical measurements, arranged as three clusters of two. The values are \((1,1)\), \((3,3)\), and \((5,5)\). Fit an intercept-only regression, so the OLS intercept is the overall mean:
The residuals in the three clusters are \((-2,-2)\), \((0,0)\), and \((2,2)\). For this intercept-only model, the uncorrected cluster-robust variance estimate is the sum of squared cluster residual sums divided by \(n^2\):
The corresponding cluster-robust standard error is \(\sqrt{0.8889}=0.9428\) measurement units. For comparison, the conventional homoskedastic standard error for the mean is based on \(s^2/n\). The residual sum of squares is \(16\), so \(s^2=16/(6-1)=3.2\), and
measurement units. The fitted intercept remains 3 under either calculation. Here the cluster-robust standard error is larger because the paired residuals move together within clusters. There are only three clusters, however, so this is an arithmetic illustration rather than a sound basis for relying on usual large-sample cluster-based inference.
A Regression Example With a Slope
The same distinction applies to slope coefficients. The next example gives a small data set in which the OLS coefficient estimates are easy to verify, then calculates one cluster-robust standard error directly. The uncorrected calculation is used for transparency.
Worked Example: A Cluster-Robust Standard Error for a Slope
Suppose three hypothetical clusters each contain two observations, with predictor values \(x=-1\) and \(x=1\). The outcomes are as follows. Each residual listed is relative to the line \(\hat{y}=3+2x\).
| Cluster | \(x\) | \(y\) | Residual from \(3+2x\) |
|---|---|---|---|
| 1 | -1 | -1.5 | -2.5 |
| 1 | 1 | 5.5 | 0.5 |
| 2 | -1 | 2 | 1 |
| 2 | 1 | 4 | -1 |
| 3 | -1 | 2.5 | 1.5 |
| 3 | 1 | 5.5 | 0.5 |
The residuals sum to \(-2.5+0.5+1-1+1.5+0.5=0\), and their products with \(x\) sum to \(2.5+0.5-1-1-1.5+0.5=0\). Thus they are orthogonal to the intercept and predictor columns, as OLS residuals must be. Also \(\sum x_i=0\) and \(\sum x_i^2=6\), so the fitted intercept is 3 and the fitted slope is 2.
For the slope, each cluster's predictor-weighted residual sum is \(\sum_{i\in g}x_i\hat{u}_i\). The three values are \(3\), \(-2\), and \(-1\). Since the intercept and predictor columns are orthogonal, the slope element of \((\mathbf{X}^{\mathsf T}\mathbf{X})^{-1}\) is \(1/6\). Therefore the uncorrected cluster-robust variance estimate for the slope is
The slope's cluster-robust standard error is \(\sqrt{0.3889}=0.6236\) outcome units per predictor unit. For comparison, the residual sum of squares is \(11\), so the conventional variance estimate is
In this constructed example, the cluster-robust standard error is smaller than the conventional one. This does not make clustering inappropriate: it shows that the method changes the variance estimate rather than applying a rule that inflates it. With only three clusters, the uncorrected estimate should not be treated as reliable large-sample inference.
What Changes in Regression Output?
For a fixed OLS model and data set, using a cluster-robust covariance estimate leaves the following quantities unchanged:
- the estimated coefficients and fitted values;
- the residuals and residual sum of squares;
- the OLS \(R^2\).
It can change the estimated standard error for each coefficient and the estimated covariances between coefficients. As a result, tests and confidence intervals based on that covariance estimate can change. For example, a test statistic for \(H_0:\beta_j=0\) uses the coefficient estimate divided by its estimated standard error. If that standard error changes while the coefficient stays fixed, the statistic changes as well. Appropriate reference distributions and small-sample adjustments require care, especially when the number of clusters is small; those details are not determined simply by switching the variance formula.
A robust standard error is not a new coefficient, a correction to the fitted line, or a guarantee that the regression assumptions all hold. Cluster-robust uncertainty does not repair a misspecified mean relationship, omitted-variable bias, measurement error, or confounding. Nor does it correct a poor choice of clustering level: the clusters must reflect the dependence structure relevant to the analysis.
Common Mistake: Expecting Cluster-Robust Errors to Refit the Model
A common mistake is to say, “After clustering, the regression coefficient changed because the observations within each group were given less weight.” That is not what the standard cluster-robust calculation does. It uses the original OLS estimates and changes how their uncertainty is estimated. If coefficients differ between two reported models, some other aspect changed—for example, the observations, predictors, weights, or estimation method—or a different model was fit.
Another mistake is to assume that a cluster-robust standard error must be larger. Its purpose is to allow within-cluster dependence, not to increase every uncertainty estimate. The covariance terms can increase or decrease a particular estimated variance. Finally, many observations do not necessarily mean much independent information when they are concentrated in a small number of clusters. The number of independent clusters matters for assessing the quality of cluster-based inference.
Check Your Understanding
Answer each question using the distinction between fitting the regression and estimating uncertainty.
- When a cluster-robust covariance estimate replaces the conventional OLS covariance estimate, which regression quantities remain unchanged?
- Why can treating positively correlated observations within a cluster as independent understate uncertainty?
- Must a cluster-robust standard error be larger than its conventional counterpart? Explain.
- In the intercept-only example, why did the paired residuals contribute together to the cluster-robust variance calculation?
- Name one important regression problem that cluster-robust standard errors do not fix.