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. |
|
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. |
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 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. |
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. |
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. |
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. |
|
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. |
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. |
Data Preparation
Utilities for preparing DiD data:
Generate synthetic data for DiD analysis with known treatment effect. |
|
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. |
Module Documentation
Detailed documentation by module: