UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Experimental Design by Roger Kirk
Chapter 5: Completely Randomized Design

use http://www.ats.ucla.edu/stat/stata/examples/kirk/cr4
Table 5.2-1, page 167. The variable order was added to the file to preserve the original ordering of the data.
tabdisp order a, cellvar(y)

----------+-----------------------
          |           a           
    order |    1     2     3     4
----------+-----------------------
        1 |    4     4     5     3
        2 |    6     5     6     5
        3 |    3     4     5     6
        4 |    3     3     4     5
        5 |    1     2     3     6
        6 |    3     3     4     7
        7 |    2     4     3     8
        8 |    2     3     4    10
----------+-----------------------

dotplot y, by(a) ylabel(1(1)10)
table a, contents(freq mean y sd y)

----------+-----------------------------------
        a |      Freq.     mean(y)       sd(y)
----------+-----------------------------------
        1 |          8           3    1.511858
        2 |          8         3.5    .9258201
        3 |          8        4.25    1.035098
        4 |          8        6.25     2.12132
----------+-----------------------------------
Figure 5.2-1(a), page 168.
egen mean = mean(y), by(a)
generate e = y - mean
dotplot e, by(a) ylabel(-3(1)4)
Table 5.3-2, page 172.
anova y a

                     Number of obs =      32     R-squared     =  0.4455
                     Root MSE      =   1.476     Adj R-squared =  0.3860

            Source |  Partial SS    df       MS           F     Prob > F
        -----------+----------------------------------------------------
             Model |       49.00     3  16.3333333       7.50     0.0008
                   |
                 a |       49.00     3  16.3333333       7.50     0.0008
                   |
          Residual |       61.00    28  2.17857143  
        -----------+----------------------------------------------------
             Total |      110.00    31   3.5483871
Three contrasts, page 173.

Note 1: The contrast command can be downloaded by typing findit contrast (see How can I use the findit command to search for programs and get additional help? for more information about using findit).

Note 2: The contrast command reports results as F-ratios, not t-tests. In this case, F is just t2.
contrast a, value(1 -1 0 0) title(contrast 1)

contrast 1
Contrast variable a (1 -1 0 0)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |          1         1      1.0000    F        =     0.46
error    |         61        28      2.1786    Prob > F =   0.5036
---------+---------------------------------

contrast a, value(0 0 1 -1) title(contrast 2)

contrast 2
Contrast variable a (0 0 1 -1)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |         16         1     16.0000    F        =     7.34
error    |         61        28      2.1786    Prob > F =   0.0114
---------+---------------------------------

contrast a, value(1 1 -1 -1) title(contrast 3)

contrast 3
Contrast variable a (1 1 -1 -1)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |         32         1     32.0000    F        =    14.69
error    |         61        28      2.1786    Prob > F =   0.0007
---------+---------------------------------
Table 5.4-1, page 174.

Note: The fhcomp command can be downloaded by typing findit fhcomp (see How can I use the findit command to search for programs and get additional help? for more information about using findit).
fhcomp a

Fisher-Hayter pairwise comparisons for variable a
studentized range critical value(.05, 3, 28) = 3.4994064

                                      mean     critical
grp vs grp       group means          dif        dif
-------------------------------------------------------
  1 vs   2     3.0000     3.5000     0.5000    1.8261
  1 vs   3     3.0000     4.2500     1.2500    1.8261
  1 vs   4     3.0000     6.2500     3.2500*   1.8261
  2 vs   3     3.5000     4.2500     0.7500    1.8261
  2 vs   4     3.5000     6.2500     2.7500*   1.8261
  3 vs   4     4.2500     6.2500     2.0000*   1.8261
Omega-squared on page 178 and effect size on page 181.

Note: The omega2 command can be downloaded by typing findit omega2 (see How can I use the findit command to search for programs and get additional help? for more information about using findit).
omega2

 omega squared = 0.3785
 effect size   = 0.7805
Parts of Table 5.7-4, page 196.
contrast a, value(-3 -1 1 3) title(linear trend)

linear trend
Contrast variable a (-3 -1 1 3)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |       44.1         1     44.1000    F        =    20.24
error    |         61        28      2.1786    Prob > F =   0.0001
---------+---------------------------------

contrast a, value(1 -1 -1 1) title(quadratic trend)

quadratic trend
Contrast variable a (1 -1 -1 1)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |        4.5         1      4.5000    F        =     2.07
error    |         61        28      2.1786    Prob > F =   0.1617
---------+---------------------------------

contrast a, value(-1 3 -3 1) title(cubic trend)

cubic trend
Contrast variable a (-1 3 -3 1)
source           SS          df      MS        Dep Var  =        y
---------+---------------------------------    N of obs =       32
contrast |         .4         1      0.4000    F        =     0.18
error    |         61        28      2.1786    Prob > F =   0.6716
---------+---------------------------------
Figure 5.7-3, page 199.
predict p1  /* compute observed means */
graph twoway (scatter p1 a, connect(l)) (lfit p1 a), ylabel(2(1)7)

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California