# Difference in differences

Difference in differences (sometimes abbreviated DID[1] or DD[2]) is a statistical technique used in econometrics and quantitative research in the social sciences that attempts to mimic an experimental research design using observational study data, by studying the differential effect of a treatment on a 'treatment group' versus a 'control group' in a natural experiment.[3] It calculates the effect of a treatment (i.e., an explanatory variable or an independent variable) on an outcome (i.e., a response variable or dependent variable) by comparing the average change over time in the outcome variable for the treatment group, compared to the average change over time for the control group. Although it is intended to mitigate the effects of extraneous factors and selection bias, depending on how the treatment group is chosen, this method may still be subject to certain biases (e.g. mean regression, reverse causality and omitted variable bias).

In contrast to a time-series estimate of the treatment effect on subjects (which analyzes differences over time) or a cross-section estimate of the treatment effect (which measures the difference between treatment and control groups), difference in differences uses panel data to measure the differences, between the treatment and control group, of the changes in the outcome variable that occur over time.

## General definition

Difference in differences requires data measured from a treatment group and a control group at two or more different time periods, specifically at least one time period before "treatment" and at least one time period after "treatment." In the example pictured, the outcome in the treatment group is represented by the line P and the outcome in the control group is represented by the line S. The outcome (dependent) variable in both groups are measured at time period 1, before either group has received the treatment (i.e., the independent or explanatory variable), represented by the points P1 and S1. The treatment group then receives or experiences the treatment and both groups are again measured at time period 2. Not all of the difference between the treatment and control groups at time period 2 (that is, the difference between P2 and S2) can be explained as being an effect of the treatment, because the treatment group and control group did not start out at the same point at time period 1. DID therefore calculates the "normal" difference in the outcome variable between the two groups (the difference that would still exist if neither group experienced the treatment), represented by the dotted line Q. (Notice that the slope from P1 to Q is the same as the slope from S1 to S2.) The treatment effect is the difference between the observed outcome and the "normal" outcome (the difference between P2 and Q).

## Formal definition

Consider the model

${\displaystyle y_{ist}~=~\gamma _{s}+\lambda _{t}+\delta D_{st}+\epsilon _{ist}}$

where ${\displaystyle y_{ist}}$ is the dependent variable for individual ${\displaystyle i}$, given ${\displaystyle s}$ and ${\displaystyle t}$. The dimensions ${\displaystyle s}$ and ${\displaystyle t}$ may for example be country and time. ${\displaystyle \gamma _{s}}$ and ${\displaystyle \lambda _{t}}$ is then the vertical intercept for ${\displaystyle s}$ and ${\displaystyle t}$ respectively. ${\displaystyle D_{st}}$ is a dummy variable indicating treatment status, ${\displaystyle \delta }$ is the treatment effect, and ${\displaystyle \epsilon _{ist}}$ is an error term.

Let

${\displaystyle {\overline {y}}_{st}~=~{\frac {1}{n}}\sum _{i=1}^{n}y_{ist}}$,

${\displaystyle {\overline {\gamma }}_{s}~=~{\frac {1}{n}}\sum _{i=1}^{n}\gamma _{s}~=~\gamma _{s}}$,

${\displaystyle {\overline {\lambda }}_{t}~=~{\frac {1}{n}}\sum _{i=1}^{n}\lambda _{t}~=~\lambda _{t}}$,

${\displaystyle {\overline {D}}_{st}~=~{\frac {1}{n}}\sum _{i=1}^{n}D_{st}~=~D_{st}}$,

${\displaystyle {\overline {\epsilon }}_{st}~=~{\frac {1}{n}}\sum _{i=1}^{n}\epsilon _{ist}}$,

and suppose for simplicity that ${\displaystyle s=1,2}$ and ${\displaystyle t=1,2}$. Then

${\displaystyle ({\overline {y}}_{11}-{\overline {y}}_{12})-({\overline {y}}_{21}-{\overline {y}}_{22})}$

${\displaystyle =\left[(\gamma _{1}+\lambda _{1}+\delta D_{11}+{\overline {\epsilon }}_{11})-(\gamma _{1}+\lambda _{2}+\delta D_{12}+{\overline {\epsilon }}_{12})\right]-\left[(\gamma _{2}+\lambda _{1}+\delta D_{21}+{\overline {\epsilon }}_{21})-(\gamma _{2}+\lambda _{2}+\delta D_{22}+{\overline {\epsilon }}_{22})\right]}$

${\displaystyle =\delta (D_{11}-D_{12})+\delta (D_{22}-D_{21})+{\overline {\epsilon }}_{11}-{\overline {\epsilon }}_{12}+{\overline {\epsilon }}_{22}-{\overline {\epsilon }}_{21}}$.

The strict exogeneity assumption then implies that

${\displaystyle E\left[({\overline {y}}_{11}-{\overline {y}}_{12})-({\overline {y}}_{21}-{\overline {y}}_{22})\right]~=~\delta (D_{11}-D_{12})+\delta (D_{22}-D_{21})}$.

