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

Please Note: the code on this page has been updated to Stata 12
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. Let's start by running the basic anova from chapter 10.
use http://www.ats.ucla.edu/stat/stata/examples/da/chap10, clear

anova errors a b a#b

                           Number of obs =      24     R-squared     =  0.4590
                           Root MSE      = 4.28174     Adj R-squared =  0.3087

                  Source |  Partial SS    df       MS           F     Prob > F
              -----------+----------------------------------------------------
                   Model |         280     5          56       3.05     0.0361
                         |
                       a |         112     2          56       3.05     0.0721
                       b |          24     1          24       1.31     0.2675
                     a#b |         144     2          72       3.93     0.0384
                         |
                Residual |         330    18  18.3333333   
              -----------+----------------------------------------------------
                   Total |         610    23  26.5217391
On page 234 Keppel shows a comparison comparing group a1 with group a3 We create a variable acomp1 that compares group a1 with group a3.
contrast {a 1 0 -1}, effects

Contrasts of marginal linear predictions

Margins      : asbalanced

------------------------------------------------
             |         df           F        P>F
-------------+----------------------------------
           a |          1        5.45     0.0313
             |
    Residual |         18
------------------------------------------------

------------------------------------------------------------------------------
             |   Contrast   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           a |
        (1)  |         -5   2.140872    -2.34   0.031    -9.497805   -.5021946
------------------------------------------------------------------------------
On page 241, Keppel shows how to perform tests of simple main effects testing the effect of A at b1 and b2.
contrast a@b,effects

Contrasts of marginal linear predictions

Margins      : asbalanced

------------------------------------------------
             |         df           F        P>F
-------------+----------------------------------
         a@b |
          1  |          2        6.76     0.0064
          2  |          2        0.22     0.8061
      Joint  |          4        3.49     0.0281
             |
    Residual |         18
------------------------------------------------

--------------------------------------------------------------------------------
               |   Contrast   Std. Err.      t    P>|t|     [95% Conf. Interval]
---------------+----------------------------------------------------------------
           a@b |
(2 vs base) 1  |          7    3.02765     2.31   0.033     .6391426    13.36086
(2 vs base) 2  |          1    3.02765     0.33   0.745    -5.360857    7.360857
(3 vs base) 1  |         11    3.02765     3.63   0.002     4.639143    17.36086
(3 vs base) 2  |         -1    3.02765    -0.33   0.745    -7.360857    5.360857
--------------------------------------------------------------------------------
Page 246 shows how to do a simple comparison.
* means of a @ b1

margins a, at(b=1)

Adjusted predictions                              Number of obs   =         24

Expression   : Linear prediction, predict()
at           : b               =           1

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           a |
          1  |          3   2.140872     1.40   0.161    -1.196032    7.196032
          2  |         10   2.140872     4.67   0.000     5.803968    14.19603
          3  |         14   2.140872     6.54   0.000     9.803968    18.19603
------------------------------------------------------------------------------

contrast {a 1 -1 0}@1.b, effects

Contrasts of marginal linear predictions

Margins      : asbalanced

------------------------------------------------
             |         df           F        P>F
-------------+----------------------------------
         a@b |
      (1) 1  |          1        5.35     0.0328
             |
    Residual |         18
------------------------------------------------

------------------------------------------------------------------------------
             |   Contrast   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         a@b |
      (1) 1  |         -7    3.02765    -2.31   0.033    -13.36086   -.6391426
------------------------------------------------------------------------------

 means of a @ b2

margins a, at(b=2)

Adjusted predictions                              Number of obs   =         24

Expression   : Linear prediction, predict()
at           : b               =           2

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           a |
          1  |         11   2.140872     5.14   0.000     6.803968    15.19603
          2  |         12   2.140872     5.61   0.000     7.803968    16.19603
          3  |         10   2.140872     4.67   0.000     5.803968    14.19603
------------------------------------------------------------------------------

contrast {a 1 -1 0}@2.b, effects

Contrasts of marginal linear predictions

Margins      : asbalanced

------------------------------------------------
             |         df           F        P>F
-------------+----------------------------------
         a@b |
      (1) 2  |          1        0.11     0.7450
             |
    Residual |         18
------------------------------------------------

------------------------------------------------------------------------------
             |   Contrast   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         a@b |
      (1) 2  |         -1    3.02765    -0.33   0.745    -7.360857    5.360857
------------------------------------------------------------------------------




How to cite this page

Report an error on this page or leave a comment

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.