Skip to content
Open
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: 1 addition & 1 deletion DEFERRED.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +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 |
| `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::_check_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
12 changes: 9 additions & 3 deletions METHODOLOGY_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +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 |
| DesignDiagnosis | `design.py` | No R parity target (`DeclareDesign` diagnoses simulated designs); internal exact enumeration | **Complete** | 2026-11-23 |

### Cross-Cutting Inference Features

Expand Down Expand Up @@ -1318,7 +1318,7 @@ CI and extending covariate-adjusted R parity are tracked follow-ups in `DEFERRED
| 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 |
| Last Review | 2026-11-23 |

**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`.
Expand All @@ -1328,15 +1328,21 @@ CI and extending covariate-adjusted R parity are tracked follow-ups in `DEFERRED
- 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).

- Held-out periods are not read by the comparison, including for an integer outcome that pandas stores as float - `tests/test_design.py::TestHoldout`.
- The lock run equals a plain run of the chosen estimator on the full panel at the derived seed, and fits only that estimator - `TestLock`; on the AR(1) panel its size for unit-clustered TWFE is near nominal - `tests/test_methodology_design.py::TestHeldOutRun`.
- The design lock round-trips through JSON, detects edits, and rebuilds each of the eight estimators - `TestLockSerialization`, `TestToEstimator`.
- Reconciliation reports each deviating item (class, parameter, fit keyword, column name, `alpha`, diagnosed data, unit count, balance, treated count, cohort count, post-window length) - `TestReconcile`.

**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.
- Held-out periods, their default count, the derived lock seed, the lock file hash and the binary `pre-specified` / `deviates` label are library choices; only the idea of reconciling the planned and the realized design is from Blair et al. (p.852). `reconcile` is a declaration check: fitted results do not record their configuration. The reduction in selection inflation from the held-out rerun is not validated numerically.
- 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).
**Tests:** `tests/test_design.py` (behaviour, guards, failure policy, results contract, held-out periods, lock, reconcile) + `tests/test_methodology_design.py` (paper-shaped findings and documented choices).

---

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +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
- [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; lock the chosen design and reconcile the analysis against it
- [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
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ 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 |
| Design-stage tutorial ("Study Design" group of `docs/tutorials/index.rst`): the full workflow - `diagnose_design`, `lock`, then `DesignLock.reconcile` after the analysis - on one worked panel. `docs/api/design.rst` and `llms-full.txt` carry 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 |
| Wire the design-lock label into the reports: `DiagnosticReport` / `BusinessReport` accept a `DesignReconciliationResults` (or a `DesignLock` to reconcile) and state whether the result is `pre-specified` or `deviates`, with the deviating items; schema and `REPORTING.md` updates. Until then the label is available only from `DesignLock.reconcile` itself. Ships before the release that carries `diagnose_design`. | `diagnostic_report.py`, `business_report.py`, `design.py` | design lock PR | 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
35 changes: 35 additions & 0 deletions changelog.d/20261123-design-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
### Added
- **Design lock: carry the pre-specified estimator from `diagnose_design` into
the analysis.** `DesignDiagnosisResults.lock(label, data=)` records one
estimator as the choice made before the analysis and returns a `DesignLock`;
`DesignLock.reconcile(estimator, outcome=, unit=, time=, ...)` later checks
the analysis that was run against it and labels it `pre-specified` or
`deviates`.
- Held-out periods: when more than one estimator is compared,
`diagnose_design` now leaves the last periods of the panel out of the
comparison (new `n_holdout=`; default half of the periods at or after the
latest adoption period, `n_holdout=0` compares on the whole panel).
`lock()` reruns only the chosen estimator with those periods included, on
fresh placebo draws, so its reported power is not taken from the runs used
to choose it.
- `DesignLock` is plain JSON data (`to_json()`, `DesignLock.from_json()`,
`DESIGN_LOCK_SCHEMA_VERSION`) holding the chosen estimator and its
configuration, the declared design, a fingerprint of the panel, every
estimator that was compared and the chosen estimator's diagnosands.
`to_estimator()` builds the estimator exactly as locked.
- `reconcile` reports one check per item (estimator class, each constructor
parameter, `fit()` keywords, column names, and with `data=` the fingerprint
of the diagnosed periods, unit count, panel balance, treated count, cohort
count and post-window lengths) in a `DesignReconciliationResults`. It
compares what the analyst declares with the lock; `pre-specified` covers
the listed checks only and a deviation is not graded.
- The reconciliation idea follows Blair et al. (2019); held-out periods, the
lock format and the label are library choices documented as Notes in
`docs/methodology/REGISTRY.md` `## DesignDiagnosis`.

### Changed
- **`diagnose_design` data fingerprint encodes numbers by value.**
`data_sha256` no longer distinguishes `1` from `1.0`, so the digest of a set
of rows does not change when pandas stores an integer column as float because
some other row is missing. `diagnose_design` has not been released, so no
stored fingerprint is affected.
11 changes: 10 additions & 1 deletion diff_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@
load_prop99,
load_walmart,
)
from diff_diff.design import DesignDiagnosisResults, diagnose_design
from diff_diff.design import (
DESIGN_LOCK_SCHEMA_VERSION,
DesignDiagnosisResults,
DesignLock,
DesignReconciliationResults,
diagnose_design,
)
from diff_diff.diagnostic_report import (
DIAGNOSTIC_REPORT_SCHEMA_VERSION,
DiagnosticReport,
Expand Down Expand Up @@ -495,6 +501,9 @@
"simulate_sample_size",
# Design diagnosis
"DesignDiagnosisResults",
"DesignLock",
"DesignReconciliationResults",
"DESIGN_LOCK_SCHEMA_VERSION",
"diagnose_design",
# Pre-trends power analysis
"PreTrendsPower",
Expand Down
Loading
Loading