Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

The Stata Journal (2016)

16, Number 1, pp. 52–71

diff: Simplifying the estimation of


difference-in-differences treatment effects
Juan M. Villa
Global Development Institute
University of Manchester
Manchester, UK
juan.villa@manchester.ac.uk

Abstract. In this article, I present the features of the user-written command diff,
which estimates difference-in-differences (DID) treatment effects. diff simplifies
the DID analysis by allowing the conventional DID setting to be combined with
other nonexperimental evaluation methods. The command is equipped with an
attractive set of options: the single DID with covariates, the kernel propensity-score
matching DID, and the quantile DID. Specific options are included to obtain DID
estimation on a repeated cross-section setting and to test the general balancing
properties of the model. I illustrate the features of diff using a sample of the
dataset from the pioneering implementation of DID by Card and Krueger (1994,
American Economic Review 84: 772–793).
Keywords: st0424, diff, difference-in-differences, causal inference, kernel propensity
score, quantile treatment effects, nonexperimental methods, DID, QDID

1 Introduction
There is a growing body of literature using difference-in-differences (DID) treatment
effects as a reliable nonexperimental evaluation method.1 DID estimation has been
widely used when panel data or repeated cross-sections are available for intervention
impact assessments. A key aspect of DID is that it facilitates the causal inference anal-
ysis of an intervention when time-invariant unobserved heterogeneity might confound a
causal-effect analysis (Abadie 2005; Angrist and Pischke 2009). Different specifications
of the DID model can also account for observed heterogeneity and can incorporate other
nonexperimental evaluation methods into the analysis.
Despite the availability of other plausible methods based on the existence of obser-
vational data for nonexperimental causal inference (that is, matching methods, instru-
mental variables, regression discontinuity, etc.), DID estimation offers an alternative by
reaching unbiased results while accounting for time-invariant unobserved heterogeneity.
Four elements are specific to the DID setting (see figure 1): the first one is the availability
of a treated group and control group; the second is the existence of parallel paths in the
pretreatment trends; the third is the clear time cutoff identifying when the treatment
starts, so there is a before and after period; and the fourth is the assumption that, with-
1. According to https://scholar.google.com (accessed in April 2015), while the number of academic
documents using DID was 136 in 2000, it had reached 2,990 in 2014.


c 2016 StataCorp LP st0424
J. M. Villa 53

out the treatment, the treated group would show a trend similar to that observed for
the control group. Thus the DID treatment effects are obtained when panel or repeated
cross-section data are available and a treatment has been administered.

Figure 1. Basic DID setting

Although the latest version of Stata is equipped with the command teffects, which
estimates the treatment effects on a cross-sectional basis, DID is based on the assessment
of an intervention’s impact on a given outcome variable in a before-and-after setting.
While DID treatment effects are focused on comparing treated and control groups sharing
common pretreatment trends, the options of the teffects command entail estimating
the average treatment effects, with special focus on the nearest-neighbor matching ap-
proach. Therefore, although existing nonexperimental evaluation methods can reach
different levels of internal and external validity (Dehejia 2013), the best method for
evaluating a given intervention depends on the characteristics of the available data.
In this article, I present the user-written command diff, which estimates DID treat-
ment effects. diff runs several types of DID estimation beyond basic single DID. diff is
attractive because it combines the single DID with control covariates, advanced match-
ing methods, and balancing-test analysis. By employing two-period panel data or re-
peated cross-sections, diff joins the DID treatment-effects estimation with the kernel
propensity-score matching following Heckman, Ichimura, and Todd (1997, 1998), and
Blundell and Dias (2009). This kernel propensity-score matching in diff follows the
algorithm of psmatch2 developed under a cross-sectional setting by Leuven and Sianesi
(2003). diff also allows estimation of the DID treatment effects at different quantiles for
the kernel matching and repeated cross-sections options (Meyer, Viscusi, and Durbin
1995). In this article, I provide details on implementing diff using a sample of the
dataset from Card and Krueger’s (1994) pioneering article on the effects of a natural
experiment consisting of a minimum-wage increase in the United States. Finally, I
explain how the balancing properties can be tested when information on covariates is
provided.
54 Simplifying the estimation of difference-in-differences treatment effects

diff makes an important contribution to advancing the development of commands


