Tools › Statistics › Regression and Modeling › Difference-in-Differences and ITS › Method
Difference-in-Differences and ITS: Method
Open the free Difference-in-Differences and ITS Calculator
The tool estimates how much an outcome moved after a change (a program, a policy, a price, a rule) beyond what it would have done anyway. With a comparison group it uses difference-in-differences; with one long series and no comparison group it uses the segmented regression of an interrupted time series. Both report a statistical association under an assumption about what would have happened without the change; neither establishes cause.
The idea of difference-in-differences
Two groups are observed before and after. One group is reached by the change (the treated group), the other is not (the comparison group). The comparison group's before-to-after change stands in for what the treated group would have done without the change. The estimate is the treated group's change minus the comparison group's change.

| Quantity | Formula | Note |
|---|---|---|
| Estimate from four means | (Tafter − Tbefore) − (Cafter − Cbefore) | T treated, C comparison |
| Counterfactual | Tbefore + (Cafter − Cbefore) | the treated group after the change under parallel trends |
| Regression | y = b0 + b1 D + b2 P + b3 D P + covariates | D = 1 for a treated unit, P = 1 from the first treated period on; b3 is the estimate |
| Classical variance | s² (X′X)−1, s² = SSE ÷ (N − k) | t with N − k degrees of freedom |
| HC1 variance | N/(N − k) × (X′X)−1 [Σ ei² xi xi′] (X′X)−1 | allows unequal variance; t with N − k |
| Cluster-robust variance (CR1) | G/(G − 1) × (N − 1)/(N − k) × (X′X)−1 [Σg sg sg′] (X′X)−1, sg = Σ xi ei over the rows of unit g | allows the rows of one unit to be correlated; t with G − 1, G = number of units |
| Summary, unequal variances | SE = √(Σ s²/n over the four cells) | Satterthwaite degrees of freedom (Σ v)² ÷ Σ v²/(n − 1), v = s²/n |
| Summary, pooled variance | SE = sp √(Σ 1/n), sp² = Σ (n − 1)s² ÷ (N − 4) | equals the classical regression error |
Why three standard errors. When the same units are followed over several periods, a unit that is high in one period tends to be high in the next. The rows then carry less independent information than their number suggests, and classical and HC1 errors, which count every row as independent, can be much too small. Errors clustered by unit allow for that. The tool prints all three so the difference can be seen; in a balanced design with four equal cells and no covariates the classical and HC1 errors are the same number.
Event study. With three or more periods the tool also fits a regression with a dummy for every period, the group dummy, and the group dummy times every period except the last one before the change. Each of those interaction coefficients is the gap between the groups in that period less the gap in the reference period. The gaps after the change show how the estimate builds up; the gaps before it are a check. A joint Wald test (reported as F with q and the residual or G − 1 degrees of freedom) asks whether the before-gaps are all zero.
The idea of an interrupted time series
One series is observed many times before and after a change at a known time T0. A straight line is fitted to each side. The line before the change, carried forward, is the counterfactual.

