Appendix — Solutions — Problem Set 5.4 (Re-running Petersen’s Clustering Comparison on a Panel)
Full worked solutions to book/weeks/week-05/ps5.4.md. Notation follows CONVENTIONS §3, Ch 2.4, and Ch 5.4. The pooled panel model is y_{it}=\beta_0+\beta_1 x_{it}+\varepsilon_{it} with i indexing firms, t indexing years; the error variance–covariance matrix is \boldsymbol\Omega=\operatorname{Var}(\boldsymbol\varepsilon\mid\mathbf{X}); the general OLS variance is the sandwich (\mathbf{X}'\mathbf{X})^{-1}\mathbf{X}'\boldsymbol\Omega\mathbf{X}(\mathbf{X}'\mathbf{X})^{-1}; the cluster-robust filling sums outer products \mathbf{X}_g'\hat{\boldsymbol\varepsilon}_g\hat{\boldsymbol\varepsilon}_g'\mathbf{X}_g over clusters g=1,\dots,G. Petersen models the error as an additive variance-component decomposition \varepsilon_{it}=\gamma_i+\delta_t+\nu_{it}. Citation: Petersen, M. A. (2009). Estimating Standard Errors in Finance Panel Data Sets: Comparing Approaches. Review of Financial Studies, 22(1), 435–480. Also referenced by name: Fama & MacBeth (1973); Cameron, Gelbach & Miller (2008, 2011); Thompson (2011); White (1980); Newey & West (1987). All coverage figures are the labeled illustrative values from the problem set, chosen to reproduce Petersen’s qualitative pattern, not transcribed from his tables.
Task 1 — The firm-effect / time-effect taxonomy (14 pts)
(a) (4 pts) Maya is describing a firm effect: a firm’s residual is correlated with itself across years. The nonzero off-diagonals of \boldsymbol\Omega are the pairs (\varepsilon_{it},\varepsilon_{is}) with the same firm i and different years t\neq s; pairs across different firms (i\neq j) are zero. So \boldsymbol\Omega is block-diagonal with one dense block per firm, each block spanning that firm’s years.
Priya is describing a time effect: all firms’ residuals move together within a year. The nonzero off-diagonals are the pairs (\varepsilon_{it},\varepsilon_{jt}) with the same year t and different firms i\neq j; pairs in different years are zero. With the data laid out firm-by-firm this is not a clean block diagonal — the correlated entries are scattered — but it is block-diagonal if you re-sort the panel by year: one dense block per year, spanning all firms in that year.
(b) (4 pts) Maya should cluster by firm; Priya should cluster by time (Priya could alternatively absorb the common shock with time fixed effects, a dummy per year). The matching reason: the cluster-robust sandwich allows arbitrary correlation within each cluster and assumes zero correlation across clusters. Clustering by firm therefore permits exactly the within-firm-across-year correlation Maya has (and forbids cross-firm correlation, which she does not have); clustering by time permits exactly the within-year-across-firm correlation Priya has. The clustering dimension is the bet about which block structure \boldsymbol\Omega has.
(c) (3 pts) With \varepsilon_{it}=\gamma_i+\delta_t+\nu_{it} and the three components independent, “pure firm effect” means the time component is switched off, \operatorname{Var}(\delta_t)=0, leaving \varepsilon_{it}=\gamma_i+\nu_{it}. For the same firm i in two different years t\neq s, the only shared piece is \gamma_i (the \nu’s are independent across years and \delta is gone), so \operatorname{Cov}(\varepsilon_{it},\varepsilon_{is})=\operatorname{Cov}(\gamma_i+\nu_{it},\,\gamma_i+\nu_{is})=\operatorname{Var}(\gamma_i)=\sigma_\gamma^2\quad(t\neq s). That constant, nonzero within-firm covariance \sigma_\gamma^2 is precisely the off-diagonal that classical OLS (which assumes it is zero) ignores. Across firms (i\neq j) the covariance is zero — different \gamma’s, independent.
(d) (3 pts) The OLS SE is barely hurt when the regressor has (near-)zero within-firm correlation — i.e., when x_{it} is essentially pure noise within each firm (\rho_x\approx 0). The Moulton-style bias scales with the product \rho_x\rho_\varepsilon (Ch 2.4 §4.1), so even a strong error correlation \rho_\varepsilon does little damage if it is multiplied by an x that does not persist within firm. Of the two regressors, leverage (Maya’s) is the persistent-within-firm one — a firm’s capital structure changes slowly, so a highly levered firm stays highly levered year after year, giving large \rho_x. A climate-exposure score can also be sticky, but Devon’s blanket claim is wrong: the error structure alone does not determine the damage; it is the error correlation times the regressor correlation. Maya’s leverage panel is the more dangerous one because both factors are large — exactly the corporate-finance case Petersen warns about.
Task 2 — Read the simulated coverage table; name the right SE (20 pts)
(a) (4 pts) Coverage 0.71 means that when this analyst builds an interval she calls “95% confident,” the interval actually contains the true \beta only about 71% of the time — so it is wrong about 29% of the time, not the advertised 5%. The SE errs in the dangerous direction: it is too small (the reported intervals are too narrow), so the analyst is overconfident — she will stamp “significant, p<0.05” on results an honest SE would call far shakier. (Petersen’s central worry: published t-stats inflated, significance stars decorative.)
(b) (5 pts) White/HC1 covers 0.73, essentially tied with OLS’s 0.71, because White SEs fix the diagonal of \boldsymbol\Omega but are blind to its off-diagonals. White lets each observation have its own variance \sigma_i^2 (it corrects heteroskedasticity), but it still sums over single observations and so assumes \operatorname{Cov}(\varepsilon_{it},\varepsilon_{is})=0 — it keeps only the squared-residual terms \hat\varepsilon_{it}^2 and throws away every within-firm cross-product \hat\varepsilon_{it}\hat\varepsilon_{is}. But the firm effect is an off-diagonal phenomenon (Task 1c: the within-firm covariance equals \sigma_\gamma^2\neq 0), so White is correcting the one thing that is not the problem and ignoring the thing that is. Hence it lands right next to OLS. The one-sentence warning: “robust” in “robust standard errors” means robust to heteroskedasticity only — it is not robust to within-cluster correlation, so the marketing word is a trap if you read it as “robust to everything.”
(c) (4 pts) The general principle: a method works when its assumed shape for \boldsymbol\Omega matches the true one. Cluster-by-firm assumes dense within-firm blocks and zero across firms — exactly the firm-effect truth — so it recovers 0.94. Cluster-by-time assumes dense within-year blocks (correlation across firms within a year) and zero otherwise; in a pure firm-effect world there is no within-year cross-firm correlation, so cluster-by-time is making a bet about a structure that is not there. It captures none of the real within-firm correlation and so stays at 0.73, no better than White. Being “a clustering method” is not enough — it must cluster on the right dimension.
(d) (4 pts) In the time-effect column the symmetry flips: cluster-by-time is now the method that recovers \approx 0.94, and cluster-by-firm is the one that fails (0.72), while OLS and White again undercover at \approx 0.70. This tells you that “cluster by firm” is not a universally safe default — it is correct only when a firm effect is present; in a time-effect world it is as wrong as not clustering at all. You must diagnose the dependence first (Task 3), not reflexively cluster by firm.
(e) (3 pts) When both effects are present, \boldsymbol\Omega has off-diagonals in two organizations at once: within-firm-across-year blocks and within-year-across-firm blocks. Cluster-by-firm captures the first family of cross-products but ignores the second; cluster-by-time captures the second but ignores the first — so each catches only part of the dependence and each undercovers (0.78, 0.79). Two-way clustering allows correlation along both dimensions simultaneously, so it accounts for both families of off-diagonals and recovers 0.94. It is the only method whose bet matches a \boldsymbol\Omega that is correlated in both directions.
Task 3 — Diagnose the dependence: Petersen’s self-diagnostic (16 pts)
(a) (5 pts) Anchor on the White SE = 0.042 as the baseline and see which clustering moves it. - Firm-clustering: 0.045/0.042\approx 1.07 — a $$7% move, essentially nothing. - Time-clustering: 0.120/0.042\approx 2.86 — it nearly triples the SE.
Time-clustering moves the SE far more than firm-clustering, so by Petersen’s diagnostic the common time effect dominates Sam’s panel: the residuals are correlated across firms within a month (a market-wide monthly shock) far more than across years within a firm. The correct clustering choice is cluster by time (cluster on month).
(b) (4 pts) The diagnostic reads the actual residuals of this regression; the prior expectation is just a guess about a generic dataset. Sam’s drilled intuition (“firm effects dominate”) came from corporate-finance leverage panels, whose left-hand-side variable is sticky firm-level accounting data; his current left-hand side is a monthly return alpha, whose dominant comovement is the market month-to-month. Same firms, different outcome, different \boldsymbol\Omega. This is the Ch 5.4 point that the right clustering depends on the left-hand-side variable, not just the dataset: the dependence lives in the residuals, and different outcomes carry different shocks. So when the prior and the diagnostic disagree, the diagnostic wins — it is measuring the thing (residual correlation) that the clustering choice is supposed to match.
(c) (4 pts) Two-way (0.122) sitting barely above time-clustered (0.120) means the firm dimension contributes almost nothing beyond what the time dimension already captured: the firm component of the residuals is small relative to the time component. Two-way clustering adds the firm-block cross-products and subtracts the doubly-counted White diagonal (see Task 6 / PS 2.4 P6e); when the firm blocks carry little extra correlation, that addition is nearly offset and two-way \approx time-clustered. So here two-way costs almost nothing (it does not blow up the SE) but also adds almost nothing (it does not change the verdict) — fine to report, but the honest one-way story is cluster-by-time.
(d) (3 pts) The close OLS-vs-White agreement (0.040 vs 0.042) tests only whether there is meaningful heteroskedasticity — whether the diagonal of \boldsymbol\Omega varies. Their agreement says “not much heteroskedasticity,” which is true and irrelevant. It says nothing about the off-diagonals — the within-cluster correlation — because neither OLS nor White looks at off-diagonals at all; both assume them away. The thing that exposes clustering’s importance is the gap between White and the clustered SE (here White 0.042 vs time-clustered 0.120, a near-tripling), which is exactly the comparison Sam skipped. Concluding “no clustering needed” from OLS\approxWhite is the classic Petersen mistake: it confuses “no heteroskedasticity” with “no dependence.”
Task 4 — The few-clusters caution: consistency in G, not N (16 pts)
(a) (4 pts) Coverage decays monotonically as the cluster count falls: 0.94 at G=30, down to 0.74 at G=5. The paradox: Priya is using the correct clustering dimension for her world — yet she still undercovers badly when G=5. Being right about the dimension does not save her because the cluster-robust estimator is only consistent as G\to\infty, not as N\to\infty (Ch 2.4 §4.3). With G=5 clusters the estimator is built from only five pieces and is itself a noisy, downward-biased estimate of the true sampling variability — so the intervals are again too narrow.
(b) (4 pts) The cluster-robust filling estimates the true variance by averaging the G cluster-level outer products \mathbf{X}_g'\hat{\boldsymbol\varepsilon}_g\hat{\boldsymbol\varepsilon}_g'\mathbf{X}_g — it treats the clusters as the independent units and uses their spread to gauge uncertainty. With only G=5 such pieces, that average is a very noisy estimate of the true cluster-level variance. The bias is specifically downward because (as with OLS residuals in Ch 2.4 §3.3) the residuals \hat{\boldsymbol\varepsilon}_g are computed from a \hat\beta that was fit to the same data, so they are systematically too small; with few clusters there is no degrees-of-freedom cushion to offset this, and the estimated variance comes out too small — overconfident. It is the Moulton disease one level up: there, observations within a cluster were not independent pieces of evidence; here, the clusters themselves are too few to be a reliable sample of independent pieces.
(c) (4 pts) Adding 200 more firms per year increases N but leaves G=5 years unchanged. The cluster-robust estimator’s precision lives in the number of clusters G, not in N: more firms within each of the 5 years just make each year’s block bigger, not more numerous, so the average over clusters is still an average over only 5 noisy pieces. (Worse: if there is a genuine time effect, all those extra firms in a given year share that year’s shock \delta_t — they are not fresh independent evidence about \beta.) The only thing that helps the few-clusters problem is more clusters — more years, here — which Priya cannot manufacture by sampling more firms. This is the exact analogue of PS 2.4 Problem 4(c): pouring observations into existing clusters does not buy the independence the formula needs; more clusters does.
(d) (4 pts) Two concrete fixes: 1. Use the t-distribution with G-1 degrees of freedom instead of the normal’s 1.96. With G=5 this swaps the critical value for t_{0.975,\,4}\approx 2.78, widening the interval to partly compensate for the noisy SE. It is cheap but only a partial correction. 2. Wild cluster bootstrap (Cameron, Gelbach & Miller 2008, Review of Economics and Statistics, 90(3), 414–427): resample whole clusters (flipping cluster-level residual signs) many times to build the sampling distribution of the t-statistic directly, rather than trusting the asymptotic normal. This is the recommended fix when G is genuinely small.
Rough rule of thumb: worry when G\lesssim 30–50. Below that, “robust to within-cluster correlation” stops being a free lunch because the price of allowing arbitrary within-cluster correlation is that you must estimate it from the across-cluster spread — and with too few clusters that estimate is itself unreliable, so the cure reintroduces the overconfidence it was meant to remove.
Task 5 — Fama–MacBeth vs. cluster-by-time (18 pts)
(a) (5 pts) Fama–MacBeth runs a separate cross-sectional regression each year, producing one slope \hat\beta_t per year, and builds the SE from \operatorname{sd}(\hat\beta_t)/\sqrt{T}. A common time shock \delta_t hits every firm in year t together, so it shifts that year’s entire cross-section — it is absorbed into the year-t regression and shows up as one contribution to the variability of \hat\beta_t across years. Because the SE is built from the year-to-year spread of the slopes, it automatically counts each year’s common shock exactly once and treats the years (not the firm-years) as the independent units. That is the same bet as cluster-by-time: “correlation is arbitrary within a year, independent across years.” Same assumed \boldsymbol\Omega, so both cover \approx 0.94 in the time-effect world.
(b) (5 pts) A persistent firm component \gamma_i is shared by firm i in every year. So when you run the year-t cross-section and the year-(t+1) cross-section, the same firms carry the same \gamma_i into both — which makes the cross-sectional slopes \hat\beta_t and \hat\beta_{t+1} positively correlated, not independent draws. Fama–MacBeth’s SE formula \operatorname{sd}(\hat\beta_t)/\sqrt{T} is the SE of a mean only if the \hat\beta_t are independent; when they are positively correlated, the true variance of \bar\beta is larger than \operatorname{Var}(\hat\beta_t)/T (the cross-terms \operatorname{Cov}(\hat\beta_t,\hat\beta_s)>0 are omitted), so FM understates the sampling variability and undercovers (0.79). Slogan: Fama–MacBeth corrects for a time effect but is blind to a firm effect.
(c) (4 pts) Fama–MacBeth is the right tool when a time effect dominates (a common per-period shock, weak within-firm persistence) — the classic asset-pricing cross-section. It is the wrong tool when a firm effect dominates — the typical corporate-finance panel, where firm characteristics (leverage, size, governance) persist for years — because then the yearly slopes are serially dependent and FM undercovers. Petersen argues the firm effect is the common corporate-finance case, which is why the reflex to use FM there is dangerous. If you suspect a firm effect dominates, prefer clustering by firm (the one-way fix that allows arbitrary within-firm-across-year correlation).
(d) (4 pts) No, they are not interchangeable in the sense the classmate means. What FM and cluster-by-time share is that both treat time as the unit of dependence — FM by averaging across years, cluster-by-time by clustering on year — so both assume independence across years within a firm. That assumption is exactly what a firm effect violates, which is why both fail in the firm-effect world (0.79 and 0.73). The classmate’s proposed “fix” — switching from FM to cluster-by-time — changes nothing, because it swaps one time-based method for another. To fix a firm-effect problem you must cluster on the firm dimension (or, if both effects are present, cluster two-way). The lesson: matching the method to the dominant effect is what matters, not switching between two methods that make the same wrong bet.
Task 6 — Replication design: the Monte Carlo coverage experiment (16 pts)
(a) (5 pts) (i) The known truth. In this experiment we build the world ourselves: we set the true slope \beta=0.30 and the true error structure (which variance components are on) in simulate_panel, so we know both the true \beta and — by drawing many panels — the true sampling variability of \hat\beta_1. Real data can never give us this: with real data we never observe the true \beta or the true \boldsymbol\Omega, so we could never check whether a method’s reported SE is right. A simulation is the only place the answer key exists — this is Petersen’s identification move (Ch 5.4 §2): not causal identification, but identifying the truth by constructing it. (ii) The two numbers per method. The true SE is the standard deviation of the S estimates \hat\beta_1 across the simulated panels (computable because we have many draws). The mean estimated SE is the average of that method’s reported \widehat{\operatorname{se}} across the S panels. (iii) Coverage. For each panel, form the interval \hat\beta_1\pm 1.96\,\widehat{\operatorname{se}} and record whether it contains \beta=0.30; coverage is the fraction of the S panels whose interval contained the truth. Method M is correct when all three agree: mean estimated SE \approx true SE (ratio \approx 1), and coverage \approx 0.95. An overconfident method shows mean estimated SE < true SE (ratio <1) and coverage \ll 0.95.
(b) (4 pts) Experiment 1 (firm effect). Set structure="firm" — the firm component \gamma_i on, the time component \delta_t off (\texttt{time\_sd}=0), idiosyncratic noise on. Crucially, the regressor x_{it} must carry a persistent firm component (in the harness, x is built from a firm piece + a time piece + noise). By the Moulton logic (Ch 2.4 §4.1, Task 1d), the OLS-SE bias scales with \rho_x\rho_\varepsilon; if x were pure within-firm noise (\rho_x\approx 0), even a strong firm effect in the errors would barely bias the OLS SE, and the experiment would show nothing. Predicted table: OLS and White both undercover (mean SE well below true SE, coverage well below 0.95); cluster-by-firm recovers \approx 0.95; cluster-by-time does not help; two-way is fine (it nests cluster-by-firm).
(c) (4 pts) Experiment 2 (time effect). Flip with structure="time" — firm component off, time component on. Predicted: now cluster-by-time is the method that matches the truth (\approx 0.95), while cluster-by-firm fails — the mirror image of Experiment 1. Time-FE aside: re-run the regression as y ~ x + C(year) (a dummy per year). The time fixed effects absorb the common per-year shock \delta_t by removing each year’s mean, so they should largely eliminate the time effect from the residuals and restore near-nominal coverage even under plainer SEs. This dramatizes the Ch 2.4 point (and PS 2.4 Task 3) that fixed effects and clustering do different jobs: a fixed effect removes a mean (the level of the year-t shock), whereas clustering handles a covariance (the within-cluster correlation). A time FE can remove a fully common shock because it is a single level per period; it cannot substitute for clustering when the within-group correlation is not a simple shared mean.
(d) (3 pts) Experiment 3 (few clusters). Start from the time-effect world where cluster-by-time covers \approx 0.95, then shrink n_years (the number of time clusters G) — e.g., sweep 30\to 20\to 12\to 8\to 5. Predicted: coverage falls monotonically below 0.95 as G shrinks, even though you are using the correct clustering (Task 4). Watching the correct method undercover on data whose truth you set yourself is more convincing than reading the caveat in prose because you cannot dismiss it as a quirk of someone’s real dataset — you controlled the world, you know the method is “right,” and you still see it fail, which is the only way the few-clusters warning becomes something you know rather than something you were told.
End of solutions for PS 5.4. Cross-references: Ch 5.4 (Reader’s Guide to Petersen 2009 — simulation-as-proof, the firm/time/both taxonomy, the cluster-firm-then-cluster-time self-diagnostic, the few-clusters caveat, the FM critique, the three nb5.4 exercises); Ch 2.4 §4.1 (Moulton factor), §4.2 (cluster-robust sandwich), §4.3 (few-clusters caveat), §5 (HAC), §6 (Petersen taxonomy and two-way clustering); PS 2.4 Problem 6 (the same taxonomy as a recipe) and Problem 4 (Moulton/few-clusters arithmetic). Key verdicts: T1 firm effect → cluster by firm, time effect → cluster by time, Moulton bias needs persistent x; T2 OLS & White undercover under firm/time effect, matching clustering restores 0.95, two-way needed under both; T3 diagnostic — bigger SE move points at the dominant effect (here time); T4 consistency in G not N, downward bias at small G, fixes = t(G-1) and wild cluster bootstrap; T5 FM corrects time but is blind to firm, FM ≈ cluster-by-time both fail under a firm effect; T6 design = build the truth, compare mean-SE to true-SE plus coverage. nb5.4 (Petersen clustering replication) is where the student regenerates every illustrative table. Looks ahead to Bertrand–Duflo–Mullainathan (2004), the same within-group serial-correlation disease in a difference-in-differences setting.