designed for causal inference analysis in Stata. In addition to the existing commands
for assessing the impact of interventions with data on a cross-section format, diff
extends the causal inference analysis for panel data with a before-and-after setting.
For instance, pscore, psmatch2, and nnmatch (Abadie et al. 2004; Becker and Ichino
2002; Leuven and Sianesi 2003) estimate the effects of interventions by using matching
techniques; rd (Nichols 2007) is helpful for when the treatment is delivered according to
an assignment variable with a clear cutoff selection threshold; and ivtreatreg (Cerulli
2014) assists in the specification of an instrumental-variable approach accounting for
unobserved heterogeneity with cross-sectional data. diff joins this family of user-
written commands in Stata by providing an intuitive syntax and simplifying the casual
inference analysis with binary treatments over time.
I divide this article into four sections. In section 2, I explain the equations behind
the estimation of the DID and the development of the diff command. In section 3, I
present the syntax for the command and options. In section 4, I provide an example
using diff on the Card and Krueger (1994) data.

2 A basic DID framework


The definition of DID treatment effects estimated by diff is based on the existence
of a pair of before-and-after periods, namely, one baseline (t = 0) and one follow-up
(t = 1). The basic DID framework is dependent on the availability of two groups of
units i, including a treated group to which the treatment is delivered (Zi = 1) and a
control group to which the treatment is not delivered (Zi = 0). The treatment indicator
in the DID setting requires absence of any intervention in the baseline for either group
(Di,t=0 = 0|Zi = 1, 0), and it requires the intervention to be positive for the treated
group in the follow-up (Di,t=1 = 1|Zi = 1). For a given outcome variable, Yit , the
population DID treatment effect is given by the difference in the outcome variable for
treated and control units before and after the intervention. The single DID setting is
given by

DID = {E(Yit=1 |Dit=1 = 1, Zi = 1) − E(Yit=1 |Dit=1 = 0, Zi = 0)}


− {E(Yit=0 |Dit=0 = 0, Zi = 1) − E(Yit=0 |Dit=0 = 0, Zi = 0)} (1)

This single DID can be combined with other nonexperimental evaluation methods.
Additional control covariates are important when observed heterogeneity may confound
the identification strategy. Given the features of DID estimation, observed covariates
should be exempt from the effects of the treatment. Thus, if observable covariates (Xi )
are available, they can be added into the analysis.

DID = {E(Yit=1 |Dit=1 = 1, Zi = 1, Xi ) − E(Yit=1 |Dit=1 = 0, Zi = 0, Xi )}


− {E(Yit=0 |Dit=0 = 0, Zi = 1, Xi ) − E(Yit=0 |Dit=0 = 0, Zi = 0, Xi )} (2)
J. M. Villa 55

A complementary method to the DID treatment effect is the incorporation of kernel


propensity-score weights. Apart from the inclusion of control variables, observed co-
variates can be used to estimate the propensity score (the likelihood of being treated)
and to calculate kernel weights following Heckman, Ichimura, and Todd (1997, 1998).
Instead of accounting for control variables, this method matches treated and control
units according to their propensity score. Each treated unit is matched to the whole
sample of control units instead of on a limited number of nearest neighbors. To begin,
one obtains the propensity score (pi ) for both groups.

pi = E(Zi = 1|Xi )

According to Heckman, Ichimura, and Todd (1997), the kernel matching is given by
the propensity score, given the covariates, which leads to the calculation of the kernel
weights,
K pih−pn
k

wi =  (3)
K pih−pn
k

in which K(·) is the kernel function and hn is the selected bandwidth. The kernel
weights are then introduced into (1) to obtain a kernel propensity-score matching DID
treatment effect as follows:

DID = {E(Yit=1 |Dit=1 = 1, Zi = 1) − wi × E(Yit=1 |Dit=1 = 0, Zi = 0)}


− {E(Yit=0 |Dit=0 = 0, Zi = 1) − wi × E(Yit=0 |Dit=0 = 0, Zi = 0)} (4)

Now, to increase the internal validity of the DID estimand, one can restrict (4) to the
common support of the propensity score for treated and control groups. The common
support is the overlapping region of the propensity for treated and control groups. This
sample of i units can be restricted to the region defined as

(i : pi ∈ [max{min(pi |Zi = 1), min(pi |Zi = 0)}, min{max(pi |Zi = 1), min(pi |Zi = 0)}])

