igerber/diff-diff
Difference-in-Differences causal inference in Python. Callaway-Sant'Anna, Synthetic DiD, Honest DiD, event studies. sklearn-like API, validated against R.
What it solves
diff-diff is a comprehensive Python library for Difference-in-Differences (DiD) causal inference. It provides a standardized, sklearn-like API to implement a wide array of econometric methods used to measure the causal effect of an intervention (such as a marketing campaign, policy change, or product launch) by comparing treated and control groups over time.
How it works
The library implements numerous causal estimators that handle different data scenarios, including:
- Staggered Adoption: Methods like Callaway & Sant'Anna and Sun & Abraham for when units are treated at different times.
- Synthetic Control: Combining DiD with synthetic control methods for cases with very few treated units.
- Complex Treatments: Support for reversible (non-absorbing) treatments, continuous treatments (dose-response), and triple-difference (DDD) designs.
- Advanced Diagnostics: Tools for testing parallel trends, running placebo tests, and performing sensitivity analysis (e.g., Honest DiD) to check how results hold up under assumption violations.
- Survey Integration: Built-in support for design-based variance estimation (strata, PSU, weights) for analyzing complex survey data like ACS or CPS.
Who it’s for
- Econometricians and Data Scientists: Those performing rigorous causal analysis on panel or cross-sectional data.
- Marketing Analysts: Professionals measuring campaign lift and product launch impact.
- Policy Researchers: Analysts evaluating the effects of policy rollouts across different regions or time periods.
Highlights
- Diverse Estimator Suite: Includes everything from basic 2x2 DiD and Two-Way Fixed Effects (TWFE) to cutting-edge methods like TROP and DMLDiD.
- Rigorous Workflow: Provides a structured 8-step practitioner workflow (based on Baker et al. 2025) to ensure results are not just calculated but validated.
- AI-Agent Ready: Includes a specialized
get_llm_guide()function to provide LLMs with concise API references and workflows. - Comprehensive Diagnostics: Features tools for Bacon Decomposition, RD plots, and manipulation testing for Regression Discontinuity designs.
Related
- Project
- Project
- Project
- Project
- Project