diff_diff.run_placebo_test#
- diff_diff.run_placebo_test(data, outcome, treatment, time, unit=None, test_type='fake_timing', fake_treatment_period=None, fake_treatment_group=None, post_periods=None, n_permutations=1000, alpha=0.05, seed=None, **estimator_kwargs)[source]
Run a placebo test to validate DiD assumptions.
Placebo tests provide evidence on the validity of the parallel trends assumption by testing whether “fake” treatments produce significant effects. A significant placebo effect suggests the parallel trends assumption may be violated.
- Parameters:
data (pd.DataFrame) – Panel data for DiD analysis.
outcome (str) – Name of outcome variable column.
treatment (str) – Name of treatment indicator column (0/1).
time (str) – Name of time period column.
unit (str, optional) – Name of unit identifier column. Required for some test types.
test_type (str, default="fake_timing") – Type of placebo test: - “fake_timing”: Assign treatment at a fake (earlier) time period - “fake_group”: Run DiD designating some control units as “fake treated” - “permutation”: Randomly reassign treatment and compute distribution - “leave_one_out”: Drop each treated unit and re-estimate
fake_treatment_period (any, optional) – For “fake_timing”: The fake treatment period to test. Should be a pre-treatment period.
fake_treatment_group (list, optional) – For “fake_group”: List of control unit IDs to designate as fake treated.
post_periods (list, optional) – List of post-treatment periods. Required for fake_timing test.
n_permutations (int, default=1000) – For “permutation”: Number of random treatment assignments.
alpha (float, default=0.05) – Significance level.
seed (int, optional) – Random seed for reproducibility.
**estimator_kwargs – Additional arguments passed to the DiD estimator.
- Returns:
Object containing placebo effect estimates, p-values, and diagnostics.
- Return type:
Examples
Fake timing test:
>>> results = run_placebo_test( ... data, outcome='sales', treatment='treated', time='period', ... test_type='fake_timing', ... fake_treatment_period=1, # Pre-treatment period ... post_periods=[2, 3, 4] ... ) >>> if results.is_significant: ... print("Warning: Pre-treatment differential trends detected!")
Permutation test:
>>> results = run_placebo_test( ... data, outcome='sales', treatment='treated', time='period', ... unit='unit_id', ... test_type='permutation', ... n_permutations=1000, ... seed=42 ... ) >>> print(f"Permutation p-value: {results.p_value:.4f}")
References
Bertrand, M., Duflo, E., & Mullainathan, S. (2004). How Much Should We Trust Differences-in-Differences Estimates? The Quarterly Journal of Economics, 119(1), 249-275.