# Re: st: difference-in-difference

 From Chris Rohlfs To statalist@hsphsun2.harvard.edu Subject Re: st: difference-in-difference Date Fri, 24 Jun 2005 09:55:52 -0500 (CDT)

Hans,

This is generally done using a regression. I'm not quite sure what the format of your data is from this output, but let's say that you reshape the data into "long" format, so that you have two dummy variables:

post - equals 1 if the observation is in the post period & 0 otherwise.
treatment - equals 1 if the observation is in the treatment group and zero otherwise.

Then do:

gen pt = post*treatment
reg gruppe pt post treatment

The coefficient on pt is the difference-in-difference estimator. The t-statistic on that regression coefficient is the t-test for equality of the differences.

Chris

On Fri, 24 Jun 2005, Hans J. Baumgartner wrote:

```Dear statalist,

I am trying to obtain the difference-in-difference estimator by using
ttest. However, I got stocked somewhere half way.

I ttested the difference in two groups. (see below). What I would like to
do now is to check the difference of these two differences. Is there
anyway to do this?`

. ttest gruppe11 = gruppe10, unpaired

Two-sample t test with equal variances

------------------------------------------------------------------------------
Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf.
Interval]
---------+--------------------------------------------------------------------
gruppe11 |      36    .4444444    .0839921    .5039526    .2739314
.6149575
gruppe10 |     203    .4187192    .0347119    .4945689     .350275
.4871634
---------+--------------------------------------------------------------------
combined |     239    .4225941    .0320194    .4950087    .3595164
.4856719
---------+--------------------------------------------------------------------
diff |            .0257252    .0896915               -.1509692
.2024197
------------------------------------------------------------------------------
Degrees of freedom: 237

Ho: mean(gruppe11) - mean(gruppe10) = diff = 0

Ha: diff < 0               Ha: diff != 0              Ha: diff > 0
t =   0.2868                t =   0.2868              t =   0.2868
P < t =   0.6127          P > |t| =   0.7745          P > t =   0.3873

. ttest gruppe01 = gruppe00, unpaired

Two-sample t test with equal variances

------------------------------------------------------------------------------
Variable |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf.
Interval]
---------+--------------------------------------------------------------------
gruppe01 |      57    .7017544    .0611344    .4615545    .5792875
.8242213
gruppe00 |     285    .5017544    .0296694    .5008764    .4433546
.5601541
---------+--------------------------------------------------------------------
combined |     342    .5350877    .0270098    .4994981     .481961
.5882144
---------+--------------------------------------------------------------------
diff |                  .2    .0717663                .0588382
.3411618
------------------------------------------------------------------------------
Degrees of freedom: 340

Ho: mean(gruppe01) - mean(gruppe00) = diff = 0

Ha: diff < 0               Ha: diff != 0              Ha: diff > 0
t =   2.7868                t =   2.7868              t =   2.7868
P < t =   0.9972          P > |t| =   0.0056          P > t =   0.0028

++++++++++++++++++++++++++++++++
Hans J. Baumgartner
Dept. Public Economics
DIW Berlin
German Institut for Economic Research
phone: +49/30/89789-307
fax :      +49/30/89789-114
URL: www.diw.de
www.hansbaumgartner.de
++++++++++++++++++++++++++++++++
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

```
```*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```