diff-diff

User Guide

  • Getting Started
    • Installation
    • Basic 2x2 DiD
    • Using Formula Interface
    • Adding Covariates
    • Cluster-Robust Standard Errors
    • Two-Way Fixed Effects
    • Event Study Design
    • Staggered Adoption
    • Parallel Trends Testing
    • Sensitivity Analysis
    • Next Steps
  • Choosing an Estimator
    • Decision Flowchart
    • Quick Reference
    • Detailed Guidance
      • Basic 2x2 DiD
      • Two-Way Fixed Effects
      • Multi-Period Event Study
      • Callaway-Sant’Anna
      • Synthetic DiD
    • Common Pitfalls
    • Standard Error Methods
    • When in Doubt
  • Troubleshooting
    • Data Issues
      • “No treated observations found”
      • “Panel is unbalanced”
    • Estimation Errors
      • “Singular matrix” or “Matrix is singular”
      • “Bootstrap iterations failed” warning
    • Standard Error Issues
      • “Standard errors seem too small/large”
      • “Wild bootstrap takes too long”
    • Staggered Adoption Issues
      • “No never-treated units found”
      • “Group-time effects have large standard errors”
    • Visualization Issues
      • “Event study plot looks wrong”
      • “Plot doesn’t show in Jupyter”
    • Performance Issues
      • “Estimation is slow”
    • Getting Help
  • Comparison with R Packages
    • Overview
    • Package Correspondence
      • R did Package → diff-diff
      • R HonestDiD Package → diff-diff
      • R synthdid Package → diff-diff
    • Key Differences
      • Design Philosophy
      • Inference
      • Fixed Effects
      • Output Format
    • Feature Comparison Table
    • Migration Tips
  • Comparison with Python Packages
    • Overview
    • Package Summaries
      • pyfixest
      • differences
      • CausalPy
      • linearmodels
    • Why diff-diff?
    • Feature Comparison Table
    • Code Comparison
      • Basic DiD
      • Staggered DiD (Callaway-Sant’Anna)
      • Sensitivity Analysis
    • When to Use Each Package
  • Benchmarks: Validation Against R Packages
    • Overview
    • Methodology
      • Validation Approach
      • Tolerance Thresholds
    • Benchmark Results
      • Summary Table
      • Basic DiD Results
      • MultiPeriodDiD Results
      • Synthetic DiD Results
      • Callaway-Sant’Anna Results
    • Performance Comparison
      • Three-Way Performance Summary
      • Dataset Sizes
      • Key Observations
      • Performance Optimization Details
      • Why is diff-diff Fast?
    • Real-World Data Validation
      • MPDTA Dataset
      • Results Comparison
    • Reproducing Benchmarks
      • Prerequisites
      • Running Benchmarks
      • Output
    • Interpretation Notes
      • When to Trust Results
      • Known Differences
    • References

