diff-diff: Difference-in-Differences in Python#

diff-diff is a Python library for Difference-in-Differences (DiD) causal inference analysis. It provides sklearn-like estimators with statsmodels-style output for econometric analysis.

from diff_diff import DifferenceInDifferences

# Fit a basic DiD model
did = DifferenceInDifferences()
results = did.fit(data, outcome='y', treatment='treated', time='post')
print(results.summary())

Key Features#

  • 20+ Estimators: Basic DiD, TWFE, Event Study, Synthetic DiD/Control, modern staggered estimators (Callaway-Sant’Anna, Sun-Abraham, Imputation, Two-Stage, Stacked, LP-DiD), reversible and heterogeneous-adoption designs (dCDH, HAD), distributional methods (Changes-in-Changes), Regression Discontinuity, and Bacon Decomposition diagnostics

  • Modern Inference: Robust standard errors, cluster-robust SEs, wild cluster bootstrap, and multiplier bootstrap

  • Assumption Testing: Parallel trends tests, placebo tests, Bacon decomposition, and comprehensive diagnostics

  • Sensitivity Analysis: Honest DiD (Rambachan & Roth 2023) for robust inference under parallel trends violations

  • Built-in Datasets: Real-world datasets from published studies (Card & Krueger, Castle Doctrine, and more)

  • High Performance: Optional Rust backend for compute-intensive estimators like Synthetic DiD and TROP

  • Publication-Ready Output: Summary tables, event study plots, and sensitivity analysis figures

Installation#

pip install diff-diff

For development:

pip install diff-diff[dev]

Explore the Documentation#

Getting Started

Install, run your first DiD analysis, and pick the right estimator for your design.

Getting Started
Practitioner Guide

Measuring campaign impact? A business-first path through DiD, no econometrics background required.

Practitioner Guide
Tutorials

28 hands-on notebooks, from basic 2x2 DiD to survey-weighted and spillover-aware designs.

Tutorials
User Guide

References, R and Python comparisons, benchmarks, and the methodology registry.

User Guide
API Reference

Complete reference for all estimators, results classes, diagnostics, and utilities.

API Reference

What is Difference-in-Differences?#

Difference-in-Differences (DiD) is a quasi-experimental research design that estimates causal treatment effects by comparing outcome changes over time between treated and control groups. It is one of the most widely used methods in applied economics, public policy evaluation, and social science research.

Why diff-diff?#

  • Complete method coverage: 20+ estimators from basic 2x2 DiD to cutting-edge methods like Efficient DiD (Chen et al. 2025), TROP (Athey et al. 2025), and HAD (de Chaisemartin et al. 2026)

  • Familiar API: sklearn-like fit() interface — if you know scikit-learn, you know diff-diff

  • Modern staggered methods: Callaway-Sant’Anna, Sun-Abraham, Imputation DiD, Two-Stage DiD, and Stacked DiD handle heterogeneous treatment timing correctly

  • Robust inference: Heteroskedasticity-robust, cluster-robust, wild cluster bootstrap, and multiplier bootstrap

  • Sensitivity analysis: Honest DiD (Rambachan & Roth 2023) for robust inference under parallel trends violations

  • Validated against R: Benchmarked against did, synthdid, and fixest — see Benchmarks

  • No heavy dependencies: Only numpy, pandas, and scipy

Supported Estimators#

Estimator

Description

DifferenceInDifferences

Basic 2x2 DiD with robust/clustered standard errors

TwoWayFixedEffects

Panel data with unit and time fixed effects

MultiPeriodDiD

Event study with period-specific treatment effects

CallawaySantAnna

Callaway & Sant’Anna (2021) group-time ATT for staggered adoption

ChaisemartinDHaultfoeuille

de Chaisemartin & D’Haultfoeuille (2020/2022) for reversible (non-absorbing) treatments

SunAbraham

Sun & Abraham (2021) interaction-weighted estimator

ImputationDiD

Borusyak, Jaravel & Spiess (2024) imputation estimator

TwoStageDiD

Gardner (2022) two-stage residualized estimator

SpilloverDiD

Butts (2021) ring-indicator spillover-aware DiD

SyntheticDiD

Synthetic DiD combining DiD and synthetic control

SyntheticControl

Abadie, Diamond & Hainmueller (2010) classic synthetic control

StackedDiD

Wing, Freedman & Hollingsworth (2024) stacked DiD

EfficientDiD

Chen, Sant’Anna & Xie (2025) efficient DiD

TripleDifference

Triple difference (DDD) estimator

StaggeredTripleDifference

Ortiz-Villavicencio & Sant’Anna (2025) staggered DDD with group-time ATT

ContinuousDiD

Callaway, Goodman-Bacon & Sant’Anna (2024) continuous-treatment dose-response DiD

HeterogeneousAdoptionDiD

de Chaisemartin, Ciccia, D’Haultfoeuille & Knau (2026) for designs with no untreated units

LPDiD

Dube, Girardi, Jorda & Taylor (2025) local-projections DiD

WooldridgeDiD

Wooldridge (2023, 2025) extended TWFE (ETWFE) via saturated OLS or QMLE

ChangesInChanges

Athey & Imbens (2006) distributional DiD with quantile treatment effects

QDiD

Quantile DiD comparison estimator applying DiD quantile-by-quantile

RegressionDiscontinuity

Calonico, Cattaneo & Titiunik (2014) sharp/fuzzy RD with robust bias-corrected inference

TROP

Triply Robust Panel with factor model adjustment (Athey et al. 2025)

BaconDecomposition

Goodman-Bacon decomposition diagnostics

Indices and tables#