kb/data/en.wikipedia.org/wiki/Difference_in_differences-0.md

891 lines
18 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Difference in differences"
chunk: 1/4
source: "https://en.wikipedia.org/wiki/Difference_in_differences"
category: "reference"
tags: "science, encyclopedia"
date_saved: "2026-05-05T09:50:03.034225+00:00"
instance: "kb-cron"
---
Difference in differences (DID or DD) is a quasi-experimental 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. 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 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), the 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 is measured at time 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 2. Not all of the difference between the treatment and control groups at time 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 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 (P2) and the "normal" outcome (the difference between P2 and Q).
== Formal definition ==
Consider the model
y
i
t
=
γ
s
(
i
)
+
λ
t
+
δ
I
(
)
+
ε
i
t
{\displaystyle y_{it}~=~\gamma _{s(i)}+\lambda _{t}+\delta I(\dots )+\varepsilon _{it}}
where
y
i
t
{\displaystyle y_{it}}
is the dependent variable for individual
i
{\displaystyle i}
and time
t
{\displaystyle t}
,
s
(
i
)
{\displaystyle s(i)}
is the group to which
i
{\displaystyle i}
belongs (i.e. the treatment or the control group), and
I
(
)
{\displaystyle I(\dots )}
is short-hand for the dummy variable equal to 1 when the event described in
(
)
{\displaystyle (\dots )}
is true, and 0 otherwise. In the plot of time versus
Y
{\displaystyle Y}
by group,
γ
s
{\displaystyle \gamma _{s}}
is the vertical intercept for the graph for
s
{\displaystyle s}
, and
λ
t
{\displaystyle \lambda _{t}}
is the time trend shared by both groups according to the parallel trend assumption (see Assumptions below).
δ
{\displaystyle \delta }
is the treatment effect, and
ε
i
t
{\displaystyle \varepsilon _{it}}
is the residual term.
Consider the average of the dependent variable and dummy indicators by group and time:
n
s
=
number of individuals in group
s
y
¯
s
t
=
1
n
s
i
=
1
n
y
i
t
I
(
s
(
i
)
=
s
)
,
γ
¯
s
=
1
n
s
i
=
1
n
γ
s
(
i
)
I
(
s
(
i
)
=
s
)
=
γ
s
,
λ
¯
s
t
=
1
n
s
i
=
1
n
λ
t
I
(
s
(
i
)
=
s
)
=
λ
t
,
D
s
t
=
1
n
s
i
=
1
n
I
(
s
(
i
)
=
treatment,
t
in after period
)
I
(
s
(
i
)
=
s
)
=
I
(
s
=
treatment,
t
in after period
)
,
ε
¯
s
t
=
1
n
s
i
=
1
n
ε
i
t
I
(
s
(
i
)
=
s
)
,
{\displaystyle {\begin{aligned}n_{s}&={\text{ number of individuals in group }}s\\{\overline {y}}_{st}&={\frac {1}{n_{s}}}\sum _{i=1}^{n}y_{it}\ I(s(i)~=~s),\\{\overline {\gamma }}_{s}&={\frac {1}{n_{s}}}\sum _{i=1}^{n}\gamma _{s(i)}\ I(s(i)~=~s)~=~\gamma _{s},\\{\overline {\lambda }}_{st}&={\frac {1}{n_{s}}}\sum _{i=1}^{n}\lambda _{t}\ I(s(i)~=~s)~=~\lambda _{t},\\D_{st}&={\frac {1}{n_{s}}}\sum _{i=1}^{n}I(s(i)~=~{\text{ treatment, }}t{\text{ in after period}})\ I(s(i)~=~s)~=~I(s~=~{\text{ treatment, }}t{\text{ in after period}}),\\{\overline {\varepsilon }}_{st}&={\frac {1}{n_{s}}}\sum _{i=1}^{n}\varepsilon _{it}\ I(s(i)~=~s),\end{aligned}}}
and suppose for simplicity that
s
=
1
,
2
{\displaystyle s=1,2}
and
t
=
1
,
2
{\displaystyle t=1,2}
. Note that
D
s
t
{\displaystyle D_{st}}
is not random; it just encodes how the groups and the periods are labeled. Then
(
y
¯
11
y
¯
12
)
(
y
¯
21
y
¯
22
)
=
[
(
γ
1
+
λ
1
+
δ
D
11
+
ε
¯
11
)
(
γ
1
+
λ
2
+
δ
D
12
+
ε
¯
12
)
]
[
(
γ
2
+
λ
1
+
δ
D
21
+
ε
¯
21
)
(
γ
2
+
λ
2
+
δ
D
22
+
ε
¯
22
)
]
=