| Quantity | Formula | Note |
|---|---|---|
| Segmented regression | yt = b0 + b1(t − T0) + b2 Xt + b3 Xt(t − T0) | Xt = 1 from T0 on; b1 slope before, b2 level change, b3 slope change |
| Change at time t after T0 | b2 + b3(t − T0) | the average over the after-observations is also reported |
| Seasonal terms (optional) | sin(2π j i/s), cos(2π j i/s), j = 1 or 1 and 2 | i counts observations, s is the seasonal period |
| Newey-West variance | n/(n − k) × (X′X)−1 [Γ0 + Σj=1..L (1 − j/(L + 1))(Γj + Γj′)] (X′X)−1, Γj = Σ et et−j xt xt−j′ | Bartlett weights; t with n − k degrees of freedom |
| Lag when none is entered | L = whole part of 4 (n/100)2/9 | a common rule of thumb; 3 for n = 48, 4 for n = 100 |
| Durbin-Watson | Σ (et − et−1)² ÷ Σ et² | about 2(1 − r1) |
| Ljung-Box | Q = n(n + 2) Σ rj²/(n − j) | chi-square with as many degrees of freedom as lags; approximate for residuals |
Time is counted from T0, so that b2 is the jump exactly at the intervention time. Bernal, Cummins and Gasparrini (2017) write the same model for a public-health series and describe the three impact models offered here (level, slope, level and slope), seasonal adjustment by sine and cosine pairs, and the check of residual autocorrelation. Their example uses Poisson regression for a count; this tool fits the linear model only. With a control series, the tool fits the same regression to the outcome minus the control.
What it assumes
- Difference-in-differences: parallel trends. Without the change, the treated group would have moved as the comparison group did. The groups may differ in level; they may not differ in trend.
- Interrupted time series: the trend continues. Without the change, the series would have stayed on the straight line fitted to the before-period (plus the seasonal terms, if used).
- Nothing else reached the treated group (or the series) at about the same time, and the make-up of the groups did not change.
- One starting date for every treated unit. Units treated at different times are outside this tool.
- Intervals and p-values use the t distribution; with few units or a short series they are rough.
When it misleads
- Groups already drifting apart. A gap that was growing before the change keeps growing after it, and the estimate reads that drift as an effect. The event study shows it when there are several before-periods.
- Few units. Cluster-robust errors are estimated from the number of units, not rows. With a handful of units they are imprecise, and with one treated unit they mean little.
- Regression to the mean. Units chosen for the program because of an unusually bad period tend to improve without it.
- A before-period that is short or unusual. The continued trend of an interrupted time series is then a poor guide, and a small error in the slope becomes a large error far from T0.
- Seasonality left out. A change made at a seasonal turn is confounded with the season.
- Outcomes with a floor or ceiling, percentages near 0 or 100 and small counts do not follow straight lines.
Common mistakes
- Comparing only after with before in the treated group, or only treated with comparison after the change. Each is one difference; the method needs both.
- Marking a treated unit 0 before the change and 1 after it. The treated column says which group a unit belongs to and is the same in every period; the page builds "after" from the period column.
- Reading the p-value from classical errors when units are followed over time.
- Reading a pre-trend test that does not reject as proof of parallel trends.
- In an interrupted time series, counting time from the start of the series in the interaction term, so that the coefficient of "after" is the gap at time zero rather than at the intervention.
- Entering the standard error of each mean where the 2 × 2 form asks for the standard deviation of the observations.
- Calling the estimate "the effect" without stating the assumption it rests on.
Related tools
Regression and Curve Fitting fits a general model to x and y; Hypothesis Tests and the A/B Test compare two groups at one time; Energy Baseline Regression compares a building with its own weather-adjusted baseline. This tool adds the two-group, two-period comparison with clustered errors and the event study, and the segmented regression of one series with Newey-West errors.
The tool's test checks every coefficient, standard error, p-value and interval of its cases and of 48 seeded data sets against an independent numpy and scipy computation, the two-by-two arithmetic against the employment means printed in Table 3 of Card and Krueger (1994), and the segmented regression on the public data set of Bernal, Cummins and Gasparrini (2017), whose own estimate is a Poisson rate ratio that the linear model on the logarithm of the rate comes close to and does not reproduce.
References
Bernal, J. L., Cummins, S., and Gasparrini, A. (2017). "Interrupted Time Series Regression for the Evaluation of Public Health Interventions: A Tutorial." International Journal of Epidemiology, Vol. 46, No. 1, pp. 348–355.
Card, D., and Krueger, A. B. (1994). "Minimum Wages and Employment: A Case Study of the Fast-Food Industry in New Jersey and Pennsylvania." American Economic Review, Vol. 84, No. 4, pp. 772–793.
Newey, W. K., and West, K. D. (1987). "A Simple, Positive Semi-Definite, Heteroskedasticity and Autocorrelation Consistent Covariance Matrix." Econometrica, Vol. 55, No. 3, pp. 703–708.