UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Design and Analysis by Geoffrey Keppel
Chapter 11: Detailed Analysis of Main Effects and Simple Effects

In chapter 11 Keppel shows how to perform comparisons of main effects and simple effects in a two way factorial anova based on the example from chapter 10. On page 234 Keppel shows a comparison comparing group a1 with group a3. We use the char command to set up this comparison and one that is orthogonal to it. 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/chap10, clear
char a[user] (1 0 -1\1 -2 1)
We now run the anova using xi3. The term _Ia_1 corresponds to the test shown on page 234. We show the test command to illustrate that the F value for this test corresponds to the value shown in the text.
xi3:  regress errors u.a*g.b

u.a               _Ia_1-3             (naturally coded; _Ia_3 omitted)
g.b               _Ib_1-2             (naturally coded; _Ib_1 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  5,    18) =    3.05
       Model |         280     5          56           Prob > F      =  0.0361
    Residual |         330    18  18.3333333           R-squared     =  0.4590
-------------+------------------------------           Adj R-squared =  0.3087
       Total |         610    23  26.5217391           Root MSE      =  4.2817

------------------------------------------------------------------------------
      errors |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ia_1 |         -5   2.140872    -2.34   0.031    -9.497805   -.5021946
       _Ia_2 |         -3   3.708099    -0.81   0.429    -10.79043    4.790427
       _Ib_2 |          2   1.748015     1.14   0.268    -1.672443    5.672443
     _Ia1Xb2 |         12   4.281744     2.80   0.012     3.004389    20.99561
     _Ia2Xb2 |  -1.56e-16   7.416198    -0.00   1.000    -15.58085    15.58085
       _cons |         10   .8740074    11.44   0.000     8.163779    11.83622
------------------------------------------------------------------------------
test  _Ia_1

 ( 1)  _Ia_1 = 0.0

       F(  1,    18) =    5.45
            Prob > F =    0.0313
On page 241, Keppel shows how to perform tests of simple main effects testing the effect of a at b1 and b2. We can get the tests of simple main effects using the xi2 command. The second xi2 command with the @ symbol instead of the * gives us the tests of simple effects of A at b1 and b2.
xi3:  regress errors g.a@g.b

g.a               _Ia_1-3             (naturally coded; _Ia_1 omitted)
g.b               _Ib_1-2             (naturally coded; _Ib_1 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  5,    18) =    3.05
       Model |         280     5          56           Prob > F      =  0.0361
    Residual |         330    18  18.3333333           R-squared     =  0.4590
-------------+------------------------------           Adj R-squared =  0.3087
       Total |         610    23  26.5217391           Root MSE      =  4.2817

------------------------------------------------------------------------------
      errors |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ib_2 |          2   1.748015     1.14   0.268    -1.672443    5.672443
     _Ia2Wb1 |          7    3.02765     2.31   0.033     .6391426    13.36086
     _Ia2Wb2 |          1    3.02765     0.33   0.745    -5.360857    7.360857
     _Ia3Wb1 |         11    3.02765     3.63   0.002     4.639143    17.36086
     _Ia3Wb2 |         -1    3.02765    -0.33   0.745    -7.360857    5.360857
       _cons |         10   .8740074    11.44   0.000     8.163779    11.83622
------------------------------------------------------------------------------
If we perform the test command below, we get all of the effects of b at a1, so this is the overall simple effect of b at a1.
test _Ia2Wb1 _Ia3Wb1

 ( 1)  _Ia2Wb1 = 0
 ( 2)  _Ia3Wb1 = 0

       F(  2,    18) =    6.76
            Prob > F =    0.0064
Likewise, the test command below tests all of the effects of effects of b at a2, so this is the overall simple effect of b at a2.
test _Ia2Wb2 _Ia3Wb2

 ( 1)  _Ia2Wb2 = 0
 ( 2)  _Ia3Wb2 = 0

       F(  2,    18) =    0.22
            Prob > F =    0.8061
Page 246 shows how to do a simple comparison comparing groups 1 and 2. Below we use the char command to specify a comparison of groups 1 and 2, and a second comparison (that we don't care about) comparing groups 1 and 2 with group 3.  We then use u.a@s.b to indicate we want the effects of a that were user defined at each level of b.
char a[user] (1 -1 0\1 1 -2)
xi3:  regress errors u.a@g.b

u.a               _Ia_1-3             (naturally coded; _Ia_3 omitted)
g.b               _Ib_1-2             (naturally coded; _Ib_1 omitted)

      Source |       SS       df       MS              Number of obs =      24
-------------+------------------------------           F(  5,    18) =    3.05
       Model |         280     5          56           Prob > F      =  0.0361
    Residual |         330    18  18.3333333           R-squared     =  0.4590
-------------+------------------------------           Adj R-squared =  0.3087
       Total |         610    23  26.5217391           Root MSE      =  4.2817

------------------------------------------------------------------------------
      errors |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _Ib_2 |          2   1.748015     1.14   0.268    -1.672443    5.672443
     _Ia1Wb1 |         -7    3.02765    -2.31   0.033    -13.36086   -.6391426
     _Ia1Wb2 |         -1    3.02765    -0.33   0.745    -7.360857    5.360857
     _Ia2Wb1 |        -15   5.244044    -2.86   0.010    -26.01733   -3.982672
     _Ia2Wb2 |          3   5.244044     0.57   0.574    -8.017328    14.01733
       _cons |         10   .8740074    11.44   0.000     8.163779    11.83622
------------------------------------------------------------------------------
The term _Ia1Wb1 is the 1st comparison on 1 at b1, and the term _Ia1Wb2 is the first comparison on 1 at b2. To see these as F tests, we use the test commands below and see they correspond to the results in the text on page 246.
test _Ia1Wb1

 ( 1)  _Ia1Wb1 = 0

       F(  1,    18) =    5.35
            Prob > F =    0.0328

test _Ia1Wb2

 ( 1)  _Ia1Wb2 = 0

       F(  1,    18) =    0.11
            Prob > F =    0.7450

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