Skip to content

fix(survey): per-cell ATT(g,t) SEs honor replicate and PSU designs (CallawaySantAnna, staggered TripleDifference) - #890

Merged
igerber merged 1 commit into
mainfrom
per-cell-design-se
Nov 22, 2026
Merged

igerber merged 1 commit into
mainfrom
per-cell-design-se

Conversation

@igerber

@igerber igerber commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • Per-cell ATT(g,t) standard errors now honor the survey design in three lanes where they silently reported a weights-only SE while the aggregate SEs of the same fit were design-based:
    • CallawaySantAnna with SurveyDesign(replicate_weights=...)
    • staggered TripleDifference with SurveyDesign(replicate_weights=...)
    • staggered TripleDifference with SurveyDesign(psu=...)
  • One dispatch helper, staggered._design_se_for_cell, now carries the per-cell contract for every CS-family producer (the three CS survey-reachable producers, the unreachable-under-survey covariate-reg producer, and the staggered DDD engine): replicate designs use IF reweighting on the cell influence function with a cell-local df min(df_survey, n_valid - 1) (new survey.cap_replicate_df); a PSU uses CR1 on the PSU totals of the cell influence function; every other lane is unchanged.
  • Fail-closed rules: a zero / negative / non-finite replicate variance, or a non-finite influence value, gives a NaN SE with NaN inference. The non-finite guard lives in the shared CR1 helper, so it also covers the existing CallawaySantAnna and DMLDiD PSU per-cell lane (the PSU variance routine sums per PSU with NaN-skipping and could otherwise report a finite SE).
  • Batch per-cell inference is grouped by each cell's own df, so a degenerate cell cannot change another cell's inference.
  • Unchanged: point estimates, all aggregate SEs and dfs, and per-cell SEs for fits with no survey design or a weights-only, strata-only or FPC-only design.

Measured before / after

One-cell panels, where the cell is the overall ATT and the two SEs must agree:

Estimator / design overall SE cell SE before cell SE after
CS, JK1 replicate 0.342755 0.156789 0.342755
staggered DDD, JK1 replicate 0.325258 0.217289 0.325258
staggered DDD, psu= 0.325258 0.217289 0.325258

For the CS case the cell p-value moves from 4.9e-06 to 0.016. On the multi-cohort test panels (strong cluster shocks by construction) cell SEs grow 1.75x to 2.15x for CS and 1.34x to 1.78x for staggered DDD.

Methodology references (required if estimator / math changes)

  • Method name(s): CallawaySantAnna and staggered TripleDifference per-cell inference under complex survey designs (replicate-weight IF reweighting; CR1 on PSU totals).
  • Paper / source link(s): Callaway and Sant'Anna (2021) for the group-time influence function; Ortiz-Villavicencio and Sant'Anna for the DDD GMM combination; Lumley (2004) for replicate and linearization survey variance. See docs/methodology/REGISTRY.md, the CallawaySantAnna per-cell survey Note and the StaggeredTripleDifference survey Note.
  • Any intentional deviations from the source (and why): R's did and triplediff have no replicate-weight or (for triplediff) survey support, so the design-based per-cell SE is a documented library extension. Weights-only / strata-only / FPC-only designs keep the IF sqrt-sum per cell (documented convention). A degenerate cell reports a NaN SE where the aggregate path clamps a zero or negative variance to 0.0 (documented asymmetry; inference is NaN either way). All recorded with REGISTRY Note labels.

Validation

  • Tests added/updated: new tests/test_per_cell_design_se.py (55 tests, both backends); a comment-only pointer update in tests/test_survey_dml.py.
    • Exact match of every cell SE to compute_replicate_if_variance / compute_survey_if_variance on the cell influence function rebuilt from the aggregation kit, per reachable producer.
    • One-cell coherence: cell SE equals overall SE.
    • Algebraic identity: delete-one-PSU JK1 per-cell SEs equal the psu= design's per-cell SEs (rtol 1e-10), CS panel and RCS and staggered DDD including GMM-combined cells.
    • Cell-local df: capped at the design df on a rank-deficient replicate matrix, tightened by n_valid - 1 otherwise, survey_metadata.df_survey untouched, NaN inference on a rank-1 design.
    • Degenerate cells fail closed and do not contaminate other cells; single-PSU DDD propagates NaN.
    • Unchanged lanes pinned to literals captured from the tree before the source edit.
  • Backtest / simulation / notebook evidence (if applicable): the measured table above. No existing test needed a value change.

