Choose your reading route
eduKateSG · Why Mathematics? · Cluster-Robust Standard Errors: Within-Group Dependence and Effective Information
Start with the question, audit the worked example, or jump to the assumptions and practice. Every chapter stays open for uninterrupted reading.
Understand the question
Define the quantity and follow the mechanism.Route 2 · Chapters 6–11
Reproduce the example
Audit the numbers one step at a time.Route 3 · Chapters 12–18
Check assumptions
See where design and calibration matter.Route 4 · Chapters 19–24
Explore applications
Connect the method to a concrete investigation.Route 5 · Chapters 25–36
Study and verify
Practise, inspect failure cases and read further.
Full chapter index · Practice and checking · Mathematics Learning Hub
Why is mathematics important when a dataset has thousands of rows but many rows belong to the same classroom, family, clinic, company or village? Cluster-robust standard errors recognise that observations within a group may share unobserved shocks. They aggregate score contributions at the cluster level so repeated rows do not masquerade as independent information.
Did You Know? In cluster-robust inference, the number and balance of independent clusters can matter more than the raw number of rows. One hundred measurements from one group are not equivalent to one measurement from each of one hundred independent groups.
Full chapter index
Chapters 1–5 · Understand the question
Chapters 6–11 · Reproduce the example
Chapters 12–18 · Check assumptions
Chapters 19–24 · Explore applications
Chapters 25–36 · Study and verify
Ordinary heteroscedasticity-consistent covariance treats rows as independent. When responses within a cluster are correlated, row-level products omit cross-observation covariance. Cluster-robust covariance permits arbitrary dependence within each cluster while relying on independence, or suitable weak dependence, across clusters.
Statsmodels documents a cluster sandwich covariance that uses group labels and offers a small-sample correction. Read the cluster covariance documentation. The robust covariance API also records cluster-specific degrees-of-freedom behaviour. Read the API.
For cluster g, add the observation score vectors X_g^T e_g to form S_g. The one-way cluster meat is Σ_g S_g S_g^T. Bread matrices (X^T X)^−1 sit on both sides. Summing before squaring preserves the cross-products that represent within-cluster co-movement.
| Cluster | Score sum |
|---|---|
| A | 2 |
| B | -1 |
| C | 3 |
| D | -2 |
Suppose four independent clusters have scalar score sums 2, −1, 3 and −2. The cluster meat is 2²+(−1)²+3²+(−2)²=18. If each bread factor is 0.1, the variance is 0.1×18×0.1=0.18 and the standard error is sqrt(0.18)=0.4243.
| Meat | Bread | Variance | Standard error |
|---|---|---|---|
| 18 | 0.1 | 0.18 | 0.4243 |
If scores within a cluster tend to share a sign, squaring their sum includes positive cross-products. Row-level HC would square each score separately and miss those terms. Negative within-cluster association can also matter; clustering is not a rule that always increases every standard error.
Cluster at the level where the common shock or assignment dependence lives. Students taught in the same class may share a teacher and environment; patients treated by the same clinic may share procedures. A convenient identifier is not enough: the grouping needs a substantive dependence story.
In experiments, the randomisation unit is a strong clue. If treatment is assigned by school, pretending individual pupils were independently assigned exaggerates information. Analysis should respect design, and a small number of randomised groups needs methods tailored to that limitation.
The basic cluster sandwich is asymptotic in the number of clusters. With few clusters, standard errors and reference distributions can be unreliable even when each group contains many rows. Small-sample corrections, t references, wild cluster bootstrap or design-based methods may be considered with appropriate expertise.
A study with many tiny clusters and a few enormous ones may have less stable inference than its total count suggests. Report cluster count, minimum, median and maximum size, and whether the target predictor varies within or between clusters.
CHAPTER 10 OF 36 · Reproduce the example
10. Within-cluster versus between-cluster variation
If a predictor changes only between clusters, its coefficient may be identified largely by the number of clusters. Thousands of repeated rows cannot create new independent between-group contrasts. This is an effective-information argument, not a claim that within-cluster data are useless.
CHAPTER 11 OF 36 · Reproduce the example
11. Fixed effects do not remove all dependence
Cluster fixed effects can absorb time-invariant cluster means, but residuals may still correlate within groups over time. Fixed effects and cluster-robust covariance answer different questions: one changes the mean specification, the other changes uncertainty estimation.
A multilevel or random-effects model specifies a probability structure and can estimate group-level variation. Cluster-robust covariance is a less structured adjustment to coefficient uncertainty. The choice depends on the estimand, design, cluster count and modelling goals.
Pupils may be nested in classes, while workers can be crossed by firm and year. One-way clustering captures one dependence dimension. Two-way cluster methods combine cluster meats with an overlap correction; they require careful identifiers and adequate independent variation in each dimension.
Statsmodels documents a two-group cluster covariance that returns the combined covariance and the one-way components. Read the two-way documentation. Software availability does not decide whether two-way clustering is scientifically justified.
Suppose an educational programme is delivered by class. Pupils within a class share lessons and peer interactions. Cluster by class for an analysis that treats classes as independent assignment or sampling units, then report the number of classes and avoid implying that pupil count alone determines precision.
Employees in one firm share management, demand conditions and policies. Firm clustering can protect inference against within-firm residual dependence. If the data also span years with common economy-wide shocks, a time dimension may need separate attention.
Missing, duplicated or changing group identifiers can silently redefine dependence. Validate that each row has exactly the intended label, inspect cluster sizes and document how mergers, transfers or repeated entities were handled.
Applying a cluster covariance to a fitted OLS model leaves coefficients, fitted values and residuals unchanged. Only the covariance and derived inference change. If cluster structure also implies a different mean model, that model must be specified separately.
Compare a design-justified cluster result with conventional and row-level HC covariance, then examine alternative defensible cluster units. Treat large differences as a reason to understand dependence, not as permission to choose the preferred significance result.
State the cluster unit, number and size range of clusters, small-sample correction, coefficient estimate and cluster-robust interval.
Cluster covariance does not fix omitted cluster-level confounders, few-cluster identification, treatment spillovers across clusters, measurement error, selection or a misspecified mean. Independence across clusters must still be defended.
Students can compare sum-of-squares with square-of-sums to see exactly where within-cluster covariance enters, then connect the algebra to sampling and experimental design.
Create one row per cluster containing the summed score for each coefficient. Form each outer product S_g S_g^T, add them, apply any documented finite-sample factor, and multiply by the common bread matrices. Separately tabulate cluster counts and sizes.
Validate the group vector against the analysis rows, fit the intended mean model once, and request cluster covariance with explicit groups and documented corrections. Unit-test the four-cluster scalar example and save the software version and degrees-of-freedom setting.
Cluster inference supports education research, clinical studies, public policy, labour economics, market experiments and operations analysis. Good work also requires understanding the institution that creates groups and explaining effective information clearly to decision makers.
Simulate 40 classes with 20 pupils each using a class shock plus an individual shock. Compare conventional, HC and class-cluster standard errors. Hold 800 pupils fixed while changing the number of classes and observe which design improves between-class information.
Clustering is not a universal inflation button, a remedy for few clusters or a substitute for multilevel thinking. Fixed effects do not automatically eliminate within-group dependence, and the largest available grouping is not always the right one.
The White sandwich guide explains the bread–meat architecture. The Generalized Least Squares guide shows a model-based covariance approach. The omitted-variable-bias guide explains why covariance correction cannot solve confounding.
Students should draw the data hierarchy and name the independent sampling or assignment units. Parents can ask whether the analysis counts rows or genuinely independent groups. This keeps the discussion focused on design rather than on a single software label.
- Recalculate the four-cluster meat.
- Explain square-of-sums versus sum-of-squares.
- Identify the cluster unit in a school trial.
- Explain why 10,000 rows in five clusters remain difficult.
- Name one problem clustering cannot repair.
### Does clustering change coefficients? Not when applied as a covariance choice after the same OLS fit.
### Should I always use the largest group? No; use the dependence and design level.
### Are many rows enough? No; the number and balance of clusters matter.
### Can clusters overlap? Some designs require multiway methods, with additional assumptions.
Name the sampling unit, regression formula, target coefficient, dependence structure, covariance estimator and finite-sample choices. Show the conventional and robust uncertainty side by side when that comparison is useful. State what changed, what did not change and which assumptions remain open.
Common corrections rescale the covariance and adjust reference degrees of freedom using cluster and parameter counts. Their exact formula is software-dependent, so name the option and inspect documentation. A correction cannot manufacture independent clusters that the design did not collect.
When a regressor varies mostly between groups, precision is anchored by independent group contrasts. When it varies within groups, repeated observations can add information, but shared shocks still reduce the amount relative to fully independent rows.
Confirm a scientific dependence story, clean group labels, enough and reasonably balanced clusters, correct treatment of nesting or crossing, and a mean model that matches the estimand. Report cluster diagnostics with the interval.
Continue through the Mathematics Learning Hub. Reproduce the arithmetic by hand, then compare it with documented software output and explain any difference before relying on the result.
Extended practice laboratory
Practice case 1: Draw the hierarchy
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 1. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 2: Name the cluster unit
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 2. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 3: Count clusters
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 3. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 4: Tabulate cluster sizes
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 4. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 5: Build row scores
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 5. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 6: Sum scores within group
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 6. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 7: Square cluster sums
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 7. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 8: Assemble the meat
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 8. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 9: Apply the bread
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 9. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 10: Calculate the standard error
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 10. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 11: Compare row-level HC
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 11. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 12: Add positive dependence
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 12. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 13: Add negative dependence
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 13. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 14: Reduce cluster count
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 14. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 15: Unbalance group sizes
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 15. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 16: Move treatment to group level
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 16. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 17: Add cluster fixed effects
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 17. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 18: Check residual dependence
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 18. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 19: Consider two-way clusters
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 19. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 20: Validate group labels
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 20. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 21: Choose degrees of freedom
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 21. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 22: Reject the raw-n claim
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 22. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 23: Report effective information
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 23. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 24: Name remaining assumptions
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 24. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.
Practice case 25: Write the conclusion
Setup: Start from the article’s cluster-robust covariance worked mechanism for case 25. Task: Change the named quantity, recompute the affected covariance terms and compare with the original.
Check: Check the defining identity, keep the observation or time unit explicit, and state one diagnostic before interpreting the interval. Show the arithmetic, name the response and predictor units, and separate the numerical result from the claim it supports. Then vary one defensible assumption, calculate again and explain whether the conclusion changed because of the data, the fitted model or the validation purpose. Finish with one compact table or graph that could reveal a failure hidden by the summary.