UCLA Academic Technology Services HomeServicesClassesContactJobs

Stata Textbook Examples
Applied Linear Statistical Models by Neter, Kutner, et. al.
Chapter 21: Two-Factor Studies--One Case Per Treatment

Inputting the Insurance Premium data.

input premium city region
  140  1  1
  100  1  2
  210  2  1
  180  2  2
  220  3  1
  200  3  2
end

Table 21.2a, p. 878.

table city region, contents(mean premium) col row
-------------------------------
          |       region       
     city |     1      2  Total
----------+--------------------
        1 |   140    100    120
        2 |   210    180    195
        3 |   220    200    210
          | 
    Total |   190    160    175
-------------------------------

Table 21.2b, p. 878.

anova premium city region
                           Number of obs =       6     R-squared     =  0.9907
                           Root MSE      = 7.07107     Adj R-squared =  0.9767

                  Source |  Partial SS    df       MS           F     Prob > F
              -----------+----------------------------------------------------
                   Model |       10650     3        3550      71.00     0.0139
                         |
                    city |        9300     2        4650      93.00     0.0106
                  region |        1350     1        1350      27.00     0.0351
                         |
                Residual |         100     2          50   
              -----------+----------------------------------------------------
                   Total |       10750     5        2150  

Fig. 21.1, p. 879.

twoway (line premium region if city==1, text(100 2.25 "Small City")) ///
(line premium region if city==2, text(175 2.25 "Medium City")) ///
(line premium region if city==3, text(200 2.25 "Large City")) ///
(scatter premium region, mcolor(navy)), legend(off) xlabel(1 "East" 2 "West") xscale(r(.5 2.5))

Predicting estimates of the treatment means, p. 881.
anova premium city region
predict predict
list city region premium predict, clean
       city   region   premium   predict  
  1.      1        1       140       135  
  2.      1        2       100       105  
  3.      2        1       210       210  
  4.      2        2       180       180  
  5.      3        1       220       225  
  6.      3        2       200       195  

Creating the dummy variables for city and region, p. 881.  Running the regression to get the factor effects alphai and betaj. When looking at the predict values from the regression we see that we get exactly the same values as from the anova.

gen x1 = 0
replace x1 =  1 if city==1
replace x1 = -1 if city==3
gen x2 = 0
replace x2 =  1 if city==2
replace x2 = -1 if city==3
gen x3 = -1
replace x3 =  1 if region==1
regress premium x1 x2 x3
predict pred
clist city region premium pred
      Source |       SS       df       MS              Number of obs =       6
-------------+------------------------------           F(  3,     2) =   71.00
       Model |       10650     3        3550           Prob > F      =  0.0139
    Residual |         100     2          50           R-squared     =  0.9907
-------------+------------------------------           Adj R-squared =  0.9767
       Total |       10750     5        2150           Root MSE      =  7.0711

------------------------------------------------------------------------------
     premium |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |        -55   4.082483   -13.47   0.005    -72.56551   -37.43449
          x2 |         20   4.082483     4.90   0.039     2.434494    37.56551
          x3 |         15   2.886751     5.20   0.035     2.579311    27.42069
       _cons |        175   2.886751    60.62   0.000     162.5793    187.4207
------------------------------------------------------------------------------
          city     region    premium       pred
  1.         1          1        140        135
  2.         1          2        100        105
  3.         2          1        210        210
  4.         2          2        180        180
  5.         3          1        220        225
  6.         3          2        200        195

Tukey test of Additivity for the insurance data, p. 884.  This figure uses nonadd, a user written program.  You can download it by typing findit nonadd (see How can I used the findit command to search for programs and get additional help? for more information about using findit).

nonadd premium city region
Tukey's test of nonadditivity (Ho: model is additive)
SS nonadd = 87.096774  df = 1
F (1,1) = 6.75   Pr > F: .23390805

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.