Without loss of generality, assume that ${\displaystyle D_{22}=1}$ and ${\displaystyle D_{11}=D_{12}=D_{21}=0}$, giving the DID estimator

${\displaystyle {\hat {\delta }}~=~({\overline {y}}_{11}-{\overline {y}}_{12})-({\overline {y}}_{21}-{\overline {y}}_{22})}$,

which can be interpreted as the treatment effect of the treatment indicated by ${\displaystyle D_{st}}$.

## Assumptions

Illustration of the parallel trend assumption

All the assumptions of the OLS model apply equally to DID. In addition, DID requires a parallel trend assumption. The parallel trend assumption says that ${\displaystyle \lambda _{2}-\lambda _{1}}$ are the same in both ${\displaystyle s=1}$ and ${\displaystyle s=2}$. Given that the formal definition above accurately represents reality, this assumption automatically holds. However, a model with ${\displaystyle \lambda _{st}~:~\lambda _{22}-\lambda _{21}\neq \lambda _{12}-\lambda _{11}}$ may well be more realistic.

As illustrated to the right, the treatment effect is the difference between the observed value of y and what the value of y would have been with parallel trends, had there been no treatment. The Achilles' heel of DID is when something other than the treatment changes in one group but not the other at the same time as the treatment, implying a violation of the parallel trend assumption.

To guarantee the accuracy of the DID estimate, the composition of individuals of the two groups is assumed to remain unchanged over time. When using a DID model, various issues that may compromise the results, such as autocorrelation and Ashenfelter dips, must be considered and dealt with.

## Implementation

The DID method can be implemented according to the table below, where the lower right cell is the DID estimator.

${\displaystyle y_{st}}$ ${\displaystyle s=2}$ ${\displaystyle s=1}$ Difference
${\displaystyle t=2}$ ${\displaystyle y_{22}}$ ${\displaystyle y_{12}}$ ${\displaystyle y_{12}-y_{22}}$
${\displaystyle t=1}$ ${\displaystyle y_{21}}$ ${\displaystyle y_{11}}$ ${\displaystyle y_{11}-y_{21}}$
Change ${\displaystyle y_{21}-y_{22}}$ ${\displaystyle y_{11}-y_{12}}$ ${\displaystyle (y_{11}-y_{21})-(y_{12}-y_{22})}$

Running a regression analysis gives the same result. Consider the OLS model

${\displaystyle y~=~\beta _{0}+\beta _{1}T+\beta _{2}S+\beta _{3}(T\cdot S)+\varepsilon }$

where ${\displaystyle T}$ is a dummy variable for ${\displaystyle t=2}$, and ${\displaystyle S}$ is a dummy variable for ${\displaystyle s=2}$. The composite variable ${\displaystyle (T\cdot S)}$ is then a dummy variable indicating when ${\displaystyle S=T=1}$. Although it is not shown rigorously here, it turns out that the estimates in this model are

${\displaystyle {\hat {\beta }}_{0}~=~(y~|~T=0,~S=0)}$

${\displaystyle {\hat {\beta }}_{1}~=~(y~|~T=1,~S=0)-(y~|~T=0,~S=0)}$

${\displaystyle {\hat {\beta }}_{2}~=~(y~|~T=0,~S=1)-(y~|~T=0,~S=0)}$

${\displaystyle {\hat {\beta }}_{3}~=~[(y~|~T=1,~S=1)-(y~|~T=0,~S=1)]-[(y~|~T=1,~S=0)-(y~|~T=0,~S=0)]}$,

which is equivalent to

${\displaystyle {\hat {\beta }}_{3}~=~(y_{11}-y_{21})-(y_{12}-y_{22})}$.

But this is the expression for the treatment effect that was given in the formal definition and in the above table.

## Card & Krueger (1994) example

Consider one of the most famous DID studies, the Card and Krueger article on minimum wage in New Jersey, published in 1994.[4] Card and Krueger compared employment in the fast food sector in New Jersey and in Pennsylvania, in February 1992 and in November 1992, after New Jersey's minimum wage rose from $4.25 to$5.05 in April 1992. Observing a change in employment in New Jersey only, before and after the treatment, would fail to control for omitted variables such as weather and macroeconomic conditions of the region. By including Pennsylvania as a control in a difference-in-differences model, any bias caused by variables common to New Jersey and Pennsylvania is implicitly controlled for, even when these variables are unobserved. Assuming that New Jersey and Pennsylvania have parallel trends over time, Pennsylvania's change in employment can be interpreted as the change New Jersey would have experienced, had they not increased the minimum wage, and vice versa. The evidence suggested that the increased minimum wage did not induce an increase in unemployment in New Jersey, as standard economic theory would suggest. The table below shows Card & Krueger's estimates of the treatment effect on employment, measured as FTEs (or Full-time equivalents). Keeping in mind that the finding is controversial, Card and Krueger estimate that the \$0.80 minimum wage increase in New Jersey led to a 2.75 FTE increase in employment.

New Jersey Pennsylvania Difference
February 20.44 23.33 -2.89
November 21.03 21.17 -0.14
Change 0.59 -2.16 2.75