Skip to content

fix(sun_abraham): per-cohort reference, exclude cohorts with no pre-period, NaN for unidentified coefficients - #908

Merged
igerber merged 1 commit into
mainfrom
sunab-reference-support
Nov 25, 2026
Merged

igerber merged 1 commit into
mainfrom
sunab-reference-support

Conversation

@igerber

@igerber igerber commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the TODO.md row "SunAbraham: a cohort not observed at its own reference relative period ... overall_att comes back NaN".

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. New field SunAbrahamResults.reference_event_times records the distinct bases; compute_pretrends_power refuses a fit with more than one.
  • Cohorts with no pre-treatment observation are excluded with a warning (ValueError when none is left; NotImplementedError under survey_design=, tracked in TODO.md).
  • Identification guard. Identification is decided exactly from the observation pattern before the solve (connected sets of units and periods; equivalent to the null space of the explicit-dummy design). 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.
  • event_study_vcov is NaN only on the rows and columns 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.

Before / after

Noiseless 90-unit, 8-period panel, cohorts 3 and 5 plus never-treated, true effect 2 + 0.5 e (unless noted):

Panel Before After
cohort treated at the first period ATT NaN, 7 wrong cohort coefficients, e = 0 row 0.0 (true 2.0) cohort excluded with a warning, every estimate exact
cohort first observed at e = 0 ATT NaN, 5 wrong, e = 0 row -0.25 excluded, exact
cohort with a gap at e = -1 e = -2 row NaN plus a rank warning exact, no NaN, warns "cohort 5: -2"
never-treated absent at calendar period 4 (cohort 5's e = -1) e = -2 row NaN exact (cohort 5 normalized at -2)
never-treated absent at calendar period 6 ATT NaN, e = 3 row 2.25 (true 3.5) 2 cells NaN, everything else exact
cohort whose units are observed at disjoint periods 4 wrong coefficients 5 cells NaN, none wrong
one cohort entirely at survey weight 0 (noise 0.5) ATT NaN, 5 NaN rows ATT 3.138, rows finite
pairs bootstrap, reversed index labels SE 0.108541 SE 0.095793 (the default-index value)
pairs bootstrap, shifted index labels IndexError SE 0.095793
load_divorce_laws() (cohort 1968 treated from the first panel year) ATT NaN after "dropping 1 of 261 columns" cohort 1968 excluded with a warning; ATT 0.19170, SE 0.05798, identical to the fit on the panel without that cohort

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)

  • Method name(s): Sun-Abraham interaction-weighted estimator
  • Paper / source link(s): Sun, L. and Abraham, S. (2021), "Estimating dynamic treatment effects in event studies with heterogeneous treatment effects", Journal of Econometrics 225(2). https://doi.org/10.1016/j.jeconom.2020.09.006
  • Any intentional deviations from the source (and why):
    • The three behaviors above are the library's rule for panels in which some cohort-by-period coefficient is not identified at the common reference period, each recorded as a **Note:** in the SunAbraham section of docs/methodology/REGISTRY.md.
    • Deviation from R (REGISTRY **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 matches feols with explicit cohort-by-period dummies to 1e-13 (coefficients) and 4e-12 (SEs), and the exclusion matches sunab on the reduced panel to 6e-15.
    • Difference from 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 added/updated:
    • tests/test_sun_abraham.py: 47 new tests in TestSunAbrahamCohortReference, TestSunAbrahamReferenceFields, TestSunAbrahamIdentificationGuard, TestStructuralIdentificationHelper, TestSunAbrahamIdentificationSurvey, TestSunAbrahamBootstrapRowPositions. They include exact recovery on noiseless panels, exclusion equal to the reduced fit at rtol=1e-12, the fallback against an independent np.linalg.lstsq explicit-dummy fit, and the guard against a full-SVD null-space oracle on 200 helper panels and 50 fitted panels (default path and hc2_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_last updated: the append-only invariant now ends with reference_event_times.
    • 136 SunAbraham tests pass on the Python and Rust backends; 4,390 pass across the 46 other test files that reference SunAbraham.
  • Backtest / simulation / notebook evidence (if applicable): tutorials 02, 09 and 11 (the only ones that fit SunAbraham) execute under --nbmake unchanged; no notebook is edited.
  • Sibling audit (report only): the gap and no-pre-period panels through CallawaySantAnna, ImputationDiD, TwoStageDiD and LPDiD are fine and EfficientDiD raises on unbalanced panels. StackedDiD returns 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

  • Confirm no secrets/PII in this PR: Yes

Changelog

  • changelog.d/ fragment added (or N/A - no user-visible change): Yes (changelog.d/20261125-sunab-reference-support.md, Fixed + Behavioral Changes)

…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.
@github-actions

Copy link
Copy Markdown

Overall assessment

✅ Looks good — No unmitigated P0 or P1 findings identified in the supplied diff.

Executive summary

  • Affected methods: Sun–Abraham interaction-weighted estimation and Roth pre-trends power analysis.
  • Reference selection, cohort exclusion, and unidentified-cell handling follow the new registry Notes.
  • Aggregation preserves NaN inference for unidentified effects while retaining covariance for identified rows.
  • Syntax, six extracted reference-selection cases, and changelog validation passed.
  • Full tests could not run because NumPy and pytest are unavailable. Primary-paper retrieval was also unavailable; methodology review used the registry, docstrings, and local paper-review notes.

Methodology

P3 — Documented methodological choices; no action required.
Location: docs/methodology/REGISTRY.md:L2092-L2095

Impact: Fallback references can mix normalization bases, and unsupported cohorts are excluded or explicitly refused under survey designs. These behaviors and the departure from fixest::sunab are documented. The pre-trends adapter rejects mixed references consistently with the stated normalization requirement.

Concrete fix: None required.

Code Quality

No findings. Changed inference paths use safe_inference(), and all visible callers handle the extended saturated-regression return value.

Performance

No findings from source review. Runtime performance was not measured.

Maintainability

No findings. Reference selection and structural identification are isolated helpers; the results field is appended without moving existing positional fields.

Tech Debt

P3 — Survey limitations are tracked.
Location: TODO.md:L50-L51

Impact: Unsupported domain estimation raises explicitly; the existing survey-array alignment limitation is recorded.

Concrete fix: None required for this PR.

Security

No findings in the changed code.

Documentation/Tests

No 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.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Nov 25, 2026
@igerber
igerber merged commit eab08ef into main Nov 25, 2026
43 of 44 checks passed
@igerber
igerber deleted the sunab-reference-support branch November 25, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ci Triggers CI test workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant