UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Design and Analysis by Geoffrey Keppel
Chapter 14: The Analysis of Covariance

Page 312 shows the analysis of covariance. With the xi3 command, you indicate a continuous variable by not providing a coding scheme for it. Hence, there is no c. or u. in front of the variable x. We use the test command to obtain the F value shown in the text. You can download the xi3 command by typing findit xi3 (see How can I use the findit command to search for programs and get additional help? for more information about using findit).
use http://www.ats.ucla.edu/stat/stata/examples/da/chap14, clear
xi3: regress y c.a x

c.a               _Ia_1-3             (naturally coded; _Ia_1 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  3,    20) =    5.50
       Model |  275.828162     3  91.9427208           Prob > F      =  0.0064
    Residual |  334.171838    20  16.7085919           R-squared     =  0.4522
-------------+------------------------------           Adj R-squared =  0.3700
       Total |         610    23  26.5217391           Root MSE      =  4.0876

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ia_2 |   3.843675   2.044417     1.88   0.075    -.4209034    8.108254
       _Ia_3 |   6.563246   2.103897     3.12   0.005     2.174594     10.9519
           x |   1.250597   .3993861     3.13   0.005     .4174919    2.083701
       _cons |   .6205251   3.109435     0.20   0.844    -5.865643    7.106693
------------------------------------------------------------------------------
test _Ia_2 _Ia_3

 ( 1)  _Ia_2 = 0.0
 ( 2)  _Ia_3 = 0.0

       F(  2,    20) =    4.96
            Prob > F =    0.0178
Below we show how to compute the adjusted means shown on page 314. The adjust command adjusts the means for x and lists them separately for each level of a.
adjust x, by(a)

--------------------------------------------------
     Dependent variable: y     Command: regress
   Variables left as is: _Ia_2, _Ia_3
  Covariate set to mean: x = 7.5
--------------------------------------------------
----------------------
        a |         xb
----------+-----------
        1 |    6.53103
        2 |    10.3747
        3 |    13.0943
----------------------
     Key:  xb  =  Linear Prediction
On pages 314-316 Keppel shows how to compare group 1 with 2 and 3. We create Acomp1 using the char command that shows the comparison of interest, and add a second comparison that is orthogonal to the first.
char a[user] (1 -.5 -.5\0 -1 1)
We now use the user-defined contrasts and the test command to obtain the results shown in the test. These results are slightly different from Keppel's on page 316, but do match results from other packages. We think the differences may be simply due to rounding error.
xi3:  regress y u.a x

u.a               _Ia_1-3             (naturally coded; _Ia_3 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  3,    20) =    5.50
       Model |  275.828162     3  91.9427208           Prob > F      =  0.0064
    Residual |  334.171838    20  16.7085919           R-squared     =  0.4522
-------------+------------------------------           Adj R-squared =  0.3700
       Total |      610.00    23  26.5217391           Root MSE      =  4.0876

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ia_1 |   -5.20346   1.784189    -2.92   0.009    -8.925214   -1.481707
       _Ia_2 |    2.71957   2.116299     1.29   0.213    -1.694951    7.134092
           x |   1.250597   .3993861     3.13   0.005     .4174919    2.083701
       _cons |   .6205251   3.109435     0.20   0.844    -5.865643    7.106693
------------------------------------------------------------------------------

test _Ia_1

 ( 1)  _Ia_1 = 0.0

       F(  1,    20) =    8.51
            Prob > F =    0.0085
At the bottom of page 320 Keppel shows how to test for homogeneity of regression across groups. This is equivalent to testing the interaction of a*x, where an interaction would indicate that the regression coefficient for x is significantly different across the levels of a. We see that the test of a*x corresponds to that shown at the bottom of page 320.
xi3: regress y c.a*x 
c.a               _Ia_1-3             (naturally coded; _Ia_1 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  5,    18) =    3.64
       Model |  306.630482     5  61.3260965           Prob > F      =  0.0189
    Residual |  303.369518    18  16.8538621           R-squared     =  0.5027
-------------+------------------------------           Adj R-squared =  0.3645
       Total |         610    23  26.5217391           Root MSE      =  4.1053

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ia_2 |   12.59373   7.515511     1.68   0.111    -3.195776    28.38323
       _Ia_3 |   14.24079   7.872543     1.81   0.087    -2.298813    30.78039
           x |   1.089651   .4314027     2.53   0.021     .1833076    1.995995
      _Ia2Xx |  -1.102471   .9093853    -1.21   0.241    -3.013019    .8080762
      _Ia3Xx |  -1.053637   1.085943    -0.97   0.345    -3.335119    1.227845
       _cons |   1.704052   3.262729     0.52   0.608    -5.150687     8.55879
------------------------------------------------------------------------------

test _Ia2Xx _Ia3Xx

 ( 1)  _Ia2Xx = 0
 ( 2)  _Ia3Xx = 0

       F(  2,    18) =    0.91
            Prob > F =    0.4188

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.