Difference-in-Differences (DiD) Analysis
Estimate the effect of a policy or intervention by comparing the change in a treated group with the change in a control group. You get the 2×2 means table, the DiD regression, a two-way fixed effects estimate and an event study that checks for parallel pre-trends.
Updated · By Bibin XavierData 640 × 5
| Storetext · 80 levels | Yearnumeric | Treatednumeric · coded | Salesnumeric | Store_Sizenumeric |
|---|---|---|---|---|
| S01 | 2016 | 1 | 72.7 | 1796 |
| S01 | 2017 | 1 | 67.5 | 1796 |
| S01 | 2018 | 1 | 73.9 | 1796 |
| S01 | 2019 | 1 | 71.1 | 1796 |
| S01 | 2020 | 1 | 78.8 | 1796 |
| S01 | 2021 | 1 | 81.8 | 1796 |
| S01 | 2022 | 1 | 80.6 | 1796 |
| S01 | 2023 | 1 | 86 | 1796 |
Variables and options
Results
640 rows · example dataDifference-in-differences: group means
| Group | Before | After | Change |
|---|---|---|---|
| Treated | 61.355 (n = 160) | 73.467 (n = 160) | 12.112 |
| Control | 57.401 (n = 160) | 63.691 (n = 160) | 6.291 |
| Difference | 3.954 | 9.776 | 5.821 |
DiD regression (Clustered by unit (80 clusters) standard errors)
| Variable | Coefficient | SE | t | p | 95% CI |
|---|---|---|---|---|---|
| Constant | 57.4006 | 1.0975 | 52.299 | < .001 | [55.2160, 59.5852] |
| Treated | 3.9544 | 1.3946 | 2.835 | .006 | [1.1784, 6.7303] |
| Post | 6.2906 | 0.2329 | 27.006 | < .001 | [5.8270, 6.7543] |
| Treated × Post (DiD) | 5.8212 | 0.3203 | 18.172 | < .001 | [5.1836, 6.4589] |
Two-way fixed effects (unit and time fixed effects)
| Estimate | Coefficient | SE | t | p | 95% CI |
|---|---|---|---|---|---|
| Treatment effect (ATT) | 5.8212 | 0.3213 | 18.115 | < .001 | [5.1816, 6.4609] |
Note. Clustered by unit. With treatment starting at the same time for all treated units, TWFE equals the canonical DiD; with staggered adoption it can be biased (Goodman-Bacon, 2021).
Outcome over time by group
Event study: effect relative to the period before treatment
Event-study coefficients
| Relative period | Coefficient | SE | p | 95% CI |
|---|---|---|---|---|
| -4 | -0.055 | 0.753 | .942 | [-1.554, 1.444] |
| -3 | -0.535 | 0.738 | .470 | [-2.003, 0.933] |
| -2 | -0.042 | 0.736 | .954 | [-1.508, 1.423] |
| 0 | 4.445 | 0.682 | < .001 | [3.088, 5.802] |
| 1 | 4.120 | 0.691 | < .001 | [2.744, 5.496] |
| 2 | 6.888 | 0.696 | < .001 | [5.503, 8.272] |
| 3 | 7.200 | 0.652 | < .001 | [5.901, 8.499] |
Note. Joint test that all pre-treatment coefficients are zero: F(3, 79) = 0.249, p = .861. Reference period: −1.
Interpretation
After treatment, the outcome of the treated group changed by 5.82 more than that of the control group (95% CI [5.18, 6.46]), which is statistically significant. The pre-treatment coefficients are jointly insignificant, consistent with parallel trends.
How to cite this tool
Using these results in a thesis, journal article, report or class assignment? Please cite this free tool so others can find it. It keeps the site free.
APA 7
Xavier, B. (2026). Difference-in-Differences (DiD) Analysis [Web application]. FreeStatisticalTools.com. https://freestatisticaltools.com/difference-in-differences-calculator/
BibTeX
@software{xavier_differenceindifferences_2026,
author = {Xavier, Bibin},
title = {Difference-in-Differences (DiD) Analysis},
publisher = {FreeStatisticalTools.com},
year = {2026},
url = {https://freestatisticaltools.com/difference-in-differences-calculator/},
note = {Web application}
}Suggested sentence for your methods section: “The analysis was carried out with the free Difference-in-Differences (DiD) Analysis tool on FreeStatisticalTools.com (Xavier, 2026).”
What is difference-in-differences?
Difference-in-differences estimates a causal effect by comparing how an outcome changed for a group exposed to a treatment with how it changed for an unexposed group. The comparison removes stable differences between groups and common shocks over time.
When to use difference-in-differences
Use DiD to evaluate a policy, programme or event that affected some units and not others, when you observe both groups before and after.
Assumptions
- Parallel trends: without treatment, both groups would have followed the same path (check the event study).
- No anticipation and no spill-overs to the control group.
- Treatment starts at the same time for all treated units in this tool; staggered adoption needs dedicated estimators.
How to set up your data
Long format: one row per unit and period with the outcome, a 0/1 treated-group indicator, the time variable and optionally a unit identifier.
How to use this tool
- Enter your data. Paste columns from Excel, Google Sheets or SPSS with variable names in the first row, or upload a CSV or Excel file. The example data shows the expected layout.
- Choose the variables. Select the outcome, treatment group indicator, value for the treated group and time variable.
- Set the options. Fill in first treated period.
- Read the results. Results update automatically. Read the plain-English interpretation, then use Copy table to paste APA-style tables into Word and Copy for the results sentence.
How to report difference-in-differences in APA style
Report the DiD estimate with clustered standard errors, the group means, and the event-study plot with the pre-trend test.
Frequently asked questions
What is the parallel trends assumption?
That without the treatment, the treated and control groups would have followed the same trend. Pre-treatment event-study coefficients close to zero support it.
How do I interpret the interaction coefficient?
The Treated × Post coefficient is the DiD estimate: the extra change in the outcome for the treated group after treatment.
What if units are treated at different times?
Staggered adoption can bias two-way fixed effects. Use estimators designed for it, such as Callaway and Sant’Anna (2021).
Related tools
Learn this method step by step in the free course Customer and Marketing Analytics, with exercises and a certificate.
Browse all categories
Data cleaning and preparation · Describe and explore · Compare means · Nonparametric tests · Correlation and regression · Bayesian statistics · Categorical data · Reliability and agreement · Multivariate analysis · Structural equation modeling · Econometrics and time series · Panel data and causal inference · Marketing research · Marketing analytics · Survival, clinical and meta-analysis · Study planning and calculators · PLS-SEM