Skip to main content
v2026.11,610 entries · CC-BY 4.0

Clustered Standard Errors: Naive vs. Cluster-Robust SEs

Clustering within classrooms, clinics, or repeated subjects violates the independence assumption behind classical standard errors. A seeded, reproducible simulation compares naive vs. cluster-robust SEs on the same data, then shows why cluster-robust corrections themselves under-perform with too few clusters.

Ask about Clustered Standard Errors: Naive vs. Cluster-Robust SEs

Answers are drawn from this guide and the rest of the CASRAI corpus, with a link to every source.

Answers are AI-generated from CASRAI’s own published pages and can be wrong, so check the linked sources before relying on one; your question is logged without personal data — never sold, never used to train a third-party model — to show us what CASRAI is missing, so please do not type personal or confidential details. How we use this

Written and maintained by CASRAI Editorial Board

Last updated

A clustered standard error is a standard error computed to account for the fact that observations inside the same group — the same classroom, the same clinic, the same patient measured repeatedly — are correlated with each other, rather than independent. Ordinary least squares (OLS) and most classical inference assume every observation is an independent draw. When observations instead come in clusters that share something unmodeled — a teacher, a treating clinician, a subject’s own baseline tendency — that assumption is false, and the standard errors computed as if it were true come out too small. The fix is not a different point estimate; the regression coefficient itself is typically still unbiased. The fix is a different variance estimator: a cluster-robust (“sandwich”) standard error that allows unrestricted correlation within each cluster while still assuming clusters are independent of each other.

What counts as a cluster

A cluster is any group of observations that plausibly share an unmodeled source of correlation. The common cases in applied quantitative research:

  • Classrooms or schools — students in the same classroom share a teacher, curriculum pacing, and peer effects, so their outcomes move together beyond whatever the model already captures.
  • Clinics or hospitals — patients treated at the same site share equipment, protocols, and clinician skill, producing site-level correlation in outcomes.
  • Repeated measures on the same subject — multiple observations from one person (longitudinal or panel data) are correlated through everything stable about that person that the model doesn’t explicitly include.
  • Firms, geographic units, or survey primary sampling units — employees within a firm, respondents within a sampled village or postcode, all share local, unmodeled context.

The unifying feature is not physical proximity but shared unmodeled context. See Unit of Analysis: Choosing It and Avoiding the Mismatch Error for the design-stage version of this same problem — deciding what your true independent replicate is before you collect data, rather than discovering after the fact that your rows aren’t independent.

Why clustering breaks the independence assumption

Classical OLS standard errors are built from a single number, the residual variance, on the assumption that every residual is drawn independently. When residuals within a cluster are positively correlated — the ordinary case, since whatever makes one classroom’s scores move together tends to push them in the same direction — the effective amount of independent information in the sample is smaller than the raw observation count n suggests. Treating 500 student-level rows as 500 independent pieces of evidence, when they really came from 20 classrooms, overstates precision. This is the same design-effect logic used in cluster sampling and formalized for trial design in cluster-randomized trials and the intracluster correlation coefficient: the design effect is roughly 1 + (m − 1)ρ, where m is the average cluster size and ρ (the ICC) is the share of total variance sitting between clusters rather than within them. A positive ICC means every additional observation inside an already-sampled cluster adds less new information than a fully independent observation would — and naive standard errors don’t know that.

Whether this matters in practice depends on two things pulling in the same direction: how strong the within-cluster correlation is, and whether the variable you care about (typically a treatment or exposure) is itself assigned at the cluster level. When treatment varies within a cluster, clustering usually matters less. When treatment is constant within a cluster — a whole classroom gets the new curriculum, a whole clinic adopts the new protocol — ignoring clustering is at its most dangerous, because every observation in a treated cluster is, in effect, echoing the same single realization of “this cluster got treated.”

A worked comparison: naive vs. cluster-robust standard errors

