MultiPeriodDiD: full event-study specification with pre-period coefficients#125
MultiPeriodDiD: full event-study specification with pre-period coefficients#125
Conversation
…cients BREAKING: Transform MultiPeriodDiD from a post-period-only estimator into a proper event-study estimator with pre-period coefficients for parallel trends assessment. Core changes: - Treatment × period interactions for ALL non-reference periods (pre and post) - Default reference period is last pre-period (e=-1 convention) with FutureWarning - New `unit` parameter for staggered adoption detection warning - `period_effects` now contains both pre and post period effects - `summary()` shows pre-period section with reference period indicator - `to_dataframe()` includes `is_post` column - `interaction_indices` stored on results for robust sub-VCV extraction Bug fix: - HonestDiD/PreTrendsPower VCV extraction uses interaction sub-VCV instead of full regression VCV (via stored interaction_indices) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Overall assessment: Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
- Upgrade post-period reference_period from warning to ValueError (P1) - Add warning when <2 pre-periods available for parallel trends (P1) - Add absorbing treatment validation when unit param provided (P2) - Fix staggered detection false positives on unbalanced panels (P2) - Fix REGISTRY.md SE default documentation (HC1, not cluster-robust) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: ⛔ Blocker
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
- Guard period-level p_value and conf_int when SE is non-finite/zero (previously conf_int returned misleading zero-width interval) - Add test assertions for full NaN propagation on unidentified periods - Fix REGISTRY.md: "requires ≥2 pre-periods" → "warns when <2" - Fix CHANGELOG.md: "Warning" → "ValueError" for post-period reference Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: Executive summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
- Add time-varying treatment warning when `unit` is provided and treatment varies within units (guides users toward ever-treated indicator D_i) - Filter non-finite pre-period effects in HonestDiD _extract_event_study_params and _estimate_max_pre_violation (prevents NaN propagation into bounds) - Update REGISTRY.md: D_i requirement and staggered check conditional on unit - Add tests for D_it warning, NaN filtering, and all-NaN-pre-periods error Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment
Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Add num_post == 0 guard in HonestDiD.fit() to raise ValueError when all post-period effects are non-finite, preventing silent computation with empty arrays. Covers both MultiPeriodDiD and CallawaySantAnna paths. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: ⛔ Blocker Executive summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
- Align avg_se guard with per-period pattern (np.isfinite check prevents avg_t_stat=0 / avg_p_value=1 when variance is infinite) - Use explicit pre-then-post ordering in HonestDiD extraction instead of sorted() (prevents misclassification when period labels don't sort chronologically) - Add test with non-monotone period labels (pre=[5,6,7], post=[1,2]) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: PR ReviewOverall assessment: ✅ Looks good Executive summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment: Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Replace sorted() with order-preserving list comprehensions in _extract_event_study_params to maintain chronological period ordering. sorted() could break smoothness-based bounds (DeltaSD, DeltaSDRM) when period labels don't sort chronologically by default (e.g., string labels). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall Assessment ✅ Looks good Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
Summary
MultiPeriodDiDfrom a post-period-only estimator into a proper event-study estimator with treatment × period interactions for ALL non-reference periods (pre and post)FutureWarningfor one release cycleunitparameter for staggered adoption detection warningChanges
Core estimator (
diff_diff/estimators.py)reference_periodchanged from first to last pre-period withFutureWarningreference_periodis set to a post-treatment periodunitparameter added tofit()for staggered adoption detectioninteraction_indices(period → column index) stored on results for robust VCV extractionnp.isfinite(se) and se > 0(consistent with other estimators)Results (
diff_diff/results.py)reference_periodandinteraction_indicesfields onMultiPeriodDiDResultspre_period_effectsandpost_period_effectsconvenience propertiessummary()shows pre-period section with[ref]indicator for reference periodto_dataframe()includesis_postcolumnget_effect()gives informative error when accessing reference periodHonestDiD / PreTrendsPower VCV fix
_extract_event_study_paramsnow extracts interaction sub-VCV using storedinteraction_indicesVisualization (
diff_diff/visualization.py)reference_periodfrom results objectTests
TestMultiPeriodDiDEventStudyclassTest plan
pytest tests/test_estimators.py -k "MultiPeriod"— 47 tests passpytest tests/test_honest_did.py— 52 tests passpytest tests/test_pretrends.py— 63 tests passpytest tests/test_visualization.py— 18 tests pass-W error::FutureWarning)ruff checkandblack --checkclean🤖 Generated with Claude Code