diff-diff  by igerber

Python library for advanced Difference-in-Differences causal inference

Created 6 months ago
280 stars

Top 92.7% on SourcePulse

GitHubView on GitHub
Project Summary

Summary

igerber/diff-diff is a Python library designed for advanced Difference-in-Differences (DiD) causal inference. It provides a comprehensive suite of estimators, including cutting-edge methods for staggered adoption, event studies, and synthetic DiD, packaged with an sklearn-like API and statsmodels-style outputs. The library targets econometricians, marketing analysts, and data scientists, enabling rigorous causal inference for campaign-lift, policy evaluation, and staggered-rollout analyses through integrated diagnostics and sensitivity analysis tools.

How It Works

The library implements a wide array of DiD estimators, such as Callaway-Sant'Anna (CS), Sun-Abraham (SA), de Chaisemartin & D'Haultfœuille (DCDH) for reversible treatments, and SpilloverDiD. It promotes a rigorous 8-step practitioner workflow (Baker et al. 2025) that guides users through assumption testing, sensitivity analysis, and robustness checks, aiming for more reliable causal estimates than basic model fitting. The API is designed to be familiar to users of scikit-learn, while outputs resemble those from statsmodels for enhanced interpretability.

Quick Start & Requirements

Installation is performed using pip: pip install diff-diff. For development, clone the repository and install with pip install -e ".[dev]". The library requires Python 3.9-3.14 and standard numerical libraries including numpy (>=1.20), pandas (>=1.3), and scipy (>=1.7). Comprehensive documentation, tutorials, quick-start guides, and API references are available.

Highlighted Details

  • Extensive Estimator Coverage: Offers over a dozen DiD estimators, including specialized methods for staggered adoption, event studies, continuous treatments, and reversible treatments (DCDH).
  • Integrated Diagnostics & Sensitivity: Features built-in tools for parallel trends testing, placebo tests, Honest DiD sensitivity analysis, and heterogeneity analysis.
  • Survey Data Support: Uniquely provides design-based variance estimation for survey data across many estimators, supporting strata, PSUs, and FPCs.
  • AI Agent Workflow: Includes dedicated functions (get_llm_guide) for AI agents, offering concise API references and structured practitioner workflows.
  • Validation: Benchmarked and validated against R implementations, ensuring consistency and reliability.

Maintenance & Community

The project is primarily authored by Isaac Gerber, with contributions acknowledged collectively. Specific community channels (e.g., Discord, Slack) or sponsorship details are not prominently featured in the README.

Licensing & Compatibility

The library is released under the permissive MIT License, which allows for broad compatibility with commercial and closed-source applications.

Limitations & Caveats

Some reporting classes (BusinessReport, DiagnosticReport) are marked as experimental preview features. The HeterogeneousAdoptionDiD estimator is currently panel-only in this release. Specific estimators may have limitations regarding the types of survey weights they accept.

Health Check
Last Commit

21 hours ago

Responsiveness

Inactive

Pull Requests (30d)
131
Issues (30d)
6
Star History
18 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.