Repository navigation
fix(sun_abraham): per-cohort reference, exclude cohorts with no pre-period, NaN for unidentified coefficients - #908
Conversation
…eriod, NaN for unidentified coefficients SunAbraham omitted one relative period, e = -1 - anticipation, for every cohort. Whenever a cohort-by-period coefficient was not identified in that design, QR dropped one unnamed column (data-dependent, often a post-treatment one), the coefficients sharing the dependency were measured against it, and those numbers were pooled into the event-study rows and the overall ATT. On the default within-transform path the deficiency was often not detected at all. - Per-cohort reference: a cohort that cannot be normalized at e = -1 - anticipation (not observed there, or no never-treated observation at that calendar period) is normalized at its latest usable pre-treatment period, with a warning. SunAbrahamResults.reference_event_times records the distinct bases; pre-trends power refuses a fit with more than one. - A cohort with no pre-treatment observation is excluded with a warning (NotImplementedError under survey_design=). - Identification guard: identification is decided exactly from the observation pattern before the solve (connected sets of units and periods). A minimal set of unidentified cells gets no design column; every unidentified coefficient, and every pooled row containing one, is NaN. rank_deficient_action="error" raises instead, on the full-sample fit only: a bootstrap draw or replicate returns NaN for what it cannot identify and is dropped, so the pairs bootstrap never substitutes the original estimate for such a draw. When every candidate cell is unidentified the fit reports them as NaN instead of raising the generic "No valid interactions" error. - event_study_vcov is NaN only on the rows that contain an unidentified cell; replicate-weight variances are computed over the identified entries. Also fixed on the same path: - both bootstrap paths used index labels as row positions (wrong SE or IndexError on a frame whose index is not 0..n-1); - a cell with zero total survey weight got an all-zero column whose NaN coefficient was pooled at weight zero, turning identified rows NaN. fixest::sunab has the same defect on these panels; the behavior is a documented deviation from R. Panels in which every cohort is observed at the reference period are unchanged.
Overall assessment✅ Looks good — No unmitigated P0 or P1 findings identified in the supplied diff. Executive summary
MethodologyP3 — Documented methodological choices; no action required. Impact: Fallback references can mix normalization bases, and unsupported cohorts are excluded or explicitly refused under survey designs. These behaviors and the departure from Concrete fix: None required. Code QualityNo findings. Changed inference paths use PerformanceNo findings from source review. Runtime performance was not measured. MaintainabilityNo findings. Reference selection and structural identification are isolated helpers; the results field is appended without moving existing positional fields. Tech DebtP3 — Survey limitations are tracked. Impact: Unsupported domain estimation raises explicitly; the existing survey-array alignment limitation is recorded. Concrete fix: None required for this PR. SecurityNo findings in the changed code. Documentation/TestsNo findings. The PR includes a changelog fragment and substantial regression coverage for identification, reference provenance, zero weights, and bootstrap indexing. The reported full-suite results could not be independently verified in this environment. |
Summary
Closes the TODO.md row "
SunAbraham: a cohort not observed at its own reference relative period ...overall_attcomes back NaN".SunAbrahamomitted one relative period,e = -1 - anticipation, for every cohort. Whenever a cohort-by-period coefficient was not identified in that design, QR dropped one unnamed column (data-dependent, often a post-treatment one), the coefficients sharing the dependency were measured against it, and those numbers were pooled into the event-study rows and the overall ATT. On the default within-transform path the deficiency was often not detected at all.e = -1 - anticipation(not observed there, or no never-treated observation at that calendar period) is normalized at its latest usable pre-treatment period, with a warning. New fieldSunAbrahamResults.reference_event_timesrecords the distinct bases;compute_pretrends_powerrefuses a fit with more than one.ValueErrorwhen none is left;NotImplementedErrorundersurvey_design=, tracked in TODO.md).rank_deficient_action="error"raises instead, on the full-sample fit only: a bootstrap draw or replicate returns NaN for what it cannot identify and is dropped.event_study_vcovis NaN only on the rows and columns that contain an unidentified cell; replicate-weight variances are computed over the identified entries.IndexErroron a frame whose index is not0..n-1); a cell with zero total survey weight got an all-zero column whose NaN coefficient was pooled at weight zero, turning identified rows NaN.Before / after
Noiseless 90-unit, 8-period panel, cohorts 3 and 5 plus never-treated, true effect
2 + 0.5 e(unless noted):e = 0row 0.0 (true 2.0)e = 0e = 0row -0.25e = -1e = -2row NaN plus a rank warninge = -1)e = -2row NaNe = 3row 2.25 (true 3.5)IndexErrorload_divorce_laws()(cohort 1968 treated from the first panel year)On 50 random-missingness panels, 14 had a wrong finite cohort coefficient before (5 of them with no rank-deficiency warning at all); none after. Panels in which every cohort is observed at the reference period, with never-treated units observed at those calendar periods, are unchanged: ten baseline configurations compare exactly equal on both backends, and the tutorial-09 castle-doctrine fit is bit-identical.
Methodology references (required if estimator / math changes)
**Note:**in the SunAbraham section ofdocs/methodology/REGISTRY.md.**Deviation from R:**):fixest::sunab(0.14.2) has the same defect on these panels. On the gap panel it removes a column by collinearity and reports ATT 1.847 (ours 3.021, truth 3.05); with the no-pre-period cohort left in it reports 2.140 (2.74379 on the reduced panel, which we match). Where the design is identified the two agree: the fallback fit matchesfeolswith explicit cohort-by-period dummies to 1e-13 (coefficients) and 4e-12 (SEs), and the exclusion matchessunabon the reduced panel to 6e-15.WooldridgeDiD(stated in the Notes): it normalizes at the latest supported pre-period and refuses a cohort whose units split into disconnected groups; here the reference is the latest usable observed pre-period and whatever that leaves unidentified is reported as NaN.Validation
tests/test_sun_abraham.py: 47 new tests inTestSunAbrahamCohortReference,TestSunAbrahamReferenceFields,TestSunAbrahamIdentificationGuard,TestStructuralIdentificationHelper,TestSunAbrahamIdentificationSurvey,TestSunAbrahamBootstrapRowPositions. They include exact recovery on noiseless panels, exclusion equal to the reduced fit atrtol=1e-12, the fallback against an independentnp.linalg.lstsqexplicit-dummy fit, and the guard against a full-SVD null-space oracle on 200 helper panels and 50 fitted panels (default path andhc2_bm). 43 of the first 45 fail on the unmodified source.tests/test_v4_cluster_policy.py::TestClusterMetadata::test_sun_abraham_results_field_is_appended_lastupdated: the append-only invariant now ends withreference_event_times.SunAbraham.SunAbraham) execute under--nbmakeunchanged; no notebook is edited.CallawaySantAnna,ImputationDiD,TwoStageDiDandLPDiDare fine andEfficientDiDraises on unbalanced panels.StackedDiDreturns shifted estimates with no warning on ragged event windows (ATT 2.664 for a true 2.5); that is logged as a TODO.md row, not fixed here.Security / privacy
Changelog
changelog.d/20261125-sunab-reference-support.md, Fixed + Behavioral Changes)