API Reference#
This section provides complete API documentation for all diff-diff modules.
Estimators#
Core estimator classes for DiD analysis:
Difference-in-Differences estimator with sklearn-like interface. |
|
Two-Way Fixed Effects (TWFE) estimator for panel DiD. |
|
Multi-Period Difference-in-Differences estimator. |
|
Synthetic Difference-in-Differences (SDID) estimator. |
|
Callaway-Sant'Anna (2021) estimator for staggered Difference-in-Differences. |
|
de Chaisemartin-D'Haultfoeuille (dCDH) estimator. |
|
Sun-Abraham (2021) interaction-weighted estimator for staggered DiD. |
|
Borusyak-Jaravel-Spiess (2024) imputation DiD estimator. |
|
Stacked Difference-in-Differences estimator. |
|
Triple Difference (DDD) estimator. |
|
Triply Robust Panel (TROP) estimator. |
|
Continuous Difference-in-Differences estimator. |
|
Heterogeneous Adoption Difference-in-Differences estimator. |
|
Efficient DiD estimator (Chen, Sant'Anna & Xie 2025). |
|
Gardner (2022) two-stage Difference-in-Differences estimator. |
|
Ring-indicator spillover-aware DiD (Butts 2021). |
|
Extended Two-Way Fixed Effects (ETWFE) DiD estimator. |
|
Goodman-Bacon (2021) decomposition of Two-Way Fixed Effects estimator. |
|
Staggered Triple Difference (DDD) estimator. |
Results Classes#
Result containers returned by estimators:
Results from a Difference-in-Differences estimation. |
|
Results from a Multi-Period Difference-in-Differences estimation. |
|
Results from a Synthetic Difference-in-Differences estimation. |
|
Treatment effect for a single time period. |
|
Results from Callaway-Sant'Anna (2021) staggered DiD estimation. |
|
Results from Callaway-Sant'Anna multiplier bootstrap inference. |
|
Treatment effect for a specific group-time combination. |
|
Results from de Chaisemartin-D'Haultfoeuille (dCDH) Phase 1 estimation. |
|
Results from ChaisemartinDHaultfoeuille (dCDH) multiplier bootstrap inference. |
|
Results from Sun-Abraham (2021) interaction-weighted estimation. |
|
Results from Sun-Abraham bootstrap inference. |
|
Results from Borusyak-Jaravel-Spiess (2024) imputation DiD estimation. |
|
Results from ImputationDiD bootstrap inference. |
|
Results from Triple Difference (DDD) estimation. |
|
Results from Stacked DiD estimation (Wing, Freedman & Hollingsworth 2024). |
|
Results from a Triply Robust Panel (TROP) estimation. |
|
Results from Continuous Difference-in-Differences estimation. |
|
Dose-response curve from continuous DiD estimation. |
|
Estimator output for |
|
Event-study results for |
|
Results from Efficient DiD (Chen, Sant'Anna & Xie 2025) estimation. |
|
Bootstrap inference results for EfficientDiD. |
|
Results from Gardner (2022) two-stage DiD estimation. |
|
Results from TwoStageDiD bootstrap inference. |
|
Results from a ring-indicator spillover-aware DiD estimation (Butts 2021). |
|
Results from Goodman-Bacon decomposition of TWFE. |
|
Results from WooldridgeDiD.fit(). |
|
A single 2x2 DiD comparison in the Bacon decomposition. |
|
Results from Staggered Triple Difference (DDD) estimation. |
|
Lightweight container for the standalone |
Visualization#
Plotting functions for results:
Create an event study plot showing treatment effects over time. |
|
Plot treatment effects by treatment cohort (group). |
|
Plot sensitivity analysis results from Honest DiD. |
|
Create event study plot with Honest DiD confidence intervals. |
|
Visualize Goodman-Bacon decomposition results. |
|
Create a power curve visualization. |
|
Plot pre-trends test power curve. |
Diagnostics#
Placebo tests and model diagnostics:
Run a placebo test to validate DiD assumptions. |
|
Test for pre-treatment effects by moving treatment timing earlier. |
|
Test for differential trends among never-treated units. |
|
Compute permutation-based p-value for DiD estimate. |
|
Assess sensitivity by dropping each treated unit in turn. |
|
Run a comprehensive suite of placebo tests. |
|
Results from a placebo test for DiD assumption validation. |
Panel Profiling#
Pre-fit description of panel structure for estimator selection. The
PanelProfile return type and its supporting dataclasses
are documented in Panel Profiling.
Describe the structure of a DiD panel. |
|
Structural facts about a DiD panel. |
|
Distributional shape of a numeric outcome column. |
|
Distributional shape of a continuous treatment dose. |
|
A factual observation about a panel. |
Sensitivity Analysis#
Honest DiD for robust inference:
Honest DiD sensitivity analysis (Rambachan & Roth 2023). |
|
Results from Honest DiD sensitivity analysis. |
|
Results from sensitivity analysis over a grid of M values. |
|
Smoothness restriction on trend violations (Delta^{SD}). |
|
Relative magnitudes restriction on trend violations (Delta^{RM}). |
|
Combined smoothness and relative magnitudes restriction. |
|
Convenience function for computing Honest DiD bounds. |
|
Create a sensitivity analysis plot. |
Parallel Trends Testing#
Testing the parallel trends assumption:
Perform a simple check for parallel trends assumption. |
|
Perform robust parallel trends testing using distributional comparisons. |
|
Perform equivalence testing (TOST) for parallel trends. |
HAD Pretest Workflow#
Companion pretest battery for HeterogeneousAdoptionDiD implementing the
Section 4 QUG / Stute / Yatchew tests from de Chaisemartin, Ciccia,
D’Haultfœuille & Knau (2026), plus a unified report wrapper:
Composite output of |
|
Result of |
|
Result of |
|
Result of |
|
Result of |
Bootstrap Inference#
Wild cluster bootstrap for valid inference:
Compute wild cluster bootstrap standard errors and p-values. |
|
Results from wild cluster bootstrap inference. |
Power Analysis#
Power analysis for study design:
Power analysis for difference-in-differences designs. |
|
Results from analytical power analysis. |
|
Results from simulation-based power analysis. |
|
Results from simulation-based minimum detectable effect search. |
|
Results from simulation-based sample size search. |
|
Convenience function to compute power for given effect and sample. |
|
Convenience function to compute minimum detectable effect. |
|
Convenience function to compute required sample size. |
|
Estimate power using Monte Carlo simulation. |
|
Find the minimum detectable effect via simulation-based bisection search. |
|
Find the required sample size via simulation-based bisection search. |
Pre-Trends Power Analysis#
Power analysis for pre-trends tests (Roth 2022):
Pre-trends power analysis (Roth 2022). |
|
Results from pre-trends power analysis. |
|
Power curve across violation magnitudes. |
|
Convenience function for pre-trends power analysis. |
|
Compute minimum detectable violation. |
Reporting#
Stakeholder-facing report and diagnostic battery wrappers around fitted result objects:
Produce a stakeholder-ready narrative from any diff-diff results object. |
|
Frozen bundle of business-framing metadata used when rendering prose. |
|
Run the standard diff-diff diagnostic battery on a fitted result. |
|
Frozen container holding the outcome of a |
Boundary Local-Linear Estimators#
Calonico-Cattaneo-Farrell (2018) MSE-optimal bandwidth selector and
Calonico-Cattaneo-Titiunik (2014) robust-bias-corrected local-linear fit
used by HeterogeneousAdoptionDiD’s continuous-dose fit paths
(continuous_at_zero and continuous_near_d_lower):
Result of a local-linear regression at a boundary. |
|
MSE-optimal bandwidth selector output plus per-stage diagnostics. |
|
Bias-corrected local-linear fit at a boundary (Phase 1c). |
Data Preparation#
Utilities for preparing DiD data:
Generate synthetic data for DiD analysis with known treatment effect. |
|
Generate synthetic data for continuous DiD analysis with known dose-response. |
|
Generate synthetic data for staggered adoption DiD analysis. |
|
Generate synthetic data for event study analysis. |
|
Generate synthetic data for Triple Difference (DDD) analysis. |
|
Generate synthetic panel data with interactive fixed effects (factor model). |
|
Generate synthetic panel data for parallel trends testing. |
|
Create a binary treatment indicator column from various input types. |
|
Create a binary post-treatment indicator column. |
|
Convert wide-format panel data to long format for DiD analysis. |
|
Balance a panel dataset to ensure all units have all time periods. |
|
Validate that data is properly formatted for DiD analysis. |
|
Generate summary statistics by treatment group and time period. |
|
Create an event-time column relative to treatment timing. |
|
Aggregate unit-level data to treatment cohort means. |
|
Rank potential control units by their suitability for DiD analysis. |
Datasets#
Built-in datasets for examples and testing:
Load the Card & Krueger (1994) minimum wage dataset. |
|
Load Castle Doctrine / Stand Your Ground laws dataset. |
|
Load unilateral divorce laws dataset. |
|
Load the Minimum Wage Panel Dataset for DiD Analysis (mpdta). |
|
Load a dataset by name. |
|
List available real-world datasets. |
|
Clear the local dataset cache. |
Module Documentation#
Estimators#
- Estimators
- Staggered Adoption
- de Chaisemartin-D’Haultfœuille (dCDH) DiD
- Imputation DiD (Borusyak et al. 2024)
- Stacked Difference-in-Differences
- Triple Difference (DDD)
- Triply Robust Panel (TROP)
- Continuous Difference-in-Differences
- Heterogeneous Adoption Difference-in-Differences
- Efficient Difference-in-Differences
- Two-Stage DiD (Gardner 2022)
- Spillover-Aware DiD (Butts 2021)
- Wooldridge Extended Two-Way Fixed Effects (ETWFE)
- Bacon Decomposition (Goodman-Bacon 2021)