The numbers below come from a seeded simulation built for this guide (mulberry32 pseudo-random generator, Box–Muller normal draws, no external statistical packages — fully reproducible from the parameters stated). The design: 40 clusters (think 40 classrooms), alternating half assigned to a cluster-level treatment, average 15 observations per cluster (unbalanced, 8–22 per cluster), a true treatment effect of 1.5, and an intraclass correlation of 0.20 (cluster-level variance of 9 against within-cluster residual variance of 36). This is an illustrative simulated dataset, not a claim about any real study.

Fitting y = β0 + β1·treat + ε by OLS on the simulated data (N = 598) gave an estimated effect of 2.85 (sampling noise around the true 1.5 in a single draw, as expected). The two standard errors for that same coefficient, computed two different ways on the identical data:

Standard error type Formula basis SE on β₁ Resulting t-statistic
Naive (classical OLS) Assumes i.i.d. residuals 0.499 5.71
Cluster-robust (CR1 sandwich) Allows within-cluster correlation, independent clusters 0.816 3.50

The cluster-robust standard error is 1.64× larger than the naive one on the exact same data and the exact same point estimate — the coefficient didn’t move, only the uncertainty attached to it did. Both t-statistics still clear conventional significance thresholds in this particular draw, but that’s not the point: the naive SE would routinely manufacture significance in null cases, which the next section demonstrates directly.

The cluster-robust (“sandwich”) estimator itself, in its most common CR1 form, is (X′X)−1 [∑g Xg′ ugug′ Xg] (X′X)−1, with a small-sample degrees-of-freedom correction of (G/(G−1))·((n−1)/(n−k)) applied on top (this is the correction Stata’s default clustered vce(cluster) uses). It replaces the single scalar residual variance in the classical formula with a matrix built from each cluster’s own summed score contribution — which is exactly what lets correlation within a cluster take any shape without being assumed away.

Why cluster-robust SEs themselves can fail: the too-few-clusters problem

The CR1 correction above is asymptotically justified as the number of clusters grows, not as the number of observations grows — adding more students to the same 6 classrooms does not fix a too-few-clusters problem the way adding more classrooms would. With few clusters, CR1 is a biased estimate of the true sandwich variance and tends to run too small, so a test built on it still over-rejects a true null, just less severely than the naive version. The same simulation setup, rerun under the null of no treatment effect (true β₁ = 0) across 4,000 replications per cluster count, at a nominal 5% significance level:

Number of clusters (G) Naive test, false-positive rate Cluster-robust (CR1) test, false-positive rate
6 34.7% 9.8%
10 32.5% 6.6%
20 33.8% 6.1%
40 32.4% 5.5%

Two things worth reading directly off this table. First, the naive test is badly wrong (roughly a 1-in-3 false-positive rate against a nominal 1-in-20) at every cluster count — clustering doesn’t become safe to ignore just because you have a lot of clusters, since the naive SE never accounts for it at all. Second, the cluster-robust correction is not a fixed fix: it lands close to the nominal 5% at 40 clusters but is still visibly over-sized at 6. Applied econometrics practice generally treats somewhere in the range of 30–50 clusters as a rough comfort floor for CR1 (Wikipedia’s summary of the cluster-robust-inference literature states practitioners commonly cite this 30–50 range), not a hard cutoff below which CR1 is useless, but a zone where its own known small-sample bias starts to matter as much as the clustering problem it was built to fix.

Remedies when you don’t have enough clusters

None of these require abandoning cluster-robust inference outright — they address the specific failure mode above:

  • Bias-reduced CR2/CR3 sandwich variants. Analogues of the heteroskedasticity-consistent HC2/HC3 corrections (see Robust (Heteroscedasticity-Consistent) Standard Errors: HC0 Through HC3 for the non-clustered version of the same idea), CR2/CR3 reweight each cluster’s contribution to correct known small-G bias and generally produce better coverage than CR1 when the cluster count is modest.
  • Wild cluster bootstrap. Rather than relying on the asymptotic sandwich variance at all, this resamples entire clusters (not individual observations) with random sign flips on the residuals, rebuilding the test statistic’s distribution directly. It is the standard remedy specifically recommended in the literature for genuinely small numbers of clusters, where CR1 (and often CR2/CR3) still under-cover. See Bootstrapping in Statistics: Resampling for Confidence Intervals for the general resampling logic this extends.
  • Aggregate to the cluster level. Collapse to one row per cluster (a cluster mean or a cluster-level regression) and analyze that. Always valid and simple, at the cost of discarding within-cluster variation — the same trade-off discussed on the unit-of-analysis page.
  • Fit the correlation structure explicitly. A mixed-effects model with a random effect for cluster, or a generalized estimating equation (GEE) with an exchangeable working correlation, models the within-cluster correlation directly rather than only patching the standard error after the fact. See Mixed-Effects Models: Choosing Random vs. Fixed Effects for Nested Research Data for when this is the better choice.

