Skip to content

feat: add LWDiD estimator (Lee & Wooldridge 2025, 2026)#588

Open
gorgeousfish wants to merge 1 commit into
igerber:mainfrom
gorgeousfish:feature/lwdid-estimator
Open

feat: add LWDiD estimator (Lee & Wooldridge 2025, 2026)#588
gorgeousfish wants to merge 1 commit into
igerber:mainfrom
gorgeousfish:feature/lwdid-estimator

Conversation

@gorgeousfish

@gorgeousfish gorgeousfish commented Jun 30, 2026

Copy link
Copy Markdown

This PR adds native support for the Lee & Wooldridge (2025, 2026) rolling-transformation difference-in-differences method. The approach works by applying unit-specific time-series transformations (demeaning or detrending) to panel outcomes before treatment, converting the panel DiD problem into a standard cross-sectional one. Once transformed, any treatment-effect estimator — regression adjustment, inverse probability weighting, doubly robust, or propensity-score matching — can be applied directly to the cross-section. The method handles both common-timing and staggered-adoption designs with flexible control-group selection.

The implementation lives entirely within diff_diff/lwdid*.py (9 modules) and introduces zero new runtime dependencies — it reuses the existing solve_ols, solve_logit, and safe_inference infrastructure. The IPW and IPWRA standard errors use the full semiparametric influence function with propensity-score and outcome-model correction terms, matching the variance formula in the authors' Stata package.

Numerical correctness has been validated against the reference lwdid Python package across all supported configurations. The RA path achieves machine-precision agreement (≤1e-10), and IPW/IPWRA paths agree to within 1%. The California Proposition 99 results from Table 3 of LW (2026) are reproduced exactly: demeaning ATT = −0.422, detrending ATT = −0.227.

Beyond core estimation, the PR includes wild cluster bootstrap inference (Rademacher/Mammen/Webb), Fisher randomization inference, parallel-trends pre-testing, sensitivity analysis, clustering-level diagnostics, and visualization methods. A tutorial notebook walks through the full workflow on the papers' empirical datasets (California smoking data, Castle Doctrine laws, Walmart county-level entry).

Methodology references (required if estimator / math changes)

  • Method name(s): LWDiD (Lee & Wooldridge rolling-transformation DiD)
  • Paper / source link(s):
  • Any intentional deviations from the source (and why): None. Implementation follows Procedures 2.1, 3.1, and 4.1 exactly. IPW/IPWRA SE uses the full semiparametric influence function matching the authors' Stata package (lwdid.ado).

Validation

  • Tests added/updated: 9 test files, 222 tests (unit tests, numerical precision, equivalence against lwdid-py, wild bootstrap, randomization, diagnostics, sensitivity, visualization)
  • Backtest / simulation / notebook evidence (if applicable): Tutorial notebook (docs/tutorials/26_lwdid.ipynb) reproduces Tables 3–4 from LW (2026) on California Proposition 99 data. ATT values match published results to 0.04% precision.

Security / privacy

  • Confirm no secrets/PII in this PR: Confirmed. No secrets, tokens, or PII. Datasets included (smoking.csv, walmart.csv, castle.csv) are publicly available research data from the referenced papers.

Native implementation of rolling-transformation DiD:
- Transformations: demean, detrend, demeanq, detrendq
- Estimation: RA, IPW, IPWRA, PSM
- Inference: classical, HC0-HC4, cluster-robust, t-distribution
- Designs: common timing + staggered adoption
- Advanced: wild cluster bootstrap, randomization inference
- Diagnostics: parallel trends, sensitivity, clustering
- Visualization: cohort trends, event study, sensitivity plots

Numerical equivalence validated against lwdid-py (tolerance ≤1e-10 for
RA paths) and paper Tables 3-4 (LW 2026) reproduced exactly.

Zero new runtime dependencies (uses existing numpy/pandas/scipy).

References:
- Lee, S.J. & Wooldridge, J.M. (2025). SSRN 4516518.
- Lee, S.J. & Wooldridge, J.M. (2026). SSRN 5325686.
@gorgeousfish gorgeousfish force-pushed the feature/lwdid-estimator branch from 9712477 to 8c5ccce Compare June 30, 2026 07:50
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