Commit 2b166cb
callaway-santanna: make per-(g,t) analytical SE cluster-aware
CI codex R3 P0: the cluster wiring contract documented in REGISTRY.md
("cluster=X means CR1 Liang-Zeger on the IF") was honored at the
aggregate inference surface (overall_se, event-study, group, bootstrap)
but the per-cell public surface results.group_time_effects[(g,t)]["se"]
remained unit-level. Users inspecting per-cell ATT(g,t) inference under
cluster= got silently misleading SE/t/p/CI even though overall inference
was correctly cluster-robust.
Fix: new module-level _cluster_robust_se_from_per_gt_if helper that
aggregates the per-(g,t) IF by PSU and returns CR1 Liang-Zeger SE.
Applied at all 4 ATT(g,t) computation sites identified by the codex:
1. _compute_all_att_gt_vectorized (no-covariate vectorized batch) —
recompute se after building inf_info, overwrite group_time_effects
[(g,t)]["se"] which was set with the unit-level value
2. _compute_all_att_gt_covariate_reg (covariate-reg batch) — same pattern
3. Main panel single-cell loop (after _compute_att_gt_fast) — local
se_gt update flows into gte_entry["se"]
4. RC fit loop (after _compute_att_gt_rc) — uses resolved_survey.psu
(per-obs) instead of resolved_survey_unit.psu (per-unit)
The recompute is gated by `if psu is not None`, so cluster=None remains
bit-equal to pre-PR. For cluster=unit (each unit its own cluster), the
CR1 formula coincides with the unit-level IF formula (modulo ddof
conventions in the underlying OR path) — methodologically consistent
with Williams (2000) CR1-on-IF for IF-based estimators.
Tests:
- test_per_gt_analytical_se_changes_with_cluster: asserts at least one
(g,t) cell shows measurable SE divergence between cluster=None and
cluster="state" on a panel with intra-cluster correlation
- test_per_gt_se_matches_explicit_survey_design: asserts per-(g,t) SE
agrees (rel=1e-10) between bare cluster="state" and explicit
SurveyDesign(psu="state") — both activate the same CR1 aggregation
All 414 tests (test_staggered + test_staggered_rc + test_triple_diff +
test_honest_did + test_two_stage) pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 2449842 commit 2b166cb
2 files changed
Lines changed: 211 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
95 | 154 | | |
96 | 155 | | |
97 | 156 | | |
| |||
1035 | 1094 | | |
1036 | 1095 | | |
1037 | 1096 | | |
1038 | | - | |
| 1097 | + | |
1039 | 1098 | | |
1040 | 1099 | | |
1041 | 1100 | | |
1042 | 1101 | | |
1043 | 1102 | | |
1044 | 1103 | | |
1045 | 1104 | | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
1046 | 1121 | | |
1047 | 1122 | | |
1048 | 1123 | | |
| |||
1379 | 1454 | | |
1380 | 1455 | | |
1381 | 1456 | | |
1382 | | - | |
| 1457 | + | |
1383 | 1458 | | |
1384 | 1459 | | |
1385 | 1460 | | |
1386 | 1461 | | |
1387 | 1462 | | |
1388 | 1463 | | |
1389 | 1464 | | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
1390 | 1475 | | |
1391 | 1476 | | |
1392 | 1477 | | |
| |||
1820 | 1905 | | |
1821 | 1906 | | |
1822 | 1907 | | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
1823 | 1924 | | |
1824 | 1925 | | |
1825 | 1926 | | |
| |||
1912 | 2013 | | |
1913 | 2014 | | |
1914 | 2015 | | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
1915 | 2032 | | |
1916 | 2033 | | |
1917 | 2034 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4829 | 4829 | | |
4830 | 4830 | | |
4831 | 4831 | | |
| 4832 | + | |
| 4833 | + | |
| 4834 | + | |
| 4835 | + | |
| 4836 | + | |
| 4837 | + | |
| 4838 | + | |
| 4839 | + | |
| 4840 | + | |
| 4841 | + | |
| 4842 | + | |
| 4843 | + | |
| 4844 | + | |
| 4845 | + | |
| 4846 | + | |
| 4847 | + | |
| 4848 | + | |
| 4849 | + | |
| 4850 | + | |
| 4851 | + | |
| 4852 | + | |
| 4853 | + | |
| 4854 | + | |
| 4855 | + | |
| 4856 | + | |
| 4857 | + | |
| 4858 | + | |
| 4859 | + | |
| 4860 | + | |
| 4861 | + | |
| 4862 | + | |
| 4863 | + | |
| 4864 | + | |
| 4865 | + | |
| 4866 | + | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
| 4874 | + | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
| 4881 | + | |
| 4882 | + | |
| 4883 | + | |
| 4884 | + | |
| 4885 | + | |
| 4886 | + | |
| 4887 | + | |
| 4888 | + | |
| 4889 | + | |
| 4890 | + | |
| 4891 | + | |
| 4892 | + | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
| 4898 | + | |
| 4899 | + | |
| 4900 | + | |
| 4901 | + | |
| 4902 | + | |
| 4903 | + | |
| 4904 | + | |
| 4905 | + | |
| 4906 | + | |
| 4907 | + | |
| 4908 | + | |
| 4909 | + | |
| 4910 | + | |
| 4911 | + | |
| 4912 | + | |
| 4913 | + | |
| 4914 | + | |
| 4915 | + | |
| 4916 | + | |
| 4917 | + | |
| 4918 | + | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
| 4922 | + | |
| 4923 | + | |
4832 | 4924 | | |
4833 | 4925 | | |
4834 | 4926 | | |
| |||
0 commit comments