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), where count is the number of permuted estimates at least as extreme as the observed and B is the number of valid permutations. With B sampled permutations this is a Monte-Carlo approximation that converges to the exact full-enumeration value count / total as B grows.

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:

PlaceboTestResults

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 +1 adds the observed assignment and prevents a zero p-value. Here count is the number of permutations at least as extreme as the observed estimate and B is the number of valid permutations. As B grows 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.