Complementarily, when treated and control units cannot be followed over the base-
line and follow-up periods, the DID treatment effects can be estimated with repeated
cross-sections. This is very common when a treatment has been administered to cer-
tain regional or demographic groups over several cross-sections. The kernel propensity-
score matching with repeated cross-section DID treatment effects is specified following
Blundell and Dias (2009).

DID = {E(Yit=1 |Dit=1 = 1, Zi = 1) − wit=1


c
× E(Yit=1 |Dit=1 = 0, Zi = 0)}
− wit=0
t
× {E(Yit=0 |Dit=0 = 0, Zi = 1) − wit=0
c
× E(Yit=0 |Dit=0 = 0, Zi = 0)}

c c
Here wit=0 and wit=1 are the kernel weights for the control group in the baseline and
t
follow-up periods, respectively, while wit=0 is the kernel weight for the treated group
in the baseline period. The three sets of kernel weights are calculated independently
56 Simplifying the estimation of difference-in-differences treatment effects

according to the estimated propensity score and do not require the panel structure of
the units in the sample.
Finally, the balancing property of the treated and the control can be tested. Given
the availability of observable covariates, it can be shown that in absence of the treatment,
the outcome variable is orthogonal to the treatment indicator given the set of covariates.
In other words, the balancing property can be tested in the baseline as
Yit=0 ⊥Zi |Xi (5)

Note that the balancing property is optional in the DID setting. The most important
assumption, which is not tested in this approach, is the complement of the parallel paths
of the outcome for the treated and the control groups. Given the availability of two
periods in this analysis, this assumption cannot be tested here. For an extension of this
test, see Mora and Reggio (2012).

2.1 Estimation
To estimate the expected values in (1), we rely on linear regression for the single DID
analysis. The subsequent complementary introduction of control variables or kernel
propensity-score matching weights is similarly specified by linear regression. In the
basic framework, the estimation can be shown as follows:
outcome vari = β0 +β1 ×period()i +β2 ×treated()i +β3 ×period()i ×treated()i +ei

Here outcome vari is the outcome variable for each unit; period()i is a binary vari-
able taking the value of 0 in the baseline and 1 in the follow-up periods; and treated()i
is a binary variable indicating the treatment status for each unit, similar to Zi = 1.
The expected values in (1) are obtained from the interaction of the estimated coef-
ficients. The estimated coefficients have the following interpretation:

• β0 : the mean outcome of the control group at the baseline.


• β0 + β1 : the mean outcome of the control group in the follow-up.
• β2 : the single difference between the treated and the control groups at the baseline.
• β0 + β2 : the mean outcome of the treated group at the baseline.
• β0 + β1 + β2 + β3 : the mean outcome of the treated group in the follow-up.
• β3 : the DID estimand.

3 The diff command


The diff command demands pooled data containing the treatment status of the treated
and control groups and the before-and-after period indicator. diff mainly simplifies
J. M. Villa 57

DID estimation by providing the output table with the estimated coefficients and their
interactions.

3.1 Syntax
     
diff outcome var if in weight , period(varname) treated(varname)

