moderndid is a unified Python implementation of modern difference-in-differences (DiD) methodologies, bringing together the fragmented landscape of DiD estimators into a single, coherent framework. This package consolidates methods from leading econometric research and various R packages into one comprehensive Python library with a consistent API.
Warning
This package is currently in active development with core estimators and some sensitivity analysis implemented. The API is subject to change.
Each subpackage below is designed as a self-contained module with its own estimators, inference procedures, and visualization tools, while sharing common infrastructure for data handling and computation. This architecture choice aims to allow researchers to use exactly the methods they need while benefiting from a unified interface and consistent design principles across all DiD approaches.
moderndid.did
— Multiple time periods and variation in treatment timing with group-time effects and flexible aggregation schemes (Callaway & Sant'Anna, 2021).
moderndid.drdid
— Doubly robust difference-in-differences estimators for panel and repeated cross-section data with improved efficiency and robustness (Sant'Anna & Zhao, 2020).
moderndid.didhonest
— Sensitivity analysis for violations of parallel trends with multiple restriction types (Rambachan & Roth, 2023).
moderndid.didcont
— Continuous treatment DiD for dose-response relationships and non-binary treatments (Callaway et al., 2024).
moderndid.didtriple
- Triple DiD estimators with regression adjustment, inverse probability weighting, and doubly robust estimators that remain valid under covariate-adjusted DDD parallel trends (Ortiz-Villavicencio & Sant'Anna, 2025).
moderndid.didinter
— Intertemporal DiD for treatment effects where the treatment may be non-binary, non-absorbing, and the outcome may be affected by treatment lags (Chaisemartin & D'Haultfœuille, 2024).
moderndid.didml
— Modern machine learning approaches to DiD for estimation of time-varying conditional average treatment effects on the treated (Hatamyar et al., 2023).
moderndid.drdidweak
— Doubly robust estimators for treatment effect estimands that is also robust against weak covariate overlap (Ma et al., 2023).
moderndid.didcomp
— DiD setups with repeated cross-sectional data and potential compositional changes across time periods (Sant'Anna & Xu, 2025).
moderndid.didimpute
— DiD designs with staggered treatment adoption and heterogeneous causal effects via efficient imputation-based estimators (Borusyak, Jaravel, & Spiess, 2024).
moderndid.didbacon
— Goodman-Bacon decomposition to understand two-way fixed effects estimates as weighted averages of all possible 2x2 DiD comparisons (Goodman-Bacon, 2019).
moderndid.didlocal
— Local projections DiD to address possible biases arising from negative weighting (Dube et al., 2025).
moderndid.did2s
— Two-stage DiD for estimating TWFE models while avoiding issues with staggered treatment adoption (Gardner, 2021).
moderndid.functional
— Specification tests for functional form assumptions in DiD models (Roth & Sant'Anna, 2023).