UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Linear Statistical Models by Neter, Kutner, et. al.
Chapter 16: Single Factor Anova Model and Tests

Inputting the Kenton Food Company data, table 16.1, page 677.
clear
input sales design store
  11  1  1
  17  1  2
  16  1  3
  14  1  4
  15  1  5
  12  2  1
  10  2  2
  15  2  3
  19  2  4
  11  2  5
  23  3  1
  20  3  2
  18  3  3
  17  3  4
  27  4  1
  33  4  2
  22  4  3
  26  4  4
  28  4  5
 end
Calculating the factor means and the grand mean.
tabstat sales, statistics(sum mean n) by(design)

Summary for variables: sales
     by categories of: design 

  design |       sum      mean         N
---------+------------------------------
       1 |        73      14.6         5
       2 |        67      13.4         5
       3 |        78      19.5         4
       4 |       136      27.2         5
---------+------------------------------
   Total |       354  18.63158        19
----------------------------------------
Figure 16.3, page 677.
graph twoway scatter design sales, ylabel(0(1)4) xlabel(0(10)40)
Anova table for the Kenton Food data including tests, pages 683-686.
anova sales design 

                           Number of obs =      19     R-squared     =  0.7881
                           Root MSE      = 3.24756     Adj R-squared =  0.7457

                  Source |  Partial SS    df       MS           F     Prob > F
              -----------+----------------------------------------------------
                   Model |  588.221053     3  196.073684      18.59     0.0000
                         |
                  design |  588.221053     3  196.073684      18.59     0.0000
                         |
                Residual |      158.20    15  10.5466667   
              -----------+----------------------------------------------------
                   Total |  746.421053    18  41.4678363  
Obtaining the residuals from the anova model of the Kenton Food data, table 16.2, page 680.
predict r, resid
list design store r

        design      store          r 
  1.         1          1       -3.6  
  2.         1          2        2.4  
  3.         1          3        1.4  
  4.         1          4        -.6  
  5.         1          5         .4  
  6.         2          1       -1.4  
  7.         2          2       -3.4  
  8.         2          3        1.6  
  9.         2          4        5.6  
 10.         2          5       -2.4  
 11.         3          1        3.5  
 12.         3          2         .5  
 13.         3          3       -1.5  
 14.         3          4       -2.5  
 15.         4          1        -.2  
 16.         4          2        5.8  
 17.         4          3       -5.2  
 18.         4          4       -1.2  
 19.         4          5         .8  
Calculating the treatment effect (taui) for the Incentive pay example, page 694.
di (70+58+90+84)/4
75.5

di 70-75.5
-5.5

di 58-75.5
-17.5

di 90-75.5
14.5

di 84-75.5
8.5
Applying deviation coding to the variable design in the Kenton Food Company data to be used in the regression approach, page 698. For more information on deviation and other coding schemes please see http://www.ats.ucla.edu/stat/stata/webbooks/reg/chapter5/statareg5.htm
gen x1=0
replace x1=1 if design==1
replace x1=-1 if design==4
(5 real changes made)

gen x2=0 
replace x2=1 if design==2
replace x2=-1 if design==4
(5 real changes made)

gen x3=0 
replace x3=1 if design==3
replace x3=-1 if design==4
(5 real changes made)

list sales design store x1-x3

         sales     design      store         x1         x2         x3 
  1.        11          1          1          1          0          0  
  2.        17          1          2          1          0          0  
  3.        16          1          3          1          0          0  
  4.        14          1          4          1          0          0  
  5.        15          1          5          1          0          0  
  6.        12          2          1          0          1          0  

<output omitted>

 18.        26          4          4         -1         -1         -1  
 19.        28          4          5         -1         -1         -1  

reg sales x1 x2 x3

      Source |       SS       df       MS              Number of obs =      19
-------------+------------------------------           F(  3,    15) =   18.59
       Model |  588.221053     3  196.073684           Prob > F      =  0.0000
    Residual |      158.20    15  10.5466667           R-squared     =  0.7881
-------------+------------------------------           Adj R-squared =  0.7457
       Total |  746.421053    18  41.4678363           Root MSE      =  3.2476

------------------------------------------------------------------------------
       sales |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |     -4.075    1.27081    -3.21   0.006    -6.783668   -1.366332
          x2 |     -5.275    1.27081    -4.15   0.001    -7.983668   -2.566332
          x3 |       .825   1.370629     0.60   0.556    -2.096427    3.746427
       _cons |     18.675   .7485263    24.95   0.000     17.07955    20.27045
------------------------------------------------------------------------------

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.