API Reference

  • API Reference
    • Estimators
      • diff_diff.DifferenceInDifferences
        • DifferenceInDifferences
      • diff_diff.TwoWayFixedEffects
        • TwoWayFixedEffects
      • diff_diff.MultiPeriodDiD
        • MultiPeriodDiD
      • diff_diff.SyntheticDiD
        • SyntheticDiD
      • diff_diff.CallawaySantAnna
        • CallawaySantAnna
      • diff_diff.SunAbraham
        • SunAbraham
      • diff_diff.ImputationDiD
        • ImputationDiD
      • diff_diff.StackedDiD
        • StackedDiD
      • diff_diff.TripleDifference
        • TripleDifference
      • diff_diff.TROP
        • TROP
    • Results Classes
      • diff_diff.DiDResults
        • DiDResults
      • diff_diff.MultiPeriodDiDResults
        • MultiPeriodDiDResults
      • diff_diff.SyntheticDiDResults
        • SyntheticDiDResults
      • diff_diff.PeriodEffect
        • PeriodEffect
      • diff_diff.CallawaySantAnnaResults
        • CallawaySantAnnaResults
      • diff_diff.CSBootstrapResults
        • CSBootstrapResults
      • diff_diff.GroupTimeEffect
        • GroupTimeEffect
      • diff_diff.SunAbrahamResults
        • SunAbrahamResults
      • diff_diff.SABootstrapResults
        • SABootstrapResults
      • diff_diff.ImputationDiDResults
        • ImputationDiDResults
      • diff_diff.ImputationBootstrapResults
        • ImputationBootstrapResults
      • diff_diff.TripleDifferenceResults
        • TripleDifferenceResults
      • diff_diff.StackedDiDResults
        • StackedDiDResults
      • diff_diff.trop.TROPResults
        • TROPResults
    • Visualization
      • diff_diff.plot_event_study
        • plot_event_study()
      • diff_diff.plot_group_effects
        • plot_group_effects()
      • diff_diff.plot_sensitivity
        • plot_sensitivity()
      • diff_diff.plot_honest_event_study
        • plot_honest_event_study()
      • diff_diff.plot_bacon
        • plot_bacon()
      • diff_diff.plot_power_curve
        • plot_power_curve()
      • diff_diff.plot_pretrends_power
        • plot_pretrends_power()
    • Diagnostics
      • diff_diff.run_placebo_test
        • run_placebo_test()
      • diff_diff.placebo_timing_test
        • placebo_timing_test()
      • diff_diff.placebo_group_test
        • placebo_group_test()
      • diff_diff.permutation_test
        • permutation_test()
      • diff_diff.leave_one_out_test
        • leave_one_out_test()
      • diff_diff.run_all_placebo_tests
        • run_all_placebo_tests()
      • diff_diff.PlaceboTestResults
        • PlaceboTestResults
    • Sensitivity Analysis
      • diff_diff.HonestDiD
        • HonestDiD
      • diff_diff.HonestDiDResults
        • HonestDiDResults
      • diff_diff.SensitivityResults
        • SensitivityResults
      • diff_diff.DeltaSD
        • DeltaSD
      • diff_diff.DeltaRM
        • DeltaRM
      • diff_diff.DeltaSDRM
        • DeltaSDRM
      • diff_diff.compute_honest_did
        • compute_honest_did()
      • diff_diff.sensitivity_plot
        • sensitivity_plot()
    • Parallel Trends Testing
      • diff_diff.check_parallel_trends
        • check_parallel_trends()
      • diff_diff.check_parallel_trends_robust
        • check_parallel_trends_robust()
      • diff_diff.equivalence_test_trends
        • equivalence_test_trends()
    • Bootstrap Inference
      • diff_diff.wild_bootstrap_se
        • wild_bootstrap_se()
      • diff_diff.WildBootstrapResults
        • WildBootstrapResults
    • Power Analysis
      • diff_diff.PowerAnalysis
        • PowerAnalysis
      • diff_diff.PowerResults
        • PowerResults
      • diff_diff.SimulationPowerResults
        • SimulationPowerResults
      • diff_diff.compute_power
        • compute_power()
      • diff_diff.compute_mde
        • compute_mde()
      • diff_diff.compute_sample_size
        • compute_sample_size()
      • diff_diff.simulate_power
        • simulate_power()
    • Pre-Trends Power Analysis
      • diff_diff.PreTrendsPower
        • PreTrendsPower
      • diff_diff.PreTrendsPowerResults
        • PreTrendsPowerResults
      • diff_diff.PreTrendsPowerCurve
        • PreTrendsPowerCurve
      • diff_diff.compute_pretrends_power
        • compute_pretrends_power()
      • diff_diff.compute_mdv
        • compute_mdv()
    • Data Preparation
      • diff_diff.generate_did_data
        • generate_did_data()
      • diff_diff.make_treatment_indicator
        • make_treatment_indicator()
      • diff_diff.make_post_indicator
        • make_post_indicator()
      • diff_diff.wide_to_long
        • wide_to_long()
      • diff_diff.balance_panel
        • balance_panel()
      • diff_diff.validate_did_data
        • validate_did_data()
      • diff_diff.summarize_did_data
        • summarize_did_data()
      • diff_diff.create_event_time
        • create_event_time()
      • diff_diff.aggregate_to_cohorts
        • aggregate_to_cohorts()
      • diff_diff.rank_control_units
        • rank_control_units()
    • Module Documentation
      • Estimators
        • DifferenceInDifferences
        • MultiPeriodDiD
        • TwoWayFixedEffects
        • SyntheticDiD
        • TripleDifference
      • Staggered Adoption
        • CallawaySantAnna
        • CallawaySantAnnaResults
        • GroupTimeEffect
        • SunAbraham
        • SunAbrahamResults
        • SABootstrapResults
      • Imputation DiD (Borusyak et al. 2024)
        • ImputationDiD
        • ImputationDiDResults
        • ImputationBootstrapResults
        • Convenience Function
        • Example Usage
      • Stacked Difference-in-Differences
        • StackedDiD
        • StackedDiDResults
        • Convenience Function
        • Example Usage
        • Comparison with Other Staggered Estimators
      • Triple Difference (DDD)
        • TripleDifference
        • TripleDifferenceResults
        • Convenience Function
        • Estimation Methods
        • Example Usage
      • Triply Robust Panel (TROP)
        • TROP
        • TROPResults
        • Convenience Function
        • Tuning Parameters
        • Estimation Methods
        • Example Usage
        • Comparison with Synthetic DiD
      • Results Classes
        • DiDResults
        • MultiPeriodDiDResults
        • PeriodEffect
        • SyntheticDiDResults
      • Visualization
        • plot_event_study
        • plot_group_effects
        • plot_sensitivity
        • plot_honest_event_study
      • Diagnostics
        • run_placebo_test
        • placebo_timing_test
        • placebo_group_test
        • permutation_test
        • leave_one_out_test
        • run_all_placebo_tests
        • PlaceboTestResults
      • Honest DiD
        • Overview
        • HonestDiD
        • HonestDiDResults
        • SensitivityResults
        • Restriction Classes
        • Convenience Functions
        • Complete Example
        • References
      • Power Analysis
        • Overview
        • PowerAnalysis
        • PowerResults
        • SimulationPowerResults
        • Convenience Functions
        • Complete Example
        • See Also
      • Pre-Trends Power Analysis
        • Overview
        • PreTrendsPower
        • PreTrendsPowerResults
        • PreTrendsPowerCurve
        • Convenience Functions
        • Violation Types
        • Complete Example
        • References
        • See Also
      • Utilities
        • Parallel Trends Testing
        • Wild Cluster Bootstrap
      • Data Preparation
        • Data Generation
        • Indicator Creation
        • Panel Data Utilities
        • Staggered Adoption Utilities
        • Data Validation
        • Control Unit Selection
  • Estimators
    • DifferenceInDifferences
      • DifferenceInDifferences
        • DifferenceInDifferences.results_
        • DifferenceInDifferences.is_fitted_
        • DifferenceInDifferences.__init__()
        • DifferenceInDifferences.fit()
        • DifferenceInDifferences.predict()
        • DifferenceInDifferences.get_params()
        • DifferenceInDifferences.set_params()
        • DifferenceInDifferences.summary()
        • DifferenceInDifferences.print_summary()
    • MultiPeriodDiD
      • MultiPeriodDiD
        • MultiPeriodDiD.results_
        • MultiPeriodDiD.is_fitted_
        • MultiPeriodDiD.fit()
        • MultiPeriodDiD.summary()
        • MultiPeriodDiD.__init__()
        • MultiPeriodDiD.get_params()
        • MultiPeriodDiD.predict()
        • MultiPeriodDiD.print_summary()
        • MultiPeriodDiD.set_params()
    • TwoWayFixedEffects
      • TwoWayFixedEffects
        • TwoWayFixedEffects.fit()
        • TwoWayFixedEffects.decompose()
        • TwoWayFixedEffects.__init__()
        • TwoWayFixedEffects.get_params()
        • TwoWayFixedEffects.predict()
        • TwoWayFixedEffects.print_summary()
        • TwoWayFixedEffects.set_params()
        • TwoWayFixedEffects.summary()
    • SyntheticDiD
      • SyntheticDiD
        • SyntheticDiD.results_
        • SyntheticDiD.is_fitted_
        • SyntheticDiD.__init__()
        • SyntheticDiD.fit()
        • SyntheticDiD.get_params()
        • SyntheticDiD.set_params()
        • SyntheticDiD.predict()
        • SyntheticDiD.print_summary()
        • SyntheticDiD.summary()
    • TripleDifference
      • TripleDifference
        • TripleDifference.results_
        • TripleDifference.is_fitted_
        • TripleDifference.__init__()
        • TripleDifference.results_
        • TripleDifference.fit()
        • TripleDifference.get_params()
        • TripleDifference.set_params()
        • TripleDifference.summary()
        • TripleDifference.print_summary()
      • TripleDifferenceResults
        • TripleDifferenceResults
      • Convenience Function
        • triple_difference()
  • Staggered Adoption
    • CallawaySantAnna
      • CallawaySantAnna
        • CallawaySantAnna.results_
        • CallawaySantAnna.is_fitted_
        • CallawaySantAnna.__init__()
        • CallawaySantAnna.anticipation
        • CallawaySantAnna.alpha
        • CallawaySantAnna.n_bootstrap
        • CallawaySantAnna.bootstrap_weight_type
        • CallawaySantAnna.seed
        • CallawaySantAnna.base_period
        • CallawaySantAnna.results_
        • CallawaySantAnna.fit()
        • CallawaySantAnna.get_params()
        • CallawaySantAnna.set_params()
        • CallawaySantAnna.summary()
        • CallawaySantAnna.print_summary()
    • CallawaySantAnnaResults
      • CallawaySantAnnaResults
        • CallawaySantAnnaResults.group_time_effects
        • CallawaySantAnnaResults.overall_att
        • CallawaySantAnnaResults.overall_se
        • CallawaySantAnnaResults.overall_p_value
        • CallawaySantAnnaResults.overall_conf_int
        • CallawaySantAnnaResults.groups
        • CallawaySantAnnaResults.time_periods
        • CallawaySantAnnaResults.n_obs
        • CallawaySantAnnaResults.n_treated_units
        • CallawaySantAnnaResults.n_control_units
        • CallawaySantAnnaResults.event_study_effects
        • CallawaySantAnnaResults.group_effects
        • CallawaySantAnnaResults.group_time_effects
        • CallawaySantAnnaResults.overall_att
        • CallawaySantAnnaResults.overall_se
        • CallawaySantAnnaResults.overall_t_stat
        • CallawaySantAnnaResults.overall_p_value
        • CallawaySantAnnaResults.overall_conf_int
        • CallawaySantAnnaResults.groups
        • CallawaySantAnnaResults.time_periods
        • CallawaySantAnnaResults.n_obs
        • CallawaySantAnnaResults.n_treated_units
        • CallawaySantAnnaResults.n_control_units
        • CallawaySantAnnaResults.alpha
        • CallawaySantAnnaResults.control_group
        • CallawaySantAnnaResults.base_period
        • CallawaySantAnnaResults.event_study_effects
        • CallawaySantAnnaResults.group_effects
        • CallawaySantAnnaResults.influence_functions
        • CallawaySantAnnaResults.bootstrap_results
        • CallawaySantAnnaResults.__repr__()
        • CallawaySantAnnaResults.summary()
        • CallawaySantAnnaResults.print_summary()
        • CallawaySantAnnaResults.to_dataframe()
        • CallawaySantAnnaResults.is_significant
        • CallawaySantAnnaResults.significance_stars
        • CallawaySantAnnaResults.__init__()
    • GroupTimeEffect
      • GroupTimeEffect
        • GroupTimeEffect.group
        • GroupTimeEffect.time
        • GroupTimeEffect.effect
        • GroupTimeEffect.se
        • GroupTimeEffect.n_treated
        • GroupTimeEffect.n_control
        • GroupTimeEffect.group
        • GroupTimeEffect.time
        • GroupTimeEffect.effect
        • GroupTimeEffect.se
        • GroupTimeEffect.t_stat
        • GroupTimeEffect.p_value
        • GroupTimeEffect.conf_int
        • GroupTimeEffect.n_treated
        • GroupTimeEffect.n_control
        • GroupTimeEffect.is_significant
        • GroupTimeEffect.significance_stars
        • GroupTimeEffect.__init__()
    • SunAbraham
      • SunAbraham
        • SunAbraham.results_
        • SunAbraham.is_fitted_
        • SunAbraham.__init__()
        • SunAbraham.results_
        • SunAbraham.fit()
        • SunAbraham.get_params()
        • SunAbraham.set_params()
        • SunAbraham.summary()
        • SunAbraham.print_summary()
    • SunAbrahamResults
      • SunAbrahamResults
        • SunAbrahamResults.event_study_effects
        • SunAbrahamResults.overall_att
        • SunAbrahamResults.overall_se
        • SunAbrahamResults.overall_t_stat
        • SunAbrahamResults.overall_p_value
        • SunAbrahamResults.overall_conf_int
        • SunAbrahamResults.cohort_weights
        • SunAbrahamResults.groups
        • SunAbrahamResults.time_periods
        • SunAbrahamResults.n_obs
        • SunAbrahamResults.n_treated_units
        • SunAbrahamResults.n_control_units
        • SunAbrahamResults.alpha
        • SunAbrahamResults.control_group
        • SunAbrahamResults.event_study_effects
        • SunAbrahamResults.overall_att
        • SunAbrahamResults.overall_se
        • SunAbrahamResults.overall_t_stat
        • SunAbrahamResults.overall_p_value
        • SunAbrahamResults.overall_conf_int
        • SunAbrahamResults.cohort_weights
        • SunAbrahamResults.groups
        • SunAbrahamResults.time_periods
        • SunAbrahamResults.n_obs
        • SunAbrahamResults.n_treated_units
        • SunAbrahamResults.n_control_units
        • SunAbrahamResults.alpha
        • SunAbrahamResults.control_group
        • SunAbrahamResults.bootstrap_results
        • SunAbrahamResults.cohort_effects
        • SunAbrahamResults.__repr__()
        • SunAbrahamResults.summary()
        • SunAbrahamResults.print_summary()
        • SunAbrahamResults.to_dataframe()
        • SunAbrahamResults.is_significant
        • SunAbrahamResults.significance_stars
        • SunAbrahamResults.__init__()
    • SABootstrapResults
      • SABootstrapResults
        • SABootstrapResults.n_bootstrap
        • SABootstrapResults.weight_type
        • SABootstrapResults.alpha
        • SABootstrapResults.overall_att_se
        • SABootstrapResults.overall_att_ci
        • SABootstrapResults.overall_att_p_value
        • SABootstrapResults.event_study_ses
        • SABootstrapResults.event_study_cis
        • SABootstrapResults.event_study_p_values
        • SABootstrapResults.bootstrap_distribution
        • SABootstrapResults.n_bootstrap
        • SABootstrapResults.weight_type
        • SABootstrapResults.alpha
        • SABootstrapResults.overall_att_se
        • SABootstrapResults.overall_att_ci
        • SABootstrapResults.overall_att_p_value
        • SABootstrapResults.event_study_ses
        • SABootstrapResults.event_study_cis
        • SABootstrapResults.event_study_p_values
        • SABootstrapResults.bootstrap_distribution
        • SABootstrapResults.__init__()
  • Results Classes
    • DiDResults
      • DiDResults
        • DiDResults.att
        • DiDResults.se
        • DiDResults.t_stat
        • DiDResults.p_value
        • DiDResults.conf_int
        • DiDResults.n_obs
        • DiDResults.n_treated
        • DiDResults.n_control
        • DiDResults.att
        • DiDResults.se
        • DiDResults.t_stat
        • DiDResults.p_value
        • DiDResults.conf_int
        • DiDResults.n_obs
        • DiDResults.n_treated
        • DiDResults.n_control
        • DiDResults.alpha
        • DiDResults.coefficients
        • DiDResults.vcov
        • DiDResults.residuals
        • DiDResults.fitted_values
        • DiDResults.r_squared
        • DiDResults.inference_method
        • DiDResults.n_bootstrap
        • DiDResults.n_clusters
        • DiDResults.bootstrap_distribution
        • DiDResults.__repr__()
        • DiDResults.summary()
        • DiDResults.print_summary()
        • DiDResults.to_dict()
        • DiDResults.to_dataframe()
        • DiDResults.is_significant
        • DiDResults.significance_stars
        • DiDResults.__init__()
    • MultiPeriodDiDResults
      • MultiPeriodDiDResults
        • MultiPeriodDiDResults.period_effects
        • MultiPeriodDiDResults.avg_att
        • MultiPeriodDiDResults.avg_se
        • MultiPeriodDiDResults.avg_t_stat
        • MultiPeriodDiDResults.avg_p_value
        • MultiPeriodDiDResults.avg_conf_int
        • MultiPeriodDiDResults.n_obs
        • MultiPeriodDiDResults.n_treated
        • MultiPeriodDiDResults.n_control
        • MultiPeriodDiDResults.pre_periods
        • MultiPeriodDiDResults.post_periods
        • MultiPeriodDiDResults.reference_period
        • MultiPeriodDiDResults.interaction_indices
        • MultiPeriodDiDResults.period_effects
        • MultiPeriodDiDResults.avg_att
        • MultiPeriodDiDResults.avg_se
        • MultiPeriodDiDResults.avg_t_stat
        • MultiPeriodDiDResults.avg_p_value
        • MultiPeriodDiDResults.avg_conf_int
        • MultiPeriodDiDResults.n_obs
        • MultiPeriodDiDResults.n_treated
        • MultiPeriodDiDResults.n_control
        • MultiPeriodDiDResults.pre_periods
        • MultiPeriodDiDResults.post_periods
        • MultiPeriodDiDResults.alpha
        • MultiPeriodDiDResults.coefficients
        • MultiPeriodDiDResults.vcov
        • MultiPeriodDiDResults.residuals
        • MultiPeriodDiDResults.fitted_values
        • MultiPeriodDiDResults.r_squared
        • MultiPeriodDiDResults.reference_period
        • MultiPeriodDiDResults.interaction_indices
        • MultiPeriodDiDResults.__repr__()
        • MultiPeriodDiDResults.pre_period_effects
        • MultiPeriodDiDResults.post_period_effects
        • MultiPeriodDiDResults.summary()
        • MultiPeriodDiDResults.print_summary()
        • MultiPeriodDiDResults.get_effect()
        • MultiPeriodDiDResults.to_dict()
        • MultiPeriodDiDResults.to_dataframe()
        • MultiPeriodDiDResults.is_significant
        • MultiPeriodDiDResults.significance_stars
        • MultiPeriodDiDResults.__init__()
    • PeriodEffect
      • PeriodEffect
        • PeriodEffect.period
        • PeriodEffect.effect
        • PeriodEffect.se
        • PeriodEffect.t_stat
        • PeriodEffect.p_value
        • PeriodEffect.conf_int
        • PeriodEffect.period
        • PeriodEffect.effect
        • PeriodEffect.se
        • PeriodEffect.t_stat
        • PeriodEffect.p_value
        • PeriodEffect.conf_int
        • PeriodEffect.__repr__()
        • PeriodEffect.is_significant
        • PeriodEffect.significance_stars
        • PeriodEffect.__init__()
    • SyntheticDiDResults
      • SyntheticDiDResults
        • SyntheticDiDResults.att
        • SyntheticDiDResults.se
        • SyntheticDiDResults.t_stat
        • SyntheticDiDResults.p_value
        • SyntheticDiDResults.conf_int
        • SyntheticDiDResults.n_obs
        • SyntheticDiDResults.n_treated
        • SyntheticDiDResults.n_control
        • SyntheticDiDResults.unit_weights
        • SyntheticDiDResults.time_weights
        • SyntheticDiDResults.pre_periods
        • SyntheticDiDResults.post_periods
        • SyntheticDiDResults.variance_method
        • SyntheticDiDResults.att
        • SyntheticDiDResults.se
        • SyntheticDiDResults.t_stat
        • SyntheticDiDResults.p_value
        • SyntheticDiDResults.conf_int
        • SyntheticDiDResults.n_obs
        • SyntheticDiDResults.n_treated
        • SyntheticDiDResults.n_control
        • SyntheticDiDResults.unit_weights
        • SyntheticDiDResults.time_weights
        • SyntheticDiDResults.pre_periods
        • SyntheticDiDResults.post_periods
        • SyntheticDiDResults.alpha
        • SyntheticDiDResults.variance_method
        • SyntheticDiDResults.noise_level
        • SyntheticDiDResults.zeta_omega
        • SyntheticDiDResults.zeta_lambda
        • SyntheticDiDResults.pre_treatment_fit
        • SyntheticDiDResults.placebo_effects
        • SyntheticDiDResults.n_bootstrap
        • SyntheticDiDResults.__repr__()
        • SyntheticDiDResults.summary()
        • SyntheticDiDResults.print_summary()
        • SyntheticDiDResults.to_dict()
        • SyntheticDiDResults.to_dataframe()
        • SyntheticDiDResults.get_unit_weights_df()
        • SyntheticDiDResults.get_time_weights_df()
        • SyntheticDiDResults.is_significant
        • SyntheticDiDResults.significance_stars
        • SyntheticDiDResults.__init__()
  • Visualization
    • plot_event_study
      • plot_event_study()
      • Example
    • plot_group_effects
      • plot_group_effects()
      • Example
    • plot_sensitivity
      • plot_sensitivity()
      • Example
    • plot_honest_event_study
      • plot_honest_event_study()
      • Example
  • Diagnostics
    • run_placebo_test
      • run_placebo_test()
    • placebo_timing_test
      • placebo_timing_test()
      • Example
    • placebo_group_test
      • placebo_group_test()
      • Example
    • permutation_test
      • permutation_test()
      • Example
    • leave_one_out_test
      • leave_one_out_test()
      • Example
    • run_all_placebo_tests
      • run_all_placebo_tests()
    • PlaceboTestResults
      • PlaceboTestResults
        • PlaceboTestResults.test_type
        • PlaceboTestResults.placebo_effect
        • PlaceboTestResults.se
        • PlaceboTestResults.t_stat
        • PlaceboTestResults.p_value
        • PlaceboTestResults.conf_int
        • PlaceboTestResults.n_obs
        • PlaceboTestResults.is_significant
        • PlaceboTestResults.original_effect
        • PlaceboTestResults.original_se
        • PlaceboTestResults.permutation_distribution
        • PlaceboTestResults.leave_one_out_effects
        • PlaceboTestResults.fake_period
        • PlaceboTestResults.fake_group
        • PlaceboTestResults.test_type
        • PlaceboTestResults.placebo_effect
        • PlaceboTestResults.se
        • PlaceboTestResults.t_stat
        • PlaceboTestResults.p_value
        • PlaceboTestResults.conf_int
        • PlaceboTestResults.n_obs
        • PlaceboTestResults.is_significant
        • PlaceboTestResults.alpha
        • PlaceboTestResults.original_effect
        • PlaceboTestResults.original_se
        • PlaceboTestResults.permutation_distribution
        • PlaceboTestResults.leave_one_out_effects
        • PlaceboTestResults.fake_period
        • PlaceboTestResults.fake_group
        • PlaceboTestResults.n_permutations
        • PlaceboTestResults.significance_stars
        • PlaceboTestResults.summary()
        • PlaceboTestResults.print_summary()
        • PlaceboTestResults.to_dict()
        • PlaceboTestResults.to_dataframe()
        • PlaceboTestResults.__init__()
  • Honest DiD
    • Overview
    • HonestDiD
      • HonestDiD
        • HonestDiD.__init__()
        • HonestDiD.get_params()
        • HonestDiD.set_params()
        • HonestDiD.fit()
        • HonestDiD.sensitivity_analysis()
        • HonestDiD.breakdown_value()
      • Example
    • HonestDiDResults
      • HonestDiDResults
        • HonestDiDResults.lb
        • HonestDiDResults.ub
        • HonestDiDResults.ci_lb
        • HonestDiDResults.ci_ub
        • HonestDiDResults.M
        • HonestDiDResults.method
        • HonestDiDResults.original_estimate
        • HonestDiDResults.original_se
        • HonestDiDResults.alpha
        • HonestDiDResults.ci_method
        • HonestDiDResults.original_results
        • HonestDiDResults.lb
        • HonestDiDResults.ub
        • HonestDiDResults.ci_lb
        • HonestDiDResults.ci_ub
        • HonestDiDResults.M
        • HonestDiDResults.method
        • HonestDiDResults.original_estimate
        • HonestDiDResults.original_se
        • HonestDiDResults.alpha
        • HonestDiDResults.ci_method
        • HonestDiDResults.original_results
        • HonestDiDResults.event_study_bounds
        • HonestDiDResults.is_significant
        • HonestDiDResults.significance_stars
        • HonestDiDResults.identified_set_width
        • HonestDiDResults.ci_width
        • HonestDiDResults.summary()
        • HonestDiDResults.print_summary()
        • HonestDiDResults.to_dict()
        • HonestDiDResults.to_dataframe()
        • HonestDiDResults.__init__()
    • SensitivityResults
      • SensitivityResults
        • SensitivityResults.M_values
        • SensitivityResults.bounds
        • SensitivityResults.robust_cis
        • SensitivityResults.breakdown_M
        • SensitivityResults.method
        • SensitivityResults.original_estimate
        • SensitivityResults.original_se
        • SensitivityResults.alpha
        • SensitivityResults.M_values
        • SensitivityResults.bounds
        • SensitivityResults.robust_cis
        • SensitivityResults.breakdown_M
        • SensitivityResults.method
        • SensitivityResults.original_estimate
        • SensitivityResults.original_se
        • SensitivityResults.alpha
        • SensitivityResults.has_breakdown
        • SensitivityResults.summary()
        • SensitivityResults.print_summary()
        • SensitivityResults.to_dataframe()
        • SensitivityResults.plot()
        • SensitivityResults.__init__()
    • Restriction Classes
      • DeltaSD
        • DeltaSD
      • DeltaRM
        • DeltaRM
      • DeltaSDRM
        • DeltaSDRM
    • Convenience Functions
      • compute_honest_did
        • compute_honest_did()
      • sensitivity_plot
        • sensitivity_plot()
    • Complete Example
    • References
  • Power Analysis
    • Overview
    • PowerAnalysis
      • PowerAnalysis
        • PowerAnalysis.__init__()
        • PowerAnalysis.power()
        • PowerAnalysis.mde()
        • PowerAnalysis.sample_size()
        • PowerAnalysis.power_curve()
        • PowerAnalysis.sample_size_curve()
      • Example
    • PowerResults
      • PowerResults
        • PowerResults.power
        • PowerResults.mde
        • PowerResults.required_n
        • PowerResults.effect_size
        • PowerResults.alpha
        • PowerResults.alternative
        • PowerResults.n_treated
        • PowerResults.n_control
        • PowerResults.n_pre
        • PowerResults.n_post
        • PowerResults.sigma
        • PowerResults.rho
        • PowerResults.design
        • PowerResults.power
        • PowerResults.mde
        • PowerResults.required_n
        • PowerResults.effect_size
        • PowerResults.alpha
        • PowerResults.alternative
        • PowerResults.n_treated
        • PowerResults.n_control
        • PowerResults.n_pre
        • PowerResults.n_post
        • PowerResults.sigma
        • PowerResults.rho
        • PowerResults.design
        • PowerResults.__repr__()
        • PowerResults.summary()
        • PowerResults.print_summary()
        • PowerResults.to_dict()
        • PowerResults.to_dataframe()
        • PowerResults.__init__()
    • SimulationPowerResults
      • SimulationPowerResults
        • SimulationPowerResults.power
        • SimulationPowerResults.power_se
        • SimulationPowerResults.power_ci
        • SimulationPowerResults.rejection_rate
        • SimulationPowerResults.mean_estimate
        • SimulationPowerResults.std_estimate
        • SimulationPowerResults.mean_se
        • SimulationPowerResults.coverage
        • SimulationPowerResults.n_simulations
        • SimulationPowerResults.effect_sizes
        • SimulationPowerResults.powers
        • SimulationPowerResults.true_effect
        • SimulationPowerResults.alpha
        • SimulationPowerResults.estimator_name
        • SimulationPowerResults.power
        • SimulationPowerResults.power_se
        • SimulationPowerResults.power_ci
        • SimulationPowerResults.rejection_rate
        • SimulationPowerResults.mean_estimate
        • SimulationPowerResults.std_estimate
        • SimulationPowerResults.mean_se
        • SimulationPowerResults.coverage
        • SimulationPowerResults.n_simulations
        • SimulationPowerResults.effect_sizes
        • SimulationPowerResults.powers
        • SimulationPowerResults.true_effect
        • SimulationPowerResults.alpha
        • SimulationPowerResults.estimator_name
        • SimulationPowerResults.bias
        • SimulationPowerResults.rmse
        • SimulationPowerResults.simulation_results
        • SimulationPowerResults.__post_init__()
        • SimulationPowerResults.__repr__()
        • SimulationPowerResults.summary()
        • SimulationPowerResults.print_summary()
        • SimulationPowerResults.to_dict()
        • SimulationPowerResults.to_dataframe()
        • SimulationPowerResults.power_curve_df()
        • SimulationPowerResults.__init__()
    • Convenience Functions
      • compute_power
        • compute_power()
      • compute_mde
        • compute_mde()
      • compute_sample_size
        • compute_sample_size()
      • simulate_power
        • simulate_power()
    • Complete Example
    • See Also
  • Pre-Trends Power Analysis
    • Overview
    • PreTrendsPower
      • PreTrendsPower
        • PreTrendsPower.__init__()
        • PreTrendsPower.get_params()
        • PreTrendsPower.set_params()
        • PreTrendsPower.fit()
        • PreTrendsPower.power_at()
        • PreTrendsPower.power_curve()
        • PreTrendsPower.sensitivity_to_honest_did()
      • Example
    • PreTrendsPowerResults
      • PreTrendsPowerResults
        • PreTrendsPowerResults.power
        • PreTrendsPowerResults.mdv
        • PreTrendsPowerResults.violation_magnitude
        • PreTrendsPowerResults.violation_type
        • PreTrendsPowerResults.alpha
        • PreTrendsPowerResults.target_power
        • PreTrendsPowerResults.n_pre_periods
        • PreTrendsPowerResults.test_statistic
        • PreTrendsPowerResults.critical_value
        • PreTrendsPowerResults.noncentrality
        • PreTrendsPowerResults.pre_period_effects
        • PreTrendsPowerResults.pre_period_ses
        • PreTrendsPowerResults.vcov
        • PreTrendsPowerResults.power
        • PreTrendsPowerResults.mdv
        • PreTrendsPowerResults.violation_magnitude
        • PreTrendsPowerResults.violation_type
        • PreTrendsPowerResults.alpha
        • PreTrendsPowerResults.target_power
        • PreTrendsPowerResults.n_pre_periods
        • PreTrendsPowerResults.test_statistic
        • PreTrendsPowerResults.critical_value
        • PreTrendsPowerResults.noncentrality
        • PreTrendsPowerResults.pre_period_effects
        • PreTrendsPowerResults.pre_period_ses
        • PreTrendsPowerResults.vcov
        • PreTrendsPowerResults.original_results
        • PreTrendsPowerResults.is_informative
        • PreTrendsPowerResults.power_adequate
        • PreTrendsPowerResults.summary()
        • PreTrendsPowerResults.print_summary()
        • PreTrendsPowerResults.to_dict()
        • PreTrendsPowerResults.to_dataframe()
        • PreTrendsPowerResults.power_at()
        • PreTrendsPowerResults.__init__()
    • PreTrendsPowerCurve
      • PreTrendsPowerCurve
        • PreTrendsPowerCurve.M_values
        • PreTrendsPowerCurve.powers
        • PreTrendsPowerCurve.mdv
        • PreTrendsPowerCurve.alpha
        • PreTrendsPowerCurve.target_power
        • PreTrendsPowerCurve.violation_type
        • PreTrendsPowerCurve.M_values
        • PreTrendsPowerCurve.powers
        • PreTrendsPowerCurve.mdv
        • PreTrendsPowerCurve.alpha
        • PreTrendsPowerCurve.target_power
        • PreTrendsPowerCurve.violation_type
        • PreTrendsPowerCurve.to_dataframe()
        • PreTrendsPowerCurve.plot()
        • PreTrendsPowerCurve.__init__()
    • Convenience Functions
      • compute_pretrends_power
        • compute_pretrends_power()
      • compute_mdv
        • compute_mdv()
    • Violation Types
    • Complete Example
    • References
    • See Also
  • Utilities
    • Parallel Trends Testing
      • check_parallel_trends
        • check_parallel_trends()
        • Example
      • check_parallel_trends_robust
        • check_parallel_trends_robust()
      • equivalence_test_trends
        • equivalence_test_trends()
        • Example
    • Wild Cluster Bootstrap
      • wild_bootstrap_se
        • wild_bootstrap_se()
        • Example
      • WildBootstrapResults
        • WildBootstrapResults
        • Weight Types
        • Recommendation
  • Data Preparation
    • Data Generation
      • generate_did_data
        • generate_did_data()
        • Example
    • Indicator Creation
      • make_treatment_indicator
        • make_treatment_indicator()
        • Example
      • make_post_indicator
        • make_post_indicator()
        • Example
    • Panel Data Utilities
      • wide_to_long
        • wide_to_long()
        • Example
      • balance_panel
        • balance_panel()
        • Example
    • Staggered Adoption Utilities
      • create_event_time
        • create_event_time()
        • Example
      • aggregate_to_cohorts
        • aggregate_to_cohorts()
        • Example
    • Data Validation
      • validate_did_data
        • validate_did_data()
        • Example
      • summarize_did_data
        • summarize_did_data()
        • Example
    • Control Unit Selection
      • rank_control_units
        • rank_control_units()
        • Example