Computing cluster-robust standard errors

The mechanics vary by software, but the underlying request is the same in each: fit the model normally, then ask for the variance-covariance matrix to be computed with clustering on the grouping variable rather than assuming i.i.d. errors.

  • Stata: add the vce(cluster clustervar) option to the estimation command, e.g. regress y x, vce(cluster classroom_id). See Regression in Stata: regress, Postestimation, and Reporting for the surrounding workflow.
  • R: fit the model with lm() or glm(), then recompute the variance-covariance matrix with the sandwich package’s vcovCL(model, cluster = ~classroom_id) and feed that into lmtest::coeftest() for the corrected test statistics; several modeling packages (e.g. fixest, estimatr) also expose a direct cluster argument on the estimation call itself.
  • Python: with statsmodels, fit the model and call .fit(cov_type='cluster', cov_kwds={'groups': df['classroom_id']}) instead of the default covariance type.

In every case, double-check which small-sample degrees-of-freedom adjustment the software applies by default — implementations differ, which is part of why identical data can produce slightly different cluster-robust standard errors across packages even before the too-few-clusters problem enters the picture.

Clustered standard errors vs. related concepts

“Cluster” does double duty in quantitative methods, and conflating the senses causes real confusion:

  • Clustered standard errors (this page) — a variance-estimation correction for correlated errors within groups.
  • Cluster sampling — a survey design choice, sampling intact groups rather than individuals directly, with its own design-effect logic that clustered SEs echo at the analysis stage.
  • Cluster-randomized trials — an experimental design that assigns treatment at the cluster level; clustered (or mixed-model) standard errors are the standard analysis approach for data this design produces.
  • Cluster analysis (hierarchical, k-means) — an unrelated technique that groups similar cases together as an exploratory or classification exercise; it has nothing to do with correcting standard errors.

Frequently asked questions

Does clustering ever make standard errors smaller instead of larger?

In principle, yes — the cluster-robust correction can occasionally shrink an SE if the within-cluster correlation in the residuals is negative rather than positive. In applied practice this is uncommon; the standard concern, and the one this guide focuses on, is positive within-cluster correlation understating uncertainty.

Should I cluster on the treatment-assignment level or on some other grouping variable?

Cluster on whatever level treatment (or the key explanatory variable) was actually assigned or is plausibly correlated at, not on any grouping variable that happens to be in the dataset. Clustering at a level coarser than necessary is broadly safe (conservative); clustering at a level finer than the true correlation structure understates uncertainty in the same way not clustering at all does.

Can I cluster on more than one dimension at once?

Yes — two-way (multi-way) clustering exists for data with more than one plausible grouping, e.g. student and school simultaneously, or firm and year. It’s a direct extension of the same sandwich logic and is supported by most of the software referenced above, though it adds its own small-sample considerations.

Is a cluster-robust standard error the same thing as a heteroskedasticity-robust standard error?

No. HC0–HC3 (see Robust Standard Errors: HC0 Through HC3) correct for non-constant error variance across otherwise independent observations. Cluster-robust SEs correct for correlation between observations within a group. Data can have either problem, both, or neither, and the cluster-robust estimator is the one built to handle within-cluster correlation specifically.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Regulatory Radar

Stop finding out after the fact

$29/month, cancel anytime. Daily digest updates from our analysis, a dashboard holding the same items, and a cited assistant for everything they raise.

  • Federal Register, Federal Register+, Grants.gov, Regulations.gov, NSF News, UKRI, plus CASRAI’s own published content.
  • 44,322 indexed passages, and every answer cites the ones it drew on.