Skip to content

feat(design): planned pre-trend power from placebo event studies (diagnose_design(event_study=True)) - #912

Open
igerber wants to merge 1 commit into
mainfrom
feat/pretrend-planning
Open

igerber wants to merge 1 commit into
mainfrom
feat/pretrend-planning

Conversation

@igerber

@igerber igerber commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

Planned pre-trend power at the design stage: before any outcome exists, how large a diverging trend would the pre-trend check of a planned design catch, and how does that change with the number of pre-periods tested.

  • diagnose_design(..., event_study=True) keeps, for each CallawaySantAnna and StackedDiD candidate, a placebo event study: the mean and the sample covariance, across the no-effect placebo draws, of the event-study coefficients of each fit. It is stored in DesignDiagnosisResults.event_study_results[label] as an EventStudyResults labelled estimand="placebo".
  • PreTrendsPower accepts the diagnosis (or one of its placebo event studies) in fit, power_at, power_curve, compute_pretrends_power and compute_mdv, and returns planned pre-trend power from Roth's (2022) formula (covariance_source="placebo_draws").
  • PreTrendsPower.power_by_pre_periods(diagnosis) tabulates it by the number of pre-periods tested (the K nearest to treatment).
  • Pre-test check. Roth's formula assumes that each coefficient's own test rejects at its nominal level when nothing is wrong. No placebo draw contains a violation, so for the pre-periods being planned PreTrendsPower counts how often the pre-trend test rejected in the draws and compares that with the rate the formula assumes. Planned power is reported only where the two agree within Monte Carlo error: fit raises with both rates otherwise, and the table shows both rates on every row (power_no_violation, placebo_rejection_rate) and leaves the planned numbers of a disagreeing row blank. This mirrors the minimum detectable effect, which is not reported for an estimator that fails the size check.
  • Consumers that describe a fitted model refuse a planned input: HonestDiD, PreTrendsPower.sensitivity_to_honest_did, and precomputed["pretrends_power"] in DiagnosticReport / BusinessReport. power_by_pre_periods refuses a fitted model (choosing how many pre-periods to test after seeing the event study is a choice made on the outcome).
  • Tutorial 34 gains a section that plans the pre-trend check for its 50-store design.
  • Fix (existing behaviour): a violation magnitude M that was NaN was reported as a power of 100% (default pre-test form) or of alpha (Wald form) by PreTrendsPower.fit, power_at, power_curve and PreTrendsPowerResults.power_at. A non-finite M now raises ValueError.
  • Fixes a PreTrendsPower example in the bundled llms-full.txt guide that called a method and an argument that do not exist.

New public surface: one keyword (diagnose_design(event_study=), the spelling TwoWayFixedEffects.fit already uses), two fields on DesignDiagnosisResults (event_study, event_study_results), one method (PreTrendsPower.power_by_pre_periods), and one new value each for two existing fields (EventStudyResults.estimand="placebo", PreTrendsPowerResults.covariance_source="placebo_draws"). No new class or function. DesignLock is unchanged, and every cell of a diagnosis is identical with the keyword on and off.

Limits, each stated in the registry and tracked in TODO.md:

  • Planned power is available for the default pre-test form (pretest_form="nis") only.
  • Placebo event studies are recorded for CallawaySantAnna and StackedDiD only, and not for a vcov_type="jackknife" candidate.
  • The check allows only for Monte Carlo error, so with more replicates it detects smaller departures. On the tutorial's 50-store panel (25 treated) each coefficient's own test rejects about 6% instead of 5%; with 500 replicates tests of one and two pre-periods are planned, with 2,000 none is.
  • Sensitivity planning (what HonestDiD M a design could rule out) is not in this PR.

