Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DEFERRED.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ provenance and AI-review deviation-documentation: a row here (or in

| Issue | Location | PR | Priority |
|-------|----------|----|----------|
| `diagnose_design` under a survey design: `survey_design` is refused because placebo assignment and unit resampling are done at the unit level, which is not valid when sampling or dependence sits above the unit (PSUs, strata). Needs a derivation of the placebo and resampling scheme at the PSU level; none of the four source papers covers survey designs. | `design.py::_REFUSED_FIT_KEYS` | design diagnosis PR-B | Low |
| Chang (2020) Case 3 (multilevel treatment intensity) DML estimator: the paper prints no Case 3 regularity assumptions or variance theorem (Theorems 2/4 cover Cases 1-2 only; "same arguments" p. 13), the printed multilevel algorithm carries typos (review Gaps items 5-6), and no oracle exists (`DoubleMLDIDMulti` is staggered TIMING, not intensity) — needs the variance derivation + overlap assumptions before implementation. Published-version cross-check (2026-08-30) CONFIRMS the blocker in the version of record: printed Appendix A carries the same score/algorithm (same typos) with no Case 3 regularity/rate assumptions and no variance theorem | `docs/methodology/papers/chang-2020-review.md` | dml-b0 | Low |
| LWDiD PSM matching variance: implement the Abadie-Imbens (2006) matching variance (matched-control reuse + first-stage matching uncertainty) so `estimation_method='psm'` can report valid inference instead of the current fail-closed NaN tuple (point retained; naive var(diffs)/n was invalid under with-replacement reuse) | `diff_diff/lwdid.py` | #588 | Low |
| LWDiD cohort-relative sensitivity exclusions: `robustness_pre_periods` / `sensitivity_no_anticipation` currently reject multi-cohort staggered inputs because their exclusion windows are defined relative to the EARLIEST adoption (later cohorts' own pre periods fall inside the global post window and survive every restriction, mislabeling the specification). Supporting staggered inputs needs per-cohort window semantics (exclude the last k periods of each cohort's own `t < g` window before its transformation), which the current row-subset design cannot express — a per-cohort masking derivation + its aggregation contract | `diff_diff/lwdid_sensitivity.py` | #588 | Low |
Expand Down Expand Up @@ -81,6 +82,7 @@ For survey-specific limitations (`NotImplementedError` paths), see the

| Issue | Location | PR | Priority |
|-------|----------|----|----------|
| `diagnose_design` on unbalanced panels and with a non-numeric calendar column: both are refused. Unit resampling and the placebo post window assume every unit is observed in every period, and the staggered estimators need numeric periods. Parked pending a user request; the source papers use balanced state-by-year panels. | `design.py::_prepare_panel` | design diagnosis PR-B | Low |
| Hard "changelog fragment required" CI gate (diff-aware job + exemption convention), and extending the fragment pattern to the other shared-file collision surfaces (TODO.md / DEFERRED.md / docs/v4-deprecations.yaml rows — rare, trivially resolvable one-line conflicts today). The shipped system enforces only the pointer-only `## [Unreleased]` invariant plus prose/reviewer nudges. | `changelog.d/` | #806 | Low |
| RDDensityTest public bandwidth-selector helper (an `rdbwdensity`-equivalent exposed function) and a Tutorial-28 executed density-test demo cell (Act 4d; needs notebook re-execution + drift-suite updates): the selector ships internal-only and the tutorial carries a prose pointer for now. | `diff_diff/rddensity.py`, `docs/tutorials/28_rdd_scholarship_illusion.ipynb` | rddensity PR-B | Low |
| LW 2025 Sec 4.3 all-eventually-treated mode for LWDiD (drop `D_infinity`, effects relative to the last cohort as reference, last cohort's own effect not estimable). Current behavior (by decision, see the REGISTRY LWDiD Sec 4.3 note): such designs raise ValueError under both control strategies rather than silently truncating | `diff_diff/lwdid_staggered.py` | #588 | Low |
Expand Down
31 changes: 31 additions & 0 deletions METHODOLOGY_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The catalog grew incrementally over several quarters, so formats vary across the
| PreTrendsPower | `pretrends.py` | `pretrends` package | **Complete** | 2026-05-19 |
| PowerAnalysis | `power.py` | `pwr` / `DeclareDesign` | **Complete** | 2026-05-31 |
| PlaceboTests | `diagnostics.py` | Bertrand-Duflo-Mullainathan (2004); base-R exact-enumeration parity | **Complete** | 2026-06-26 |
| DesignDiagnosis | `design.py` | No R parity target (`DeclareDesign` diagnoses simulated designs); internal exact enumeration | **Complete** | 2026-11-22 |

### Cross-Cutting Inference Features

Expand Down Expand Up @@ -1309,6 +1310,36 @@ CI and extending covariate-adjusted R parity are tracked follow-ups in `DEFERRED

---

#### DesignDiagnosis

| Field | Value |
|-------|-------|
| Module | `design.py` |
| Primary References | Bertrand, Duflo & Mullainathan (2004) - placebo assignment on real data, unit resampling, rejection rates, additive effect injection; Mizushima & Powell (2025) - staggered placebos; Coglianese & Fang (2026) - shared placebo events across estimators; Blair, Cooper, Coppock & Humphreys (2019) - diagnosands. Paper reviews under `docs/methodology/papers/`. |
| R Reference | None. `DeclareDesign` implements Blair et al.'s diagnosis on simulated data, not placebo assignment on a user's panel; the source papers distribute no placebo generator. |
| Status | **Complete** |
| Last Review | 2026-11-22 |

**Verified components:**
- Placebo assignment follows the declared design: exact treated count, adoption periods drawn from `cohort_periods`, absorbing treatment, never-treated controls, effect injected only from each unit's own adoption on - `tests/test_design.py::TestPlaceboGenerator`.
- All eight supported estimators recover an injected effect under common timing, and the six staggered ones under staggered timing - `TestRecovery`.
- Every estimator and every effect size sees the same placebo draws, including under `seed=None` - `TestPlaceboDraws`.
- With the panel held fixed, the rejection rate agrees with exact enumeration of all C(6,3) assignments - `TestPlaceboDraws::test_fixed_panel_matches_exact_enumeration`.
- The outcome-blind truncation never reads rows from the first real adoption on - `TestOutcomeBlindGuard`.
- Paper-shaped findings on simulated panels - `tests/test_methodology_design.py`: with AR(1) outcomes (rho = 0.8, 50 units x 21 periods) classical TWFE standard errors reject a true null far above the nominal level while unit-clustered ones are near it (Bertrand et al.); with 2 of 40 units treated, asymptotic inference over-rejects, and with 20 it is near nominal (Mizushima-Powell).

**Deviations and library choices (documented in REGISTRY `## DesignDiagnosis`):**
- The size check, the minimum detectable effect on real data, the two-pre-period minimum and the data fingerprint have no paper source.
- A fit with non-finite inference is excluded from every rate; `simulate_power` alone counts it as a non-rejection.
- RMSE is the existing `ddof = 1` form, not Blair et al.'s root mean squared error.
- Adoption periods are declared; Bertrand et al.'s randomly drawn passage year is not implemented.

**Not validated:** no R parity; the source papers' CPS tables are not reproduced.

**Tests:** `tests/test_design.py` (behaviour, guards, failure policy, results contract) + `tests/test_methodology_design.py` (paper-shaped findings and documented choices).

---

#### PlaceboTests

| Field | Value |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Full guide: `diff_diff.get_llm_guide("practitioner")`.
- [Honest DiD](https://diff-diff.readthedocs.io/en/stable/api/honest_did.html) - Rambachan & Roth (2023) sensitivity analysis: robust CI under PT violations, breakdown values
- [Pre-Trends Power Analysis](https://diff-diff.readthedocs.io/en/stable/api/pretrends.html) - Roth (2022) minimum detectable violation and power curves
- [Power Analysis](https://diff-diff.readthedocs.io/en/stable/api/power.html) - analytical and simulation-based MDE, sample size, power curves for study design
- [Design Diagnosis](https://diff-diff.readthedocs.io/en/stable/api/design.html) - `diagnose_design`: placebo assignments on your own untreated panel, reporting each candidate estimator's size, power, bias, coverage and MDE before any real analysis
- [MMM Calibration Export](https://diff-diff.readthedocs.io/en/stable/api/mmm.html) - convert experiment results into MMM calibration inputs: PyMC-Marketing lift-test frames and Google Meridian lognormal ROI priors
- Conley spatial HAC SE (`vcov_type="conley"`) on cross-sectional `LinearRegression` / `compute_robust_vcov` plus panel `DifferenceInDifferences` / `TwoWayFixedEffects` (with `conley_lag_cutoff` for within-unit Bartlett temporal HAC) - Conley (1999) spatial-correlation-aware SEs with parity vs R `conleyreg` on cross-sectional + panel fixtures, optional combined spatial + cluster product kernel via explicit `cluster=`, auto-activating sparse k-d-tree fast path for `n > 5_000`

Expand Down
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Related tracking surfaces:

| Issue | Location | Origin | Effort | Priority |
|-------|----------|--------|--------|----------|
| `diagnose_design` staggered placebo for `DifferenceInDifferences` / `TwoWayFixedEffects`: both are refused under a staggered declaration (two or more `cohort_periods`) because they are fitted with one `post` dummy. Supporting them needs a staggered TWFE placebo fit (a time-varying treatment column) and a stated estimand, since static TWFE under staggered timing does not target the injected effect cleanly. | `design.py::_validate_estimators` | design diagnosis PR-B | Mid | Low |
| `diagnose_design` with `anticipation > 0`: refused today because the candidate's aggregate averages periods before adoption where no effect is injected. Inject the effect from `g - anticipation` so that bias and coverage are scored against the right target. | `design.py::_validate_estimators`, `design.py::_make_placebo_generator` | design diagnosis PR-B | Mid | Low |
| `diagnose_design` randomly drawn common adoption period (the Bertrand, Duflo & Mullainathan 2004 main design: one passage year drawn per replicate from an interior window). `cohort_periods` is required and declared; a `None` default would have altered its meaning relative to `generate_staggered_data`, so the random-date variant needs its own argument. | `design.py::diagnose_design` | design diagnosis PR-B | Quick | Low |
| One-way (unclustered) Bell-McCaffrey DOF for `SunAbraham` / `WooldridgeDiD` `vcov_type="hc2_bm"` + `cluster=False`: both reject the combination at 4.0 (item 7b) because their BM contrast helper `_compute_cr2_bm_contrast_dof` is cluster-only; port the one-way lane through `linalg._compute_bm_dof_from_contrasts` (the TWFE event-study core's helper) with a clubSandwich `vcovCR(cluster=1:n, type="CR2")` parity pin, then lift the two rejects and their tests | `diff_diff/sun_abraham.py`, `diff_diff/wooldridge.py` | #v4-7b | Mid | Low |
| `decompose_twfe_weights(method="aipw")`: port upstream `implicit_aipw_weights` (covariate-adjusted only; `twfe_weights.py` rejects the value today and lists `"fwl"`). The R goldens already carry the `decompose.aipw` / `balance.aipw` / `two_period.*` blocks under `meta.reserved_blocks`, so no R re-run is needed | `diff_diff/twfe_weights.py` | #812 | Mid | Medium |
| Consolidate the remaining estimator-entangled DR/logit score variants (`staggered.py::_doubly_robust` + RC twins, `triple_diff.py`, `lwdid.py`, `wooldridge.py`) onto the shared `_dr_scores.py` module, each migration with its own committed oracle capture (the ContinuousDiD lift's two-tier pattern in `tests/test_dr_scores.py`); and add a ridge vcov path to `solve_ridge` if an estimator ever needs analytical ridge inference | `diff_diff/_dr_scores.py` | dml-b0 | Mid | Low |
Expand Down Expand Up @@ -84,6 +87,7 @@ generic sparse-FE, QR+SVD rank-detection redundancy, `check_finite` bypass — m

| Issue | Location | Origin | Effort | Priority |
|-------|----------|--------|--------|----------|
| Design-stage tutorial ("Study Design" group of `docs/tutorials/index.rst`): the full workflow - `diagnose_design`, then the design lock and reconciliation - deferred from the diagnosis PR because the lock does not exist yet; `llms-full.txt` carries a worked example in the meantime. Ships with the report-wiring PR, before the release that carries `diagnose_design`. | `docs/tutorials/`, `design.py` | design diagnosis PR-B | Mid | Medium |
| Relay `to_dataframe(level='group')` to `aggregate('group').to_dataframe()` on CallawaySantAnna/DMLDiD, EfficientDiD and TripleDifference (staggered) - the level still raises with the post-fit pointer while `level='event_study'` was rewired to the aggregate route at the 4.0 cut (item 8b, [M-093]); ImputationDiD/TwoStageDiD keep their native `group` frames and need the same decision | `diff_diff/staggered_results.py`, `diff_diff/efficient_did_results.py`, `diff_diff/triple_diff_results.py` | #883 | Quick | Low |
| TWFE event-study one-way HC2-BM absorbed-FE R parity against the `mpd_absorbed_fe_did` golden (`clubSandwich::vcovCR(cluster=1:n, type="CR2")`): since 4.0 (item 7b) `cluster=False` + hc2_bm reaches the one-way lane directly (no singleton-cluster column needed; `tests/test_v4_cluster_policy.py` pins finiteness and the static-surface LinearRegression parity only), so the open item is the R pin itself; the hc2 lane is pinned by `TestTWFEEventStudyAbsorbedFERParity` and the clustered hc2_bm per-period lane by `test_twfe_event_study_cluster_hc2_bm_per_period_df_matches_clubsandwich`; the MultiPeriodDiD lanes died at the 4.0 cut (PR 4c-ii) | `tests/test_estimators_vcov_type.py` | #v4-4c-i | Mid | Medium |
| TWFE event-study power profile: `simulate_power`/`simulate_mde`/`simulate_sample_size` have no `_EstimatorProfile` for `TwoWayFixedEffects.fit(event_study=True)` since the MultiPeriodDiD registry entry went with the class (PR 4c-ii); `EventStudyResults` carries no scalar headline, so the profile needs a design (post-period average via the `tests/helpers/event_study_average.py` arithmetic, or a named period) plus its `_SURVEY_FIT_BUILDERS` twin | `diff_diff/power.py` | #v4-4c-ii | Mid | Low |
Expand Down
24 changes: 24 additions & 0 deletions changelog.d/20261122-design-diagnosis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Added
- **`diagnose_design`: design diagnosis on your own untreated panel.** Before
analysing a study, check how each candidate estimator behaves on the panel
you will actually use. `diagnose_design(data, outcome=, unit=, time=,
estimators=, cohort_periods=, n_treated= | treatment_fraction=, ...)`
repeatedly assigns placebo treatments that follow the declared design,
optionally adds a known effect to the placebo-treated observations, fits
every estimator on the same placebo draws, and returns a
`DesignDiagnosisResults` with, per estimator, the rejection rate under no
effect (size) and the power, bias, RMSE and coverage at each injected effect,
plus an optional minimum detectable effect (`power=`).
- Outcome-blind: no real treatment effect is estimated. Pass `first_treat=`
to drop every period from the earliest real adoption onward.
- Estimators are returned in input order and never ranked. `size_controlled`
flags those whose no-effect rejection rate is consistent with `alpha`; no
minimum detectable effect is reported for the others.
- Supports `DifferenceInDifferences`, `TwoWayFixedEffects`,
`CallawaySantAnna`, `SunAbraham`, `ImputationDiD`, `TwoStageDiD`,
`StackedDiD` and `EfficientDiD`, under common or staggered timing.
- Sources: Bertrand, Duflo & Mullainathan (2004), Mizushima & Powell (2025),
Coglianese & Fang (2026) and Blair et al. (2019). The size check, the
minimum detectable effect on real data and the other choices with no paper
source are documented as Notes in `docs/methodology/REGISTRY.md`
`## DesignDiagnosis`.
4 changes: 4 additions & 0 deletions diff_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
load_prop99,
load_walmart,
)
from diff_diff.design import DesignDiagnosisResults, diagnose_design
from diff_diff.diagnostic_report import (
DIAGNOSTIC_REPORT_SCHEMA_VERSION,
DiagnosticReport,
Expand Down Expand Up @@ -492,6 +493,9 @@
"simulate_mde",
"simulate_power",
"simulate_sample_size",
# Design diagnosis
"DesignDiagnosisResults",
"diagnose_design",
# Pre-trends power analysis
"PreTrendsPower",
"PreTrendsPowerResults",
Expand Down
Loading
Loading