Conditional Extrapolation Pre-Test for Difference-in-Differences
pretest implements the conditional extrapolation pre-test framework for
difference-in-differences (DID) designs proposed by Mikhaeil and Harshaw (2025).
Conventional pre-tests for parallel trends suffer from a fundamental limitation: failing to reject the null hypothesis is uninformative, as the test may simply lack power. Moreover, conditioning on passing such tests can lead to severe inference distortions (Roth, 2022). This package provides a principled solution.
Under the conditional extrapolation assumption, if pre-treatment violations fall below an acceptable threshold M, extrapolation to post-treatment is justified:
Assumption 3 (Conditional Extrapolation): If S pre ≤ M, then S post ≤ S pre .
The package provides:
- An asymptotically consistent pre-test for the extrapolation condition
- Conditionally valid confidence intervals for the Average Treatment Effect on the Treated (ATT) with guaranteed asymptotic coverage
Before using this package, ensure your data meets the following requirements:
| Requirement | Description |
|---|---|
| Minimum 3 time periods | T pre ≥ 2. At least two pre-treatment periods are required because iterative violations ν̂t are only defined for t ≥ 2. |
| Block adoption design | All treated units must receive treatment at the same timet 0 . Staggered adoption designs are not supported. |
| Binary treatment | Treatment indicator must be coded as 0 (control) or 1 (treated). |
| Complete time-group cells | Each time period must contain observations in both treatment and control groups. |
When some time periods lack observations for either group, the covariance matrix cannot be computed. In such cases:
e(phi)= . (missing, indicating data issue)e(data_valid)= 0e(S_pre),e(f_alpha),e(ci_lower),e(ci_upper)will be missing (.)
Common causes:
- Missing values in treatment or outcome variables creating empty cells
- Survey data with irregular interview schedules
- Sample restrictions that eliminate entire time periods for one group
Solution: Ensure at least one observation per time-treatment cell, or restrict analysis to time periods with complete coverage.
This command cannot be used for canonical 2×2 DID designs with only two time periods.
net install pretest, from("https://raw.githubusercontent.com/gorgeousfish/pretest/main") replaceThis package will be available on the SSC archive in the near future.
* Load the included example data (California Proposition 99)
webuse set "https://raw.githubusercontent.com/gorgeousfish/pretest/main/"
webuse prop99_smoking.dta, clear
* Set panel structure
xtset state year
* Run pre-test with threshold M = 5
pretest cigsale, treatment(treated) time(year) treat_time(1989) threshold(5)
* Or use overall mode (less conservative)
pretest cigsale, treatment(treated) time(year) treat_time(1989) threshold(5) overallpretest depvar , treatment(varname) time(varname) threshold(#) [options]| Option | Description |
|---|---|
treatment(varname) |
Binary treatment indicator (0/1) |
time(varname) |
Time variable |
threshold(#) |
Acceptable violation thresholdM > 0 |
| Option | Default | Description |
|---|---|---|
treat_time(#) |
auto | Treatment timet 0 |
p(#) |
2 | Severity normp ≥ 1 |
alpha(#) |
0.05 | Significance level |
level(#) |
95 | Confidence level (%) |
cluster(varname) |
— | Cluster variable for robust SE |
overall |
off | Use overall violations mode |
nograph |
off | Suppress event study graph |
simulate(#) |
5000 | Monte Carlo simulations |
seed(#) |
12345 | Random seed |
diagnose |
off | Display detailed diagnostic information |
| Option | Description |
|---|---|
ci_opt_pass(string) |
Override CI style when pretest passes |
ci_opt_fail(string) |
Override CI style when pretest fails |
line_opt_m(string) |
Override threshold M line style |
marker_opt_pre(string) |
Override pre-treatment marker style |
marker_opt_post(string) |
Override post-treatment marker style |
scheme(), title(), etc. |
Any standard Stata twoway_options |
Note: Element-specific options (e.g., ci_opt_pass) completely replace default styling when specified.
The pre-test indicator is defined as:
φ = 𝟙{Ŝ pre > M}
where φ = 0 indicates PASS (extrapolation justified) and φ = 1 indicates FAIL (extrapolation rejected).
Important: The δ̄̂ reported by this package is not the traditional ATT.
The DID estimand at time t is defined relative to the treatment time t 0 :
δ̂t = (Ȳ t,D=1 − Ȳ t₀,D=1 ) − (Ȳ t,D=0 − Ȳ t₀,D=0 )
where Ȳ t,D=d denotes the sample mean of outcomes for group D = d at time t.
The average DID estimand across post-treatment periods is:
δ̄̂ = (1/Tpost) × Σt=t₀T δ̂t
Key differences from traditional DID:
| Aspect | Paper's δ̄̂ | Traditional ATT |
|---|---|---|
| Reference point | Treatment timet 0 | Pre-treatment average |
| δ̂t₀ | Always 0 (by construction) | N/A |
| Interpretation | Incremental change fromt 0 | Total treatment effect |
Example: If treatment effect is constant at 2.0 per period:
- Traditional ATT ≈ 2.0 (total effect)
- Paper's δ̄̂ ≈ 0 (no incremental change after t₀)
Why this definition? The paper's δ̄̂ is designed for the conditional extrapolation framework, where:
- The CI bounds account for potential bias via κ · Ŝ_pre
- The interpretation is: "treatment effect relative to treatment onset"
For traditional ATT comparison, use e(ci_conv_lower) and e(ci_conv_upper).
1. Iterative mode (Default):
I = δ̄̂ ± {κ · Ŝ pre + f(α, Σ̂) / √n}
Bias bound includes the multiplier κ ≥ 1.
2. Overall mode:
IΔ = δ̄̂ ± {ŜΔpre + fΔ(α, Σ̂Δ) / √n}
Bias bound uses no multiplier (κ = 1).
κ = ((1/Tpost) · Σt=1Tpost tq)1/q
where q is the Hölder conjugate of p. κ captures the worst-case accumulation of iterative violations over time.
- For T post > 1, κ > 1.
- For p = 2 and large T post , κ grows with √T post .
- Overall Mode: κ is not used (effectively κ = 1), yielding narrower intervals.
| Result | Description |
|---|---|
e(S_pre) |
Estimated pre-treatment severity |
e(S_pre_se) |
Standard error of S_pre (Delta method) |
e(kappa) |
Bias bound constant κ (iterative mode) |
e(phi) |
Pre-test result (0 = pass, 1 = fail, . = data issue or invalid) |
e(data_valid) |
Data validity indicator |
e(pretest_pass) |
Pre-test pass indicator |
e(delta_bar) |
Average DID estimate |
e(se_delta_bar) |
Standard error of average DID estimate |
e(ci_lower) |
Conditional CI lower bound |
e(ci_upper) |
Conditional CI upper bound |
e(T) |
Total time periods |
e(T_pre) |
Pre-treatment periods |
e(T_post) |
Post-treatment periods |
e(N) |
Number of observations |
| Result | Description |
|---|---|
e(nu) |
Iterative violations (T pre −1 × 1) |
e(delta) |
DID estimates (T post × 1) |
e(theta) |
Full parameter vector θ̂ |
e(Sigma) |
Asymptotic covariance matrix |
e(b) |
Coefficient vector |
e(V) |
Variance matrix |
The package offers two assumptions about parallel trend violations, which have different sensitivities:
| Feature | Iterative Mode (Default) | Overall Mode (overall) |
|---|---|---|
| Assumption | Violations accumulate period-to-period | Violations are bounded by cumulative total |
| Sensitivity | Sensitive tovolatility/noise (sharp changes) | Sensitive todrift/trend (long-term divergence) |
| Blind Spot | May pass smooth linear trends (constant small changes) | May fail even if period-to-period changes are small |
| Bias Bound | Scaled by κ (proportional to √T post ) | No multiplier (κ = 1) |
| CI Width | Generally Wider (accounts for worst-case accumulation) | Generally Narrower (assumes bounded total error) |
Recommendation:
- Start with Iterative Mode as it is the standard, robust approach.
- Check Overall Mode if:
- You suspect a linear trend or long-term drift (Iterative might incorrectly pass).
- The Iterative results are too conservative (wide CIs) despite visually decent parallel trends.
- If Iterative PASSES but Overall FAILS: This strongly suggests the presence of a smooth linear trend difference between groups. Extrapolation is risky unless you conceptually allow for this drift to continue.
* Simulated panel data
clear
set seed 12345
set obs 500
gen id = ceil(_n/10)
gen time = mod(_n-1, 10) + 1
gen treat = (id <= 25)
gen y = rnormal() + treat*(time >= 6)*0.5The development team is evaluating the following extensions for future versions:
- Triple Difference-in-Differences (DDD): Extending the conditional extrapolation framework to DDD designs with an additional grouping dimension.
- Staggered Adoption Support: Extending the conditional extrapolation framework to staggered treatment adoption designs via cohort stacking.
- Covariate Adjustment: Adding support for control variables in the estimation.
-
Threshold Sensitivity Analysis: Visualizing how the Conditional CI varies across a continuous range of
$M$ values.
Mikhaeil, J. M., & Harshaw, C. (2025). In Defense of the Pre-Test: Valid Inference When Testing Violations of Parallel Trends for Difference-in-Differences. arXiv preprint arXiv:2510.26470. Available at: https://arxiv.org/abs/2510.26470
Rambachan, A., & Roth, J. (2023). A More Credible Approach to Parallel Trends. Review of Economic Studies, 90(5), 2555–2591. https://doi.org/10.1093/restud/rdad018
Roth, J. (2022). Pretest with Caution: Event-Study Estimates after Testing for Parallel Trends. American Economic Review: Insights, 4(3), 305–322. https://doi.org/10.1257/aeri.20210236
Stata Implementation:
- Xuanyu Cai, City University of MacauEmail: xuanyuCAI@outlook.com
- Wenli Xu, City University of Macau Email: wlxu@cityu.edu.mo
Methodology:
- Jonas M. Mikhaeil, Department of Statistics, Columbia University
- Christopher Harshaw, Department of Statistics, Columbia University
AGPL-3.0. See LICENSE for details.
If you use this package in your research, please cite both the methodology paper and the Stata implementation:
APA Format:
Cai, X., & Xu, W. (2025). pretest: Stata module to implement the conditional extrapolation pre-test for difference-in-differences (Version 0.1.0) [Computer software]. GitHub. https://github.com/gorgeousfish/pretest
Mikhaeil, J. M., & Harshaw, C. (2025). In Defense of the Pre-Test: Valid Inference when Testing Violations of Parallel Trends for Difference-in-Differences. arXiv preprint arXiv:2510.26470. https://arxiv.org/abs/2510.26470
BibTeX:
@software{pretest2025stata,
title={pretest: Stata module to implement the conditional extrapolation pre-test for difference-in-differences},
author={Xuanyu Cai and Wenli Xu},
year={2025},
version={0.1.0},
url={https://github.com/gorgeousfish/pretest}
}
@misc{mikhaeil2025defensepretestvalidinference,
title={In Defense of the Pre-Test: Valid Inference when Testing Violations
of Parallel Trends for Difference-in-Differences},
author={Jonas M. Mikhaeil and Christopher Harshaw},
year={2025},
eprint={2510.26470},
archivePrefix={arXiv},
primaryClass={stat.ME},
url={https://arxiv.org/abs/2510.26470}
}For beginners in causal inference and econometrics:
- Causal Inference for the Brave and True - An excellent introductory tutorial on causal inference by Matheus Facure
- Causal Inference for the Brave and True (Chinese Edition) - Chinese translation by Wenzhe Huang and Wenli Xu