Methodology references (required if estimator / math changes)

  • Method name(s): design diagnosis (placebo event study), pre-trends power. docs/methodology/REGISTRY.md ## DesignDiagnosis ("Placebo event study" and its Notes), ## PreTrendsPower (Note (design-stage input), Note (power_by_pre_periods)), ## HonestDiD (Note (placebo event studies are refused)); docs/methodology/REPORTING.md (planned pre-trends power is refused).
  • Paper / source link(s): Roth, J. (2022), "Pretest with Caution: Event-Study Estimates after Testing for Parallel Trends", AER: Insights 4(3), 305-322, https://doi.org/10.1257/aeri.20210236 (the power formula, Sections I.C and II.A-B). The placebo procedure is the one diagnose_design already uses (Bertrand, Duflo & Mullainathan 2004; Mizushima & Powell 2025).
  • Any intentional deviations from the source (and why), each labelled as a Note in the registry:
    • Roth calibrates the formula to the covariance of an estimated event study. Taking the covariance from placebo draws of a design that has not been run is a library extension with no paper source.
    • The pre-test check, its two-sided form and its Monte Carlo tolerance are library rules with no paper source.
    • The layout rule for averaging draws, the 10% exclusion bound, the minimum number of draws and the rank gate; which candidates record a placebo event study; what the surface's inference columns mean; the selection caveat for a candidate picked from a comparison.