cov(varlist) kernel id(varname) bw(#) ktype(kernel) rcs qdid(quantile)
pscore(varname) logit support addcov(varlist) cluster(varname) robust

bs reps(int) test report nostar export(filename)

The command requires the specification of the outcome variable (outcome var) and
allows the use of sampling weights.
The simplification of the diff command also consists of the arrangement of the
regression coefficients in the output table. The number of observations, R-squared, the
standard errors, the t statistic (or the z statistic when standard errors are bootstrapped),
and the p-value are also presented.

DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS


Number of observations in the DIFF-IN-DIFF: #
Baseline Follow-up
Control: # # (total)
Treated: # # (total)
(total) (total)

Outcome var. fte S. Err. t P>|t|

Baseline

Control β0

Treated β0 + β2

Diff (T-C) β2

Follow-up

Control β0 + β1

Treated β0 + β1 + β2 + β3

Diff (T-C) β2 + β3

Diff-in-Diff β3

R-square: #.##
* Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1
58 Simplifying the estimation of difference-in-differences treatment effects

3.2 Options
period(varname) specifies the binary period variable (0: baseline; 1: follow-up). Op-
tion period() is required.
treated(varname) specifies the binary treatment variable (0: controls; 1: treated).
Option treated() is required.
cov(varlist) allows the user to include control covariates in the model [Xi in (2)]. The
coefficients of the variables in cov(varlist) are not displayed in the output table.
They can be seen when option report is specified.
kernel performs the kernel propensity-score matching DID. This option generates the
variable weights, which contains the weights2 derived from the kernel propensity-
score matching, as well as generates ps when the propensity score is not supplied
in pscore(varname), following Leuven and Sianesi (2003). This option requires
specification of the id(varname) option except when the rcs option is also specified
(under the repeated cross-section setting).3 Under a panel or cross-sectional setting,
you can specify the support option with kernel to allow the estimation of the DID
on the common support.
id(varname) specifies the identification variable for each unit or individual when the
dataset is composed of a panel of treated and control groups. Option kernel requires
id().
bw(#) specifies the supplied bandwidth of the kernel function. The default is bw(0.06).
ktype(kernel) specifies the type of the kernel function. The types are epanechnikov
(the default), gaussian, biweight, uniform, and tricube.
rcs indicates that the kernel is set for repeated cross-section. This option does
not require option id(varname). Option rcs strongly assumes that covariates in
cov(varlist) do not vary over time.
qdid(quantile) performs the quantile difference-in-differences (QDID) estimation at the
specified quantile from 0.1 to 0.9 (quantile 0.5 performs the QDID at the median).
This option may be combined with kernel and cov(). qdid() does not support
weights or robust standard errors. This option uses the Stata commands qreg for
quantile nonlinear regressions and bsqreg for complementary bootstrapped standard
errors. See Angrist and Pischke (2009) for detailed information on quantile treat-
ment effects and Meyer, Viscusi, and Durbin (1995) for an illustrative example.
pscore(varname) specifies the supplied propensity score.

2. These weights are 1 for treated units or individuals.


3. See Blundell and Dias (2009) for further details on kernel propensity-score matching upon repeated
cross-sections.
J. M. Villa 59

logit specifies logit estimation of the propensity score. The default is probit estimation.
The results of the probit estimation are used to predict the probability of being
treated, known as the propensity score, and then to calculate the kernel matching,
as in (3).
support performs diff on the common support of the propensity score given the option
kernel.
addcov(varlist) specifies additional covariates with those specified in the estimation of
the propensity score.
cluster(varname) estimates clustered standard errors by the specified category in
varname.
robust estimates robust standard errors following Stata’s sandwich-type estimation.
bs executes a bootstrapped estimation of standard errors.
reps(int) specifies the number of replications when the bs option is also specified. The
default is reps(50).
test performs a balancing t test of the difference in the means of the covariates between
the control and the treated groups in period() = 0. The option test combined
with kernel performs the balancing t test with the weighted covariates; see [R] ttest.
This option is one way to test (5).
report displays the inference of the included covariates or the estimation of the propen-
sity score when option kernel is specified.
nostar removes the inference stars from the p-values.
export(filename) exports the output table into the working directory in a .csv file.
See [D] cd for details.
60 Simplifying the estimation of difference-in-differences treatment effects

3.3 Stored results


diff stores the following in r():
Scalars
r(mean c0) mean of output var of the control group in period() = 0
r(mean t0) mean of output var of the treated group in period() = 0
r(diff0) difference of the mean of output var between the treated and the
control groups in period t = 0
r(mean c1) mean of output var of the control group in period() = 1
r(mean t1) mean of output var of the treated group in period() = 1
r(diff1) difference of the mean of output var between the treated and the
control groups in period() = 1
r(did) DID treatment effect
r(se c0) standard error of the mean of output var of the control group in period() = 0
r(se t0) standard error of the mean of output var of the treated group in period() = 0
r(se d0) standard error of the difference of output var between the treated and the
control groups in period() = 0
r(se c1) standard error of the mean of output var of the control group in period() = 1
r(se t1) standard error of the mean of output var of the treated group in period() = 1
r(se d1) standard error of the difference of output var between the treated and the
control groups in period() = 1
r(se dd) standard error of the DID

4 Example
To illustrate the use of diff, we use a downloadable dataset (included with the com-
mand) with a sample of the data used by Card and Krueger (1994).4 The data are from
a study by the authors on the impact of the increase in minimum wage in New Jersey
(the treated group) on the employment level in the fast-food industry. This interven-
tion took place in April 1992. They compare the changes in the number of employees
at fast-food restaurants in the treated group with those located in a neighboring state,
Pennsylvania (the control or untreated group). They conducted a baseline survey in
February 1992 and a follow-up in November.

4. This dataset is provided for illustration only. It might not be suitable for all diff options.
J. M. Villa 61

The details of the variables in the dataset are as follows:

. use cardkrueger1994.dta
(Sample dataset from Card and Krueger (1994))
. describe
Contains data from cardkrueger1994.dta
obs: 780 Sample dataset from Card and
Krueger (1994)
vars: 8 12 Mar 2014 14:03
size: 11,700

storage display value


variable name type format label variable label

id int %8.0g Store ID


t byte %8.0g Feb. 1992 = 0; Nov. 1992 = 1
treated long %8.0g treated New Jersey = 1; Pennsylvania = 0
fte float %9.0g Output: Full Time Employment
bk byte %8.0g Burger King == 1
kfc byte %8.0g Kentucky Fried Chicken == 1
roys byte %8.0g Roy Rogers == 1
wendys byte %8.0g Wendy´s == 1

Sorted by: id t treated

With 780 observations, the number of units (or restaurants) is 314 and 76 in the
treated and the control groups (or states), respectively. The outcome variable is full-
time employment (fte). Some covariates are defined as binary variables, indicating
whether the observation belongs to a given fast-food restaurant. The basic statistics
are shown as follows:

. summarize id t treated fte bk kfc roys wendys


Variable Obs Mean Std. Dev. Min Max

id 780 247.2641 148.644 1 522


t 780 .5 .5003208 0 1
treated 780 .8051282 .3963561 0 1
fte 780 17.58109 9.095066 0 80
bk 780 .4179487 .4935381 0 1

kfc 780 .2051282 .4040544 0 1


roys 780 .2435897 .4295233 0 1
wendys 780 .1333333 .3401528 0 1
62 Simplifying the estimation of difference-in-differences treatment effects

4.1 Single DID with no covariates


The single DID treatment-effects estimations with diff requires three variables: out-
come, treated, and period. This basic estimation assumes that time-invariant unob-
served heterogeneity exclusively contaminates the identification strategy. In absence of
control covariates, the command is run as follows:

. diff fte, treated(treated) period(t)


DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 20.013
Treated 17.069
Diff (T-C) -2.944 1.160 -2.54 0.011**
Follow-up
Control 17.523
Treated 17.518
Diff (T-C) -0.005 1.160 -0.00 0.997

Diff-in-Diff 2.939 1.641 1.79 0.074*

R-square: 0.01
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1

The baseline rows contain information on the mean outcome for each group as well
as each group’s single difference (−2.944 in this case). These estimators are presented
along with their standard errors, t statistics, and p-values. The same information is
displayed for the follow-up period. The last row is the DID treatment-effects estimand,
implying an increase in the number of employees by 2.939. The p-value is accompanied
by a star, which indicates the statistical inference at different significance levels, as
shown below the table (*** p < 0.01; ** p < 0.05; * p < 0.1). In this case, the DID
estimand is significant at the 10% level.
J. M. Villa 63

The parametric estimation of the standard errors could be problematic in certain


circumstances. Therefore, as an alternative, bootstrapped standard errors can be re-
quested by adding the option bs.

. diff fte, treated(treated) period(t) bs rep(50)


(running regress on estimation sample)
Bootstrap replications (50)
1 2 3 4 5
.................................................. 50
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 20.013
Treated 17.069
Diff (T-C) -2.944 1.468 -2.01 0.045**
Follow-up
Control 17.523
Treated 17.518
Diff (T-C) -0.005 1.216 -0.00 0.997

Diff-in-Diff 2.939 1.768 1.66 0.096*

R-square: 0.01
- Bootstrapped Standard Errors
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1
64 Simplifying the estimation of difference-in-differences treatment effects

4.2 Single DID with covariates


When control covariates are available in the dataset, diff allows them to be included
with the option cov(varlist). In this case, the binary variables indicating the categories
of the restaurants are provided.

. diff fte, treated(treated) period(t) cov(bk kfc roys)


DIFFERENCE-IN-DIFFERENCES WITH COVARIATES
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 21.342
Treated 19.003
Diff (T-C) -2.339 1.052 -2.22 0.026**
Follow-up
Control 18.852
Treated 19.452
Diff (T-C) 0.600 1.052 0.57 0.569

Diff-in-Diff 2.939 1.485 1.98 0.048**

R-square: 0.19
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1

Option report displays the output table of the coefficients and statistics from the
cov(varlist).

. diff fte, treated(treated) period(t) cov(bk kfc roys) report


DIFFERENCE-IN-DIFFERENCES WITH COVARIATES
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390
Report - Covariates and coefficients:

Variable(s) Coeff. Std. Err. t P>|t|

bk 0.850 0.925 0.918 0.359


kfc -9.331 1.037 -8.997 0.000
roys -1.054 1.003 -1.051 0.294
J. M. Villa 65

Outcome var. fte S. Err. t P>|t|

Baseline
Control 21.342
Treated 19.003
Diff (T-C) -2.339 1.052 -2.22 0.026**
Follow-up
Control 18.852
Treated 19.452
Diff (T-C) 0.600 1.052 0.57 0.569

Diff-in-Diff 2.939 1.485 1.98 0.048**

R-square: 0.19
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1

4.3 Kernel propensity-score matching DID treatment effects


As mentioned above, the control covariates can be used to match treated and control
units. This is possible with diff by adding the kernel option. Additionally, the
kernel propensity-score matching DID can be estimated on the common support of the
propensity score, and the propensity score can be provided in option pscore(varname)
if the user has previously executed its estimation. The syntax is

diff fte, treated(treated) period(t) cov(bk kfc roys) kernel id(id)

To view the first stage of the estimation of the propensity score, the user should
supply the report option.

. diff fte, treated(treated) period(t) cov(bk kfc roys) kernel id(id) report
KERNEL PROPENSITY SCORE MATCHING DIFFERENCE-IN-DIFFERENCES
Report - Propensity score estimation with probit command
Atention: _pscore is estimated at baseline
Iteration 0: log likelihood = -192.3521
Iteration 1: log likelihood = -191.15937
Iteration 2: log likelihood = -191.15777
Probit regression Number of obs = 390
LR chi2(3) = 2.39
Prob > chi2 = 0.4957
Log likelihood = -191.15777 Pseudo R2 = 0.0062

treated Coef. Std. Err. z P>|z| [95% Conf. Interval]

bk .1368372 .2190827 0.62 0.532 -.292557 .5662315


kfc .3619436 .2549971 1.42 0.156 -.1378415 .8617288
roys .2448943 .2415265 1.01 0.311 -.228489 .7182775
_cons .6744898 .1889629 3.57 0.000 .3041292 1.04485
66 Simplifying the estimation of difference-in-differences treatment effects

Matching iterations...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 20.006
Treated 17.069
Diff (T-C) -2.937 0.959 -3.06 0.002***
Follow-up
Control 17.367
Treated 17.518
Diff (T-C) 0.151 0.959 0.16 0.875

Diff-in-Diff 3.088 1.357 2.28 0.023**

R-square: 0.02
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1

In the case of repeated cross-sections, diff should be typed as

. diff fte, treated(treated) period(t) cov(bk kfc roys) kernel rcs


KERNEL PROPENSITY SCORE MATCHING DIFFERENCE-IN-DIFFERENCES
Repeated Cross Section - rcs option
Matching iterations: control group at base line...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
Matching iterations: control group at follow up...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
Matching iterations: treated group at baseline...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
J. M. Villa 67

DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS


Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 20.006
Treated 17.497
Diff (T-C) -2.508 0.961 -2.61 0.009***
Follow-up
Control 17.367
Treated 17.518
Diff (T-C) 0.151 0.961 0.16 0.875

Diff-in-Diff 2.660 1.359 1.96 0.051*

R-square: 0.01
- Means and Standard Errors are estimated by linear regression
**Inference: *** p<0.01; ** p<0.05; * p<0.1

4.4 QDID
It sometimes is useful to assess the effects of the intervention over the distribution of the
outcome variable. diff provides this option on the DID setting. Here one would like to
know whether the effect of the increase in minimum wage was stronger for restaurants
with a low or high number of full-time employees. The QDID is then obtained when the
option qdid(quantile) is specified. For example, estimating the treatment effects on the
median of the number of full-time employees requires the following syntax:

diff fte, treated(treated) period(t) qdid(0.50)


68 Simplifying the estimation of difference-in-differences treatment effects

This specification might be combined with covariates as follows:


. diff fte, treated(treated) period(t) qdid(0.50) cov(bk kfc roys)
QUANTILE DIFFERENCE-IN-DIFFERENCES WITH COVARIATES
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 17.250
Treated 17.250
Diff (T-C) 0.000 0.996 0.00 1.000
Follow-up
Control 17.750
Treated 17.750
Diff (T-C) 0.000 1.003 0.00 1.000

Diff-in-Diff -0.000 1.412 -0.00 1.000

R-square: 0.15
- Values are estimated at the .5 quantile
**Inference: *** p<0.01; ** p<0.05; * p<0.1

By chance, when one accounts for covariates, at the 0.5 quantile, which is the same as
the median of the dependent variable, the value of the full-time employment variable
(fte) is similar for control and treated units in the baseline and follow-up periods.
Therefore, the result above indicates a DID effect of −1.407e-15 (very close to 0), but it
is rounded to −0.000 because of the numbering format of the table.
As with the single DID, the QDID can be combined with the kernel option (also in
repeated cross-sections).
. diff fte, treated(treated) period(t) qdid(0.50) cov(bk kfc roys) kernel
> id(id) report
KERNEL PROPENSITY SCORE MATCHING QUANTILE DIFFERENCE-IN-DIFFERENCES
Report - Propensity score estimation with probit command
Atention: _pscore is estimated at baseline
Iteration 0: log likelihood = -192.3521
Iteration 1: log likelihood = -191.15937
Iteration 2: log likelihood = -191.15777
Probit regression Number of obs = 390
LR chi2(3) = 2.39
Prob > chi2 = 0.4957
Log likelihood = -191.15777 Pseudo R2 = 0.0062

treated Coef. Std. Err. z P>|z| [95% Conf. Interval]

bk .1368372 .2190827 0.62 0.532 -.292557 .5662315


kfc .3619436 .2549971 1.42 0.156 -.1378415 .8617288
roys .2448943 .2415265 1.01 0.311 -.228489 .7182775
_cons .6744898 .1889629 3.57 0.000 .3041292 1.04485
J. M. Villa 69

Matching iterations...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
DIFFERENCE-IN-DIFFERENCES ESTIMATION RESULTS
Number of observations in the DIFF-IN-DIFF: 780
Baseline Follow-up
Control: 76 76 152
Treated: 314 314 628
390 390

Outcome var. fte S. Err. t P>|t|

Baseline
Control 17.000
Treated 15.750
Diff (T-C) -1.250 1.202 -1.04 0.299
Follow-up
Control 16.000
Treated 17.000
Diff (T-C) 1.000 1.195 0.84 0.403

Diff-in-Diff 2.250 1.695 1.33 0.185

R-square: 0.00
- Values are estimated at the .5 quantile
**Inference: *** p<0.01; ** p<0.05; * p<0.1

4.5 Balancing test


The balancing test for each covariate is obtained only at the baseline. The syntax is
similar to the one for DID with control covariates. The syntax for this option is

. diff fte, treated(treated) period(t) cov(bk kfc roys) test


TWO-SAMPLE T TEST
Number of observations (baseline): 390
Baseline Follow-up
Control: 76 - 76
Treated: 314 - 314
390 -
t-test at period = 0:

Variable(s) Mean Control Mean Treated Diff. |t| Pr(|T|>|t|)

fte 20.013 17.069 -2.944 2.43 0.0155**


bk 0.447 0.411 -0.037 0.58 0.5634
kfc 0.158 0.217 0.059 1.14 0.2569
roys 0.224 0.248 0.025 0.45 0.6533

*** p<0.01; ** p<0.05; * p<0.1


70 Simplifying the estimation of difference-in-differences treatment effects

When combined with the kernel option, the covariates are weighted, and the dif-
ferences are obtained by linear regression (this test is also suitable with repeated cross-
sections).

. diff fte, treated(treated) period(t) cov(bk kfc roys) test id(id) kernel
Matching iterations...
................................................................................
> ..............................................................................
> ..............................................................................
> ..............................................................................
TWO-SAMPLE T TEST
Number of observations (baseline): 390
Baseline Follow-up
Control: 76 - 76
Treated: 314 - 314
390 -
t-test at period = 0:

Weighted Variable(s) Mean Control Mean Treated Diff. |t| Pr(|T|>|t|)

fte 20.006 17.069 -2.937 2.79 0.0056***


bk 0.465 0.411 -0.054 1.08 0.2797
kfc 0.146 0.217 0.071 1.81 0.0704*
roys 0.285 0.248 -0.036 0.81 0.4174

*** p<0.01; ** p<0.05; * p<0.1


Attention: option kernel weighs variables in cov(varlist)
Means and t-test are estimated by linear regression

5 Acknowledgments
I thank Kit Baum from Boston College for his valuable suggestions. I also thank at-
tendees at the 2012 Stata Users Meeting Group in London, UK, for providing feedback
on a previous version of this command. David Card from the University of Califor-
nia, Berkeley, as well as Vincenzo di Maro from The World Bank and Pablo Ibarraran
from the Inter-American Development Bank, provided important suggestions in an early
stage of the development of the code. Monica Oviedo from Universitat Autònoma de
Barcelona contributed with a review of some options of the diff code. I am grateful
to the Global Development Institute (formerly Brooks World Poverty Institute) and
United Nations University World Institute for Development Economics Research for
their research support. All the errors and omissions in the article are my own.

6 References
Abadie, A. 2005. Semiparametric difference-in-differences estimators. Review of Eco-
nomic Studies 72: 1–19.

Abadie, A., J. L. Herr, G. Imbens, and D. M. Drukker. 2004. nnmatch: Stata module to
compute nearest-neighbor bias-corrected estimators. Statistical Software Components
S439701, Department of Economics, Boston College.
http://econpapers.repec.org/software/bocbocode/s439701.htm.
J. M. Villa 71

Angrist, J. D., and J.-S. Pischke. 2009. Mostly Harmless Econometrics: An Empiricist’s
Companion. Princeton, NJ: Princeton University Press.

Becker, S. O., and A. Ichino. 2002. Estimation of average treatment effects based on
propensity scores. Stata Journal 2: 358–377.

Blundell, R., and M. C. Dias. 2009. Alternative approaches to evaluation in empirical


microeconomics. Journal of Human Resources 44: 565–640.

Card, D., and A. B. Krueger. 1994. Minimum wages and employment: A case study of
the fast-food industry in New Jersey and Pennsylvania. American Economic Review
84: 772–793.

Cerulli, G. 2014. ivtreatreg: A command for fitting binary treatment models with
heterogeneous response to treatment and unobservable selection. Stata Journal 14:
453–480.

Dehejia, R. 2013. The porous dialectic: Experimental and non-experimental methods in


development economics. WIDER Working Paper No. WP/2013/011, United Nations
University World Institute for Development Economics Research.
http://www.wider.unu.edu/publications/working-papers/2013/en GB/wp2013-011/.

Heckman, J. J., H. Ichimura, and P. E. Todd. 1997. Matching as an econometric


evaluation estimator: Evidence from evaluating a job training programme. Review of
Economic Studies 64: 605–654.

. 1998. Matching as an econometric evaluation estimator. Review of Economic


Studies 65: 261–294.

Leuven, E., and B. Sianesi. 2003. psmatch2: Stata module to perform full Mahalanobis
and propensity score matching, common support graphing, and covariate imbalance
testing. Statistical Software Components S432001, Department of Economics, Boston
College. https://ideas.repec.org/c/boc/bocode/s432001.html.

Meyer, B. D., W. K. Viscusi, and D. L. Durbin. 1995. Workers’ compensation and


injury duration: Evidence from a natural experiment. American Economic Review
85: 322–340.

Mora, R., and I. Reggio. 2012. Treatment effect identification using alternative parallel
assumptions. Working Paper 12-33, Universidad Carlos III de Madrid.

Nichols, A. 2007. rd: Stata module for regression discontinuity estimation. Statistical
Software Components S456888, Department of Economics, Boston College.
https://ideas.repec.org/c/boc/bocode/s456888.html.

About the author


Juan M. Villa is a research fellow at the Global Development Institute at the University of
Manchester, UK.

You might also like