Follow-ups recorded in TODO.md

  • The replicate effective-df row is rewritten to the remaining work: the min-cap of the replace-style df relays, which is library-wide rather than the five sites originally listed. The aggregate df code is deliberately not touched in this PR.
  • The staggered-DDD clustering row is reworded: a PSU declared through survey_design= is honored analytically, so what remains is wiring the bare cluster= parameter onto that lane.

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/20261122-per-cell-design-se.md)

…allawaySantAnna, staggered TripleDifference)

Per-cell SEs ignored the survey design in three lanes while the aggregate
SEs on the same fit were design-based: CallawaySantAnna under replicate
weights, and staggered TripleDifference under replicate weights and under
SurveyDesign(psu=...). One dispatch helper (staggered._design_se_for_cell)
now routes every CS-family per-cell producer: replicate designs use IF
reweighting with a cell-local df min(df_survey, n_valid - 1)
(survey.cap_replicate_df), PSU designs use CR1 on the cell IF. Degenerate
cells and non-finite influence functions fail closed to NaN.

Measured on one-cell panels (cell == overall ATT): CS + JK1 cell SE
0.156789 -> 0.342755; staggered DDD 0.217289 -> 0.325258 under both JK1
and psu=. Point estimates and aggregate results are unchanged.
@github-actions

Copy link
Copy Markdown

Overall assessment: ✅ Looks good

No unmitigated P0/P1 findings identified in the supplied diff. Runtime validation remains incomplete because this environment lacks NumPy and pytest.

Executive summary

  • CS and staggered DDD route per-cell survey SEs through the existing design-variance routines with consistent IF scaling.
  • Replicate df caps stay local to each cell; invalid cells preserve NaN inference without affecting neighboring cells.
  • The survey extensions and unchanged strata/FPC conventions are explicitly documented in the Methodology Registry.
  • A changelog fragment is present. Syntax checks and eight isolated df-helper boundary checks passed.

Methodology

P3 — Informational: documented survey extensions.
Affected methods are CallawaySantAnna, staggered TripleDifference, and indirectly DMLDiD through the shared PSU guard.

The dispatch in diff_diff/staggered.py:L187-L223 matches the registry: replicate IF variance, PSU-total variance, and unchanged SEs for the remaining lanes. Staggered DDD correctly supplies its GMM-combined, aggregation-scaled IF in diff_diff/_staggered_triple_diff_engine.py:L470-L515.

Impact: These extensions differ from the original papers’ sampling frameworks, but are explicitly documented at docs/methodology/REGISTRY.md:L1365 and L4599-L4620; they are not defects.
Concrete fix: None required.

Cross-checking used the registry, docstrings, survey-theory derivations, and the repository’s version-pinned Ortiz-Villavicencio–Sant’Anna paper review. External primary-paper retrieval was unavailable because network DNS failed.

Code Quality

No actionable findings. New inference calls use the shared safe-inference functions. Non-finite IF guards precede replicate computation and PSU aggregation, avoiding NaN-skipping variance results (diff_diff/staggered.py:L175-L183, L329-L340).

Performance

No actionable findings. Additional per-cell design-variance computation is necessary for the corrected outputs; no demonstrated performance regression was identified.

Maintainability

No actionable findings. The shared dispatch centralizes the survey contract across the changed producers, while the batch wrapper keeps inference grouped by cell df.

Tech Debt

No new untracked debt identified. The unchanged aggregate replicate-df relays remain separate follow-up work in TODO.md:L38; this review does not treat tracking as mitigation for incorrect statistical output.

Security

No findings. The diff introduces no apparent secrets, external execution, or sensitive-data handling.

Documentation/Tests

No actionable findings. The changelog fragment follows the repository convention, and the new tests cover variance agreement, JK1/CR1 equivalence, cell-local df, degeneracy, and unchanged lanes.

All six changed Python files parsed successfully, and eight isolated cap_replicate_df boundary checks passed. The numerical pytest suite could not run because NumPy and pytest are unavailable; backend results were therefore not independently reproduced.

@igerber igerber added the ready-for-ci Triggers CI test workflows label Nov 22, 2026
@igerber
igerber merged commit 97eaee0 into main Nov 22, 2026
43 of 44 checks passed
@igerber
igerber deleted the per-cell-design-se branch November 22, 2026 19:40
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