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 Python library for Difference-in-Differences (DiD) causal inference — a statistical method that estimates the effect of a treatment (like a policy, campaign, or product launch) by comparing changes over time between a treated group and an untreated control group. It solves the practical problem of getting reliable causal estimates from real-world data that often has complications: treatments rolled out at different times, few treated units, treatments that switch on and off, or complex survey designs.

How it works

The library provides a consistent, scikit-learn-like API: you pass a dataframe with outcome, treatment, and time columns, call fit(), and get results with standard errors, p-values, and summary tables in the style of statsmodels. Under the hood it implements dozens of modern DiD estimators from the academic literature (e.g., Callaway & Sant'Anna, Synthetic DiD, Sun & Abraham, and many more), each tailored to specific data structures and assumptions. It also includes a suite of diagnostics — parallel-trends tests, placebo tests, sensitivity analysis, and design diagnosis — to validate that the assumptions behind the estimates hold. For survey data, it supports design-based variance estimation with strata, clusters, and weights.

Who it's for

Econometricians, marketing analysts, and data scientists who need to measure the causal impact of interventions — such as campaign lift, policy changes, product launches, or staggered rollouts — from observational or quasi-experimental data. It's also useful for researchers who want to compare multiple estimators and run robustness checks.

Highlights

  • Wide estimator coverage: from basic 2×2 DiD to advanced methods for staggered adoption, reversible treatments, continuous treatments, and even regression discontinuity.
  • Built-in diagnostics: parallel-trends tests, placebo tests, Bacon decomposition, honest DiD sensitivity bounds, and pre-trends power analysis.
  • Survey design support: handles complex survey designs (strata, PSU, weights) with Taylor linearization, replicate weights, and survey-aware bootstrap.
  • LLM-friendly guides: includes get_llm_guide() for AI agents and a practitioner workflow (Baker et al. 2025) to ensure rigorous analysis.
  • Validation against R packages: benchmarks and comparisons against did, synthdid, and fixest to ensure numerical parity.

Related

  • Project
  • Project
  • Project
  • Project
  • Project