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 proportion of permuted estimates at least as extreme as the original.
- 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
The permutation test is exact and does not rely on asymptotic approximations, making it valid with any sample size.