diff_diff.permutation_test#
- diff_diff.permutation_test(data, outcome, treatment, time, unit, n_permutations=1000, alpha=0.05, seed=None, **estimator_kwargs)[source]
Compute permutation-based p-value for DiD estimate.
Randomly reassigns treatment status at the unit level and computes the DiD estimate for each permutation. The p-value is the randomization-inference value
(1 + count) / (B + 1)(Phipson & Smyth 2010), wherecountis the number of permuted estimates at least as extreme as the observed andBis the number of valid permutations. WithBsampled permutations this is a Monte-Carlo approximation that converges to the exact full-enumeration valuecount / totalasBgrows.- Parameters:
data (pd.DataFrame) – Panel data.
outcome (str) – Outcome variable column.
treatment (str) – Treatment indicator column.
time (str) – Time period column.
unit (str) – Unit identifier column.
n_permutations (int, default=1000) – Number of random permutations.
alpha (float, default=0.05) – Significance level.
seed (int, optional) – Random seed for reproducibility.
**estimator_kwargs – Arguments passed to DifferenceInDifferences.
- Returns:
Results with permutation distribution and p-value.
- Return type:
Notes
This is a randomization-inference (permutation) test of the sharp null of no effect for any unit; it does not rely on asymptotic approximations. Treatment assignments are drawn independently each iteration (Monte-Carlo sampling with replacement from the assignment space), so the reported p-value
(1 + count) / (B + 1)(Phipson & Smyth 2010) is a valid but slightly conservative estimator – the+1adds the observed assignment and prevents a zero p-value. Herecountis the number of permutations at least as extreme as the observed estimate andBis the number of valid permutations. AsBgrows it converges to the exact p-value obtained by full enumeration of all assignments (the R-parity reference). “Exact” is reserved for that full enumeration; the sampled value approximates it.