-
Notifications
You must be signed in to change notification settings - Fork 12
Add Borusyak-Jaravel-Spiess (2024) Imputation DiD estimator #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implement ImputationDiD, the efficient imputation estimator for staggered DiD from Borusyak, Jaravel & Spiess (2024) "Revisiting Event-Study Designs: Robust and Efficient Estimation", Review of Economic Studies. Core features: - Three-step estimation: OLS on untreated → impute counterfactuals → aggregate - Conservative clustered variance (Theorem 3) with configurable auxiliary model partition (cohort_horizon, cohort, horizon) - Event study and group aggregation with balance_e and horizon_max options - Pre-trend test (Equation 9) independent of treatment effect estimation - Proposition 5: NaN for unidentified long-run effects without never-treated - Optional multiplier bootstrap for consistency with other staggered estimators - Covariate support via within-transformation Includes 54 tests, API docs, tutorial notebook, R benchmark scripts, methodology registry entry, and README/ROADMAP/CLAUDE.md updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Overall Assessment: ⛔ Blocker Executive Summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
…ring - Fix 1 (P0): Replace one-pass demeaning with iterative Gauss-Seidel for exact FE on unbalanced panels (add _iterative_fe helper) - Fix 2 (P0): Use v_it-weighted tau_tilde_g in auxiliary residuals per Eq 8 - Fix 3 (P1): Add rank-condition checks after Step 1, fix fillna(0.0)->NaN consistency in auxiliary residuals, handle NaN in v*eps product - Fix 4 (P1): Bootstrap generates weights per cluster_var (not always unit), add cluster column validation - Fix 5 (P2): plot_event_study detects reference via n_obs==0 (ImputationDiD) - Fix 6 (P3): Use scipy.sparse for FE dummy matrices in covariate v_it - Fix 7: Add 6 new tests, update REGISTRY.md edge cases and docstrings Co-Authored-By: Claude Opus 4.6 <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
|
…tstrap balance_e - Extract _iterative_demean as static method; fix _pretrend_test to use iterative demeaning (exact for unbalanced panels) instead of one-pass - Overall ATT SE: zero-weight NaN tau_hat observations so variance matches the finite-only ATT estimand; guard n_valid==0 returning NaN SE - Extract _compute_balanced_cohort_mask helper; apply in bootstrap event-study loop so bootstrap SEs respect balance_e filtering - Add 4 new tests covering all three fixes - Update REGISTRY.md edge cases documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/ai-review |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: Executive summary
Methodology
Code Quality
Performance
Maintainability
Tech Debt
Security
Documentation/Tests
|
…putationDiD Emit UserWarning when first_treat varies within a unit, which violates the absorbing treatment assumption. The estimator proceeds but warns users that results may be unreliable. Adds test and REGISTRY.md documentation. Co-Authored-By: Claude Opus 4.6 <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
|
…riance, weight/covariate fixes - Fix bootstrap to use Theorem 3 influence function (psi_i = sum_t v_it * epsilon_tilde_it) instead of perturbing raw tau_hat, correctly accounting for first-stage estimation error - Add sparse solver (spsolve) for variance normal equations to avoid O(p^2) memory blow-up, with dense lstsq fallback - Exclude rank-deficient covariates from variance design matrices A_0/A_1 via kept_cov_mask - Renormalize treatment_effects weights: 0 for NaN tau_hat, 1/n_valid for finite - Add 6 new tests: zero-noise bootstrap SE, sparse solver, dense fallback, weight consistency, rank-deficient covariates, bootstrap precomputation failure warning - Update REGISTRY.md edge cases documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment:
|
…riods _compute_balanced_cohort_mask had two bugs preventing pre-treatment balance checking: (1) required_range filtered from post-treatment-only all_horizons, missing negative values; (2) cohort horizons were built from Omega_1 (post-treatment), so negative rel_times were never seen. Fix: add _build_cohort_rel_times() to scan the full panel, and use range(-balance_e, max_h+1) for the required set. Co-Authored-By: Claude Opus 4.6 <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
|
…cstring
- Coerce non-constant first_treat to per-unit value via transform("first")
after warning, so downstream code (_never_treated, _treated, _rel_time)
uses a consistent value matching the Registry documentation
- Fix ImputationBootstrapResults docstring: weight_type is rademacher-only,
not "rademacher, mammen, webb"
- Add behavioral assertion to test verifying coercion actually applied
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
/ai-review |
1 similar comment
|
/ai-review |
|
🔁 AI review rerun (requested by @igerber) Head SHA: Overall assessment: Executive summary
Methodology
Code Quality
PerformanceNo issues found. Maintainability
Tech DebtNo issues found. SecurityNo issues found. Documentation/TestsNo issues found beyond the P1/P2 items above. |
… warning, dead code - Replace normal-approx bootstrap CIs/p-values with percentile/empirical method, matching CallawaySantAnna/SunAbraham convention. Shift perturbation-centered draws by original effect before computing CIs. - Warn when balance_e/horizon_max filter out all treated horizons, leaving only the reference period marker in event study results. - Remove unused omega_1_indices variable (ruff F841). Co-Authored-By: Claude Opus 4.6 <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
ImputationDiDestimator: the efficient imputation approach for staggered DiD from Borusyak, Jaravel & Spiess (2024)Methodology references (required if estimator / math changes)
Validation
tests/test_imputation.py(54 tests covering basic fit, aggregation modes, variance estimation, pre-trend test, bootstrap, cross-validation vs CS/SA, edge cases)docs/tutorials/11_imputation_did.ipynb, R benchmark scripts atbenchmarks/R/benchmark_didimputation.RSecurity / privacy
Generated with Claude Code