diff-diff
  • API Reference
  • diff_diff.check_parallel_trends_robust
  • View page source

diff_diff.check_parallel_trends_robust

diff_diff.check_parallel_trends_robust(data, outcome, time, treatment_group, unit=None, pre_periods=None, n_permutations=1000, seed=None, wasserstein_threshold=0.2)[source]

Perform robust parallel trends testing using distributional comparisons.

Uses the Wasserstein (Earth Mover’s) distance to compare the full distribution of outcome changes between treated and control groups, with permutation-based inference.

Parameters:
  • data (pd.DataFrame) – Panel data with repeated observations over time.

  • outcome (str) – Name of outcome variable column.

  • time (str) – Name of time period column.

  • treatment_group (str) – Name of treatment group indicator column (0/1).

  • unit (str, optional) – Name of unit identifier column. If provided, computes unit-level changes. Otherwise uses observation-level data.

  • pre_periods (list, optional) – List of pre-treatment time periods. If None, uses first half of periods.

  • n_permutations (int, default=1000) – Number of permutations for computing p-value.

  • seed (int, optional) – Random seed for reproducibility.

  • wasserstein_threshold (float, default=0.2) – Threshold for normalized Wasserstein distance. Values below this threshold (combined with p > 0.05) suggest parallel trends are plausible.

Returns:

Dictionary containing: - wasserstein_distance: Wasserstein distance between group distributions - wasserstein_p_value: Permutation-based p-value - ks_statistic: Kolmogorov-Smirnov test statistic - ks_p_value: KS test p-value - mean_difference: Difference in mean changes - variance_ratio: Ratio of variances in changes - treated_changes: Array of outcome changes for treated - control_changes: Array of outcome changes for control - parallel_trends_plausible: Boolean assessment

Return type:

dict

Examples

>>> results = check_parallel_trends_robust(
...     data, outcome='sales', time='year',
...     treatment_group='treated', unit='firm_id'
... )
>>> print(f"Wasserstein distance: {results['wasserstein_distance']:.4f}")
>>> print(f"P-value: {results['wasserstein_p_value']:.4f}")

Notes

The Wasserstein distance (Earth Mover’s Distance) measures the minimum “cost” of transforming one distribution into another. Unlike simple mean comparisons, it captures differences in the entire distribution shape, making it more robust to non-normal data and heterogeneous effects.

A small Wasserstein distance and high p-value suggest the distributions of pre-treatment changes are similar, supporting the parallel trends assumption.

Previous Next

© Copyright 2026, diff-diff contributors.

Built with Sphinx using a theme provided by Read the Docs.