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 provides a comprehensive toolkit for Difference-in-Differences (DiD) causal inference, allowing researchers and analysts to measure the actual impact of a treatment or policy (the "lift") by comparing treated and control groups over time. It specifically addresses the complexities of modern causal analysis, such as staggered rollouts (where different units receive treatment at different times), reversible treatments, and the need for rigorous sensitivity testing to ensure results aren't driven by coincidental trends.

How it works

The library implements a wide array of econometric estimators with a scikit-learn-like API (fit and predict patterns) and statsmodels-style output. It supports various design patterns:

  • Standard DiD: Basic 2x2 comparisons.
  • Staggered Adoption: Advanced estimators like Callaway & Sant'Anna, Sun & Abraham, and Imputation DiD to handle varying treatment timing.
  • Synthetic Control/DiD: Creating weighted counterfactuals for cases with very few treated units.
  • Specialized Designs: Regression Discontinuity (RDD), Triple Difference (DDD), and Continuous DiD for dose-response analysis.
  • Robustness Tools: Built-in diagnostics for parallel trends, placebo tests, and "Honest DiD" sensitivity analysis to bound results under potential assumption violations.
  • Survey Integration: Native support for design-based variance estimation (strata, PSU, weights) for complex survey data like ACS or CPS.

Who it’s for

  • Econometricians and Academic Researchers: For rigorous causal inference and policy evaluation.
  • Marketing Analysts: For measuring campaign lift and product launch impact.
  • Data Scientists: For running A/B tests, staggered rollouts, and business impact analysis.

Highlights

  • Extensive Estimator Library: Includes modern implementations of CS, SA, BJS, and TROP estimators.
  • Rigorous Workflow: Provides a structured 8-step practitioner workflow (Baker et al. 2025) to prevent unreliable results.
  • Survey-Aware: The only Python/R DiD package offering design-based variance estimation for modern heterogeneity-robust estimators.
  • AI-Ready: Includes a get_llm_guide() function to provide concise API references and workflows specifically for AI agents.
  • Comprehensive Diagnostics: Includes RD plots, manipulation testing, and spatial HAC standard errors (Conley SEs).

Related

  • Project
  • Project
  • Project
  • Project
  • Project