Validation

  • Tests added/updated: tests/test_design_event_study.py (new, 77 tests), tests/test_pretrends.py (non-finite M), tests/test_t34_design_diagnosis_drift.py (the new tutorial section, including two slow tests that rerun it).

    • The placebo event study equals the mean and sample covariance of a by-hand loop over the same draws at 1e-12 (CallawaySantAnna with both base periods, staggered timing, StackedDiD), including the per-draw record and the counted rejection rate; only the no-effect cell is captured, and the diagnosis cells and the lock are identical with the keyword on and off.
    • Reduction rules on constructed inputs: provenance taken from the retained draws on a calendar with gaps (the first draw loses a cohort), excluded draws, too few draws, no pre-period, a rank-deficient covariance from a four-unit panel without resampling.
    • The benchmark's draw scoring (a fresh draw that lacks a planned period is not scored for any tested set).
    • Planned power equals the hand computation on the placebo covariance; the pre-test check on the tested set in both directions; blank rows in the table; refusals (Wald form, a surface without its per-draw record, fitted models, HonestDiD, both reports on every BusinessReport path); pickling, including a state from before the new fields existed.
    • The new file passes on pandas 3.1, 2.2 and 1.5 (Python 3.14, 3.12, 3.9); the touched suites pass on both backends (2,745 each).
  • Backtest / simulation / notebook evidence (if applicable): benchmarks/python/pretrend_planning_check.py (results committed as benchmarks/data/pretrend_planning_check.json; the registry's numbers are pinned to that file by TestPlanningEvidence). Twelve simulated AR(1) panels of 12 periods (40 and 200 units, a quarter treated, AR 0, 0.5 and 0.8, common and staggered adoption), CallawaySantAnna(base_period="universal") on all and StackedDiD on the common-adoption ones, 500 diagnosis replicates, tests of 2, 4 and all pre-periods (48 cells). For each cell, 1,000 fresh placebo draws with a linear trend of the planned size added to the placebo-treated units, the pre-test applied with each fit's own standard errors:

    Pre-test check Cells Counted minus assumed rejection rate Power at the planned MDV (target 80%) No-violation rejection, fresh draws: observed minus planned Cells flagged
    agrees 28 (22 of 24 at 200 units, 6 of 24 at 40 units) -1.9pp to +2.4pp 73% to 84%, mean 79% -0.4pp to +5.2pp 0
    disagrees 20 (18 at 40 units, 2 at 200 units) +2.9pp to +21.6pp 78% to 90%, mean 83% +2.3pp to +21.5pp 15

    A cell is flagged when the observed power at the planned MDV is more than 5pp plus two Monte Carlo standard errors from 80%, or the observed no-violation rate is more than 3pp plus two standard errors from the planned one. Every flagged cell is one the check withholds. The same script measures the Monte Carlo error of the planned MDV (standard deviation over 20 seeds: 4% to 5% of the mean at 200 replicates, 3% to 4% at 500, 2% at 1,000) and the effect of picking a candidate from a comparison (the picked candidate's planned MDV differed from a rerun alone on a new seed by -1.7% and +1.4%, standard errors 0.7 and 0.6). This is one family of simulated designs.

  • Tutorial 34 was re-executed; its existing outputs are unchanged.

  • mypy diff_diff at the pinned versions reports no errors; the Sphinx -W build passes.

Security / privacy

  • Confirm no secrets/PII in this PR: Yes

Changelog

  • changelog.d/ fragment added (or N/A - no user-visible change): Yes

diagnose_design(..., event_study=True) records, for CallawaySantAnna and
StackedDiD candidates, a placebo event study: the mean and the sample
covariance, across the no-effect placebo draws, of each fit's event-study
coefficients, as an EventStudyResults with estimand="placebo". It also keeps,
per draw, each pre-period coefficient over its own reported standard error.

PreTrendsPower accepts the diagnosis (or one of its surfaces) in fit,
power_at, power_curve, compute_pretrends_power and compute_mdv and returns
planned pre-trend power from Roth's (2022) formula. The new
power_by_pre_periods tabulates it by number of pre-periods tested.

The formula assumes that each coefficient's own test rejects at its nominal
level. For the pre-periods being planned, PreTrendsPower counts how often
the pre-trend test rejected in the placebo draws and compares that with the
rate the formula assumes. Planned power is reported only where the two agree
within Monte Carlo error: fit raises otherwise, and the table shows both
rates on every row and leaves a disagreeing row blank. NIS form only.

HonestDiD, sensitivity_to_honest_did and the reports' precomputed
pretrends_power refuse a placebo surface or a result planned from one.

Also: a non-finite violation magnitude M now raises ValueError in fit,
power_at, power_curve and PreTrendsPowerResults.power_at (a NaN was reported
as power 1.0, or alpha under the Wald form); the PreTrendsPower example in
llms-full.txt called a method and an argument that do not exist.

benchmarks/python/pretrend_planning_check.py checks the planned numbers
against direct trend injection on simulated panels; tutorial 34 gains a
section that plans the pre-trend check of its design.
@github-actions

Copy link
Copy Markdown

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

Executive summary

  • Placebo covariance construction and planned power follow the Methodology Registry.
  • Empty results, insufficient draws, singular covariance, and non-finite violation magnitudes have explicit handling.
  • Planned results are refused by the changed fitted-model consumers.
  • Syntax, benchmark-record consistency, and changelog checks passed. Numerical tests could not run because NumPy and pytest are unavailable.

Methodology

  • P3 — Informational: documented library extensions. Affected methods are DesignDiagnosis, Roth (2022) pre-trend power, and HonestDiD input admission. Cross-checking the registry, docstrings, and committed paper audits found the sample covariance, reference anchoring, NIS rejection probability, and pre-test check consistent with their stated contracts. The placebo covariance extension, calibration tolerance, and draw-selection policies are explicitly documented at docs/methodology/REGISTRY.md:L7158-L7172. Impact: these are library planning rules beyond the cited papers. Concrete fix: none required.

Code Quality

No findings. The new surface uses safe_inference() consistently at diff_diff/design.py:L772-L780; the changed public entry points propagate planned inputs and magnitude validation.

Performance

No actionable findings. Event-study capture is optional and limited to the no-effect cell. Bootstrap aggregation can add replay work, but no demonstrated performance defect was identified.

Maintainability

No findings. Shared report validation, retained provenance, and backward-compatible pickle defaults support the new input path.

Tech Debt

  • P3 — Informational: tracked feature limits. Additional estimator support, planned Wald power, and sensitivity planning are tracked in TODO.md:L23-L25 and documented in the registry. Impact: narrower supported functionality with explicit refusals. Concrete fix: none required for this PR.

Security

No findings. No apparent secrets or newly introduced unsafe execution paths were identified.

Documentation/Tests

No actionable findings. The PR includes a valid changelog fragment and targeted tests for reduction rules, calibration, consumer refusals, and serialization.

Validation completed: all 11 changed Python files and notebook code cells parsed; all 48 committed benchmark classifications matched the documented rules; changelog validation passed. These checks do not independently reproduce the numerical simulations or pytest results.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant