Homework 5

Doug Hemken

Illustrate a two-group t-test using Stata. Illustrate with a box plot.

First, simulate some data.

. clear

. set obs 2
number of observations (_N) was 0, now 2

. generate group = _n - 1

. expand = 15
(28 observations created)

. generate y = rnormal(group)

Let’s check the data we created.

. table group, contents(freq mean y sd y semean y) row

----------------------------------------------------------
    group |      Freq.     mean(y)       sd(y)      sem(y)
----------+-----------------------------------------------
        0 |         15   -.0062374    .6081133    .1570142
        1 |         15    .7164829    .8867842    .2289667
          | 
    Total |         30    .3551227    .8326126    .1520136
----------------------------------------------------------

Next, do the t-test.

. ttest y, by(group)

Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
       0 |      15   -.0062374    .1570142    .6081134   -.3429993    .3305246
       1 |      15    .7164829    .2289667    .8867842    .2253982    1.207568
---------+--------------------------------------------------------------------
combined |      30    .3551227    .1520136    .8326126    .0442201    .6660254
---------+--------------------------------------------------------------------
    diff |           -.7227203    .2776314               -1.291422   -.1540181
------------------------------------------------------------------------------
    diff = mean(0) - mean(1)                                      t =  -2.6032
Ho: diff = 0                                     degrees of freedom =       28

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0073         Pr(|T| > |t|) = 0.0146          Pr(T > t) = 0.9927

Finally, a box plot.

. graph box y, by(group)