UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Linear Statistical Models by Neter, Kutner, et. al.
Chapter 7: Multiple Regression II

Table 7.1, p. 261.
input x1 x2 x3 y
  19.5  43.1  29.1  11.9
  24.7  49.8  28.2  22.8
  30.7  51.9  37.0  18.7
  29.8  54.3  31.1  20.1
  19.1  42.2  30.9  12.9
  25.6  53.9  23.7  21.7
  31.4  58.5  27.6  27.1
  27.9  52.1  30.6  25.4
  22.1  49.9  23.2  21.3
  25.5  53.5  24.8  19.3
  31.1  56.6  30.0  25.4
  30.4  56.7  28.3  27.2
  18.7  46.5  23.0  11.7
  19.7  44.2  28.6  17.8
  14.6  42.7  21.3  12.8
  29.5  54.4  30.1  23.9
  27.7  55.3  25.7  22.6
  30.2  58.6  24.6  25.4
  22.7  48.2  27.1  14.8
  25.2  51.0  27.5  21.1
end

label var x1 "Triceps" 
label var x2 "Thigh cir."
label var x3 "Midarm cir."
label var  y "body fat"

save chch7tab01
Table 7.2, p. 262-263.
regress y x1

      Source |       SS       df       MS              Number of obs =      20
-------------+------------------------------           F(  1,    18) =   44.30
       Model |  352.269824     1  352.269824           Prob > F      =  0.0000
    Residual |  143.119689    18  7.95109386           R-squared     =  0.7111
-------------+------------------------------           Adj R-squared =  0.6950
       Total |  495.389513    19  26.0731323           Root MSE      =  2.8198

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |   .8571866   .1287808     6.66   0.000     .5866282    1.127745
       _cons |  -1.496107   3.319235    -0.45   0.658     -8.46956    5.477347
------------------------------------------------------------------------------

regress y x2

      Source |       SS       df       MS              Number of obs =      20
-------------+------------------------------           F(  1,    18) =   60.62
       Model |  381.965845     1  381.965845           Prob > F      =  0.0000
    Residual |  113.423669    18  6.30131492           R-squared     =  0.7710
-------------+------------------------------           Adj R-squared =  0.7583
       Total |  495.389513    19  26.0731323           Root MSE      =  2.5102

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x2 |   .8565467   .1100156     7.79   0.000     .6254124    1.087681
       _cons |  -23.63449   5.657414    -4.18   0.000    -35.52028   -11.74871
------------------------------------------------------------------------------

regress y x1 x2

      Source |       SS       df       MS              Number of obs =      20
-------------+------------------------------           F(  2,    17) =   29.80
       Model |  385.438738     2  192.719369           Prob > F      =  0.0000
    Residual |  109.950775    17  6.46769267           R-squared     =  0.7781
-------------+------------------------------           Adj R-squared =  0.7519
       Total |  495.389513    19  26.0731323           Root MSE      =  2.5432

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |   .2223526   .3034389     0.73   0.474    -.4178475    .8625527
          x2 |   .6594218   .2911873     2.26   0.037     .0450704    1.273773
       _cons |  -19.17425    8.36064    -2.29   0.035    -36.81366   -1.534839
------------------------------------------------------------------------------

regress y x1-x3

      Source |       SS       df       MS              Number of obs =      20
-------------+------------------------------           F(  3,    16) =   21.52
       Model |  396.984607     3  132.328202           Prob > F      =  0.0000
    Residual |  98.4049068    16  6.15030667           R-squared     =  0.8014
-------------+------------------------------           Adj R-squared =  0.7641
       Total |  495.389513    19  26.0731323           Root MSE      =    2.48

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |   4.334085   3.015511     1.44   0.170    -2.058512    10.72668
          x2 |  -2.856842   2.582015    -1.11   0.285    -8.330468    2.616785
          x3 |  -2.186056   1.595499    -1.37   0.190    -5.568362     1.19625
       _cons |   117.0844   99.78238     1.17   0.258    -94.44474    328.6136
------------------------------------------------------------------------------
Table 7.4, p. 267.The first test is for the example of testing one variable, p. 269. The second test is for the example of testing two variables at once, p. 270-271.
test x3

 ( 1)  x3 = 0.0

       F(  1,    16) =    1.88
            Prob > F =    0.1896

test x2 x3

 ( 1)  x2 = 0.0
 ( 2)  x3 = 0.0

       F(  2,    16) =    3.64
            Prob > F =    0.0500
Coefficients of partial determination, p. 275.
ry1.2 and ry2.1 are from the first model. ry3.12 is the coefficient from X3 in the second model.
pcorr y x1 x2
(obs=20)

Partial correlation of y with

    Variable |    Corr.     Sig.
-------------+------------------
          x1 |   0.1750    0.474
          x2 |   0.4814    0.037
          
display 0.1750^2
.30625

display 0.4814^2
.23174596

pcorr y x1-x3
(obs=20)

Partial correlation of y with

    Variable |    Corr.     Sig.
-------------+------------------
          x1 |   0.3381    0.170
          x2 |  -0.2666    0.285
          x3 |  -0.3241    0.190
          
display 0.3381^2
.11431161

display -0.2666^2
-.07107556

display -0.3241^2
-.10504081
Inputting the Dwaine Studio Data from Ch. 6, Table 5 (p. 241).
input x1 x2 y
  68.5  16.7  174.4
  45.2  16.8  164.4
  91.3  18.2  244.2
  47.8  16.3  154.6
  46.9  17.3  181.6
  66.1  18.2  207.5
  49.5  15.9  152.8
  52.0  17.2  163.2
  48.9  16.6  145.4
  38.4  16.0  137.2
  87.9  18.3  241.9
  72.8  17.1  191.1
  88.4  17.4  232.0
  42.9  15.8  145.3
  52.5  17.8  161.1
  85.7  18.4  209.7
  41.3  16.5  146.4
  51.7  16.3  144.0
  89.6  18.1  232.6
  82.7  19.1  224.1
  52.3  16.0  166.5
end

label var  y  "sales"
label var x1 "targtpop"
label var x2 "dispoinc"
Creating the standardized variables of the Dwaine Studios Data, p. 282. Table 7.5b, p. 283.
egen yprime = std(y)
egen x1prime = std(x1)
egen x2prime = std(x2)

list yprime x1prime x2prime

        yprime    x1prime    x2prime
  1. -.2073638   .3480579  -.4563901
  2. -.4836733  -.9032627  -.3533356
  3.  1.721276   1.572526    1.08945
  4. -.7544563  -.7636304  -.8686157
  5. -.0084207  -.8119646   .1619444
  6.  .7072207   .2191664    1.08945
  7. -.8041921  -.6723323  -1.280839
  8. -.5168304  -.5380704     .05889
  9. -1.008661  -.7045551  -.5594465
 10. -1.235235  -1.268455  -1.177783
 11.  1.657725    1.38993   1.192505
 12.  .2540733   .5789885  -.0441664
 13.  1.384179   1.416782   .2650008
 14. -1.011424  -1.026784  -1.383895
 15. -.5748551  -.5112181   .6772245
 16.  .7680086   1.271779   1.295561
 17. -.9810303  -1.112711  -.6625029
 18. -1.047344  -.5541818  -.8686157
 19.  1.400758   1.481228   .9863937
 20.  1.165895   1.110665   2.016954
 21. -.4256482  -.5219591  -1.177783

regress yprime x1prime x2prime, beta

      Source |       SS       df       MS              Number of obs =      21
-------------+------------------------------           F(  2,    18) =   99.10
       Model |  18.3349289     2  9.16746445           Prob > F      =  0.0000
    Residual |  1.66507101    18  .092503945           R-squared     =  0.9167
-------------+------------------------------           Adj R-squared =  0.9075
       Total |  19.9999999    20  .999999995           Root MSE      =  .30414

------------------------------------------------------------------------------
      yprime |      Coef.   Std. Err.      t    P>|t|                     Beta
-------------+----------------------------------------------------------------
     x1prime |   .7483669   .1089611     6.87   0.000                 .7483669
     x2prime |   .2511039   .1089611     2.30   0.033                 .2511039
       _cons |  -4.72e-09   .0663698    -0.00   1.000                        .
------------------------------------------------------------------------------
Inputting the data of the Work Crew data.
input x1 x2 y
  4  2  42
  4  2  39
  4  3  48
  4  3  51
  6  2  49
  6  2  53
  6  3  61
  6  3  60
end

label var x1 "Crew size"
label var x2 "Bonus Pay"
label var y "Crew productivity"
Table 7.6, p. 286.
list

            x1         x2          y
  1.         4          2         42
  2.         4          2         39
  3.         4          3         48
  4.         4          3         51
  5.         6          2         49
  6.         6          2         53
  7.         6          3         61
  8.         6          3         60
Table 7.7, p. 287.
regress y x1 x2

      Source |       SS       df       MS              Number of obs =       8
-------------+------------------------------           F(  2,     5) =   57.06
       Model |      402.25     2     201.125           Prob > F      =  0.0004
    Residual |      17.625     5       3.525           R-squared     =  0.9580
-------------+------------------------------           Adj R-squared =  0.9412
       Total |     419.875     7  59.9821429           Root MSE      =  1.8775

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |      5.375   .6637959     8.10   0.000     3.668658    7.081342
          x2 |       9.25   1.327592     6.97   0.001     5.837317    12.66268
       _cons |       .375   4.740451     0.08   0.940    -11.81072    12.56072
------------------------------------------------------------------------------

regress y x1

      Source |       SS       df       MS              Number of obs =       8
-------------+------------------------------           F(  1,     6) =    7.35
       Model |     231.125     1     231.125           Prob > F      =  0.0351
    Residual |      188.75     6  31.4583333           R-squared     =  0.5505
-------------+------------------------------           Adj R-squared =  0.4755
       Total |     419.875     7  59.9821429           Root MSE      =  5.6088

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |      5.375   1.983001     2.71   0.035     .5227722    10.22723
       _cons |       23.5   10.11136     2.32   0.059    -1.241604     48.2416
------------------------------------------------------------------------------

regress y x2

      Source |       SS       df       MS              Number of obs =       8
-------------+------------------------------           F(  1,     6) =    4.13
       Model |     171.125     1     171.125           Prob > F      =  0.0885
    Residual |      248.75     6  41.4583333           R-squared     =  0.4076
-------------+------------------------------           Adj R-squared =  0.3088
       Total |     419.875     7  59.9821429           Root MSE      =  6.4388

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x2 |       9.25   4.552929     2.03   0.088    -1.890617    20.39062
       _cons |      27.25   11.60774     2.35   0.057    -1.153112    55.65311
------------------------------------------------------------------------------
Fig. 7.3, p. 290. The graph matrix command can be used for making a scatterplot matrix.
input x1 x2 x3 y
  19.5  43.1  29.1  11.9
  24.7  49.8  28.2  22.8
  30.7  51.9  37.0  18.7
  29.8  54.3  31.1  20.1
  19.1  42.2  30.9  12.9
  25.6  53.9  23.7  21.7
  31.4  58.5  27.6  27.1
  27.9  52.1  30.6  25.4
  22.1  49.9  23.2  21.3
  25.5  53.5  24.8  19.3
  31.1  56.6  30.0  25.4
  30.4  56.7  28.3  27.2
  18.7  46.5  23.0  11.7
  19.7  44.2  28.6  17.8
  14.6  42.7  21.3  12.8
  29.5  54.4  30.1  23.9
  27.7  55.3  25.7  22.6
  30.2  58.6  24.6  25.4
  22.7  48.2  27.1  14.8
  25.2  51.0  27.5  21.1
end

label var x1 "Triceps" 
label var x2 "Thigh cir."
label var x3 "Midarm cir."
label var  y "body fat"
  
graph matrix x1 x2 x3, half
Showing correlations of x1 to x3.
corr x1-x3
(obs=20)

             |       x1       x2       x3
-------------+---------------------------
          x1 |   1.0000
          x2 |   0.9238   1.0000
          x3 |   0.4578   0.0847   1.0000
Inputting data in table 7.9, p. 302.
input y x1 x2
  150  0.6  10
   86  1.0  10
   49  1.4  10
  288  0.6  20
  157  1.0  20
  131  1.0  20
  184  1.0  20
  109  1.4  20
  279  0.6  30
  235  1.0  30
  224  1.4  30
end

label var  y "cycles"
label var x1 "Charge rate"
label var x2 "Temperature"

/* Creating new variables */

generate   lx1 = round((x1-1)/.4,1)
generate   lx2 = round((x2-20)/10,1)
generate lx1sq = lx1^2
generate lx2sq = lx2^2
generate lx1x2 = lx1*lx2
generate  x1sq = x1^2
generate  x2sq = x2^2
Correlations at the bottom of page 302.
corr x1 x1sq x2 x2sq lx1 lx1sq lx2 lx2sq
(obs=11)

             |       x1     x1sq       x2     x2sq      lx1    lx1sq      lx2    lx2sq
-------------+------------------------------------------------------------------------
          x1 |   1.0000
        x1sq |   0.9910   1.0000
          x2 |   0.0000   0.0000   1.0000
        x2sq |   0.0000   0.0059   0.9861   1.0000
         lx1 |   1.0000   0.9910   0.0000   0.0000   1.0000
       lx1sq |   0.0000   0.1336   0.0000   0.0443   0.0000   1.0000
         lx2 |   0.0000   0.0000   1.0000   0.9861   0.0000   0.0000   1.0000
       lx2sq |   0.0000   0.0356   0.0000   0.1662   0.0000   0.2667   0.0000   1.0000
Table 7.9, p. 303.
list y x1 x2 x1sq x2sq

             y         x1         x2       x1sq       x2sq
  1.       150         .6         10        .36        100
  2.        86          1         10          1        100
  3.        49        1.4         10       1.96        100
  4.       288         .6         20        .36        400
  5.       157          1         20          1        400
  6.       131          1         20          1        400
  7.       184          1         20          1        400
  8.       109        1.4         20       1.96        400
  9.       279         .6         30        .36        900
 10.       235          1         30          1        900
 11.       224        1.4         30       1.96        900

list lx1 lx2 lx1sq lx2sq lx1x2

           lx1        lx2      lx1sq      lx2sq      lx1x2
  1.        -1         -1          1          1          1
  2.         0         -1          0          1          0
  3.         1         -1          1          1         -1
  4.        -1          0          1          0          0
  5.         0          0          0          0          0
  6.         0          0          0          0          0
  7.         0          0          0          0          0
  8.         1          0          1          0          0
  9.        -1          1          1          1         -1
 10.         0          1          0          1          0
 11.         1          1          1          1          1

summarize x1 x2

    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
          x1 |      11           1   .3098386         .6        1.4
          x2 |      11          20   7.745967         10         30
Table 7.7, p. 304.,Fig. 7.8a-7.8c, p. 304.

Test1 is the Partial F-test on p. 306.
regress y lx1 lx2 lx1sq lx2sq lx1x2

      Source |       SS       df       MS              Number of obs =      11
-------------+------------------------------           F(  5,     5) =   10.57
       Model |  55365.5614     5  11073.1123           Prob > F      =  0.0109
    Residual |   5240.4386     5  1048.08772           R-squared     =  0.9135
-------------+------------------------------           Adj R-squared =  0.8271
       Total |    60606.00    10     6060.60           Root MSE      =  32.374

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         lx1 |  -55.83333    13.2167    -4.22   0.008    -89.80795   -21.85871
         lx2 |       75.5    13.2167     5.71   0.002     41.52538    109.4746
       lx1sq |   27.39474   20.34008     1.35   0.236     -24.8911    79.68058
       lx2sq |  -10.60526   20.34008    -0.52   0.624     -62.8911    41.68058
       lx1x2 |       11.5   16.18709     0.71   0.509    -30.11024    53.11024
       _cons |   162.8421   16.60761     9.81   0.000     120.1509    205.5333
------------------------------------------------------------------------------

predict resid, resid

test lx1sq lx2sq lx1x2

 ( 1)  lx1sq = 0.0
 ( 2)  lx2sq = 0.0
 ( 3)  lx1x2 = 0.0

       F(  3,     5) =    0.78
            Prob > F =    0.5527
Fig. 7.8a, p. 304.
rvfplot, ylabel(-40(20)60) xlabel(0(100)300)
Fig. 7.8b, p. 304.
rvpplot lx1, ylabel(-40(20)60) xlabel(-2(1)2)
Fig. 7.8c, p. 304.
rvpplot lx2, ylabel(-40(20)60) xlabel(-2(1)2)
Fig. 7.8d, p. 304.
qnorm resid, ylabel(-50(20)50) xlabel(-60(20)60)
First Order Models using transformed and not transformed variables, p. 306 and p. 307.
regress y lx1 lx2

      Source |       SS       df       MS              Number of obs =      11
-------------+------------------------------           F(  2,     8) =   27.48
       Model |  52905.6667     2  26452.8333           Prob > F      =  0.0003
    Residual |  7700.33333     8  962.541667           R-squared     =  0.8729
-------------+------------------------------           Adj R-squared =  0.8412
       Total |    60606.00    10     6060.60           Root MSE      =  31.025

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         lx1 |  -55.83333   12.66584    -4.41   0.002    -85.04082   -26.62584
         lx2 |       75.5   12.66584     5.96   0.000     46.29251    104.7075
       _cons |        172   9.354346    18.39   0.000     150.4288    193.5712
------------------------------------------------------------------------------

regress y x1 x2

      Source |       SS       df       MS              Number of obs =      11
-------------+------------------------------           F(  2,     8) =   27.48
       Model |  52905.6667     2  26452.8333           Prob > F      =  0.0003
    Residual |  7700.33333     8  962.541667           R-squared     =  0.8729
-------------+------------------------------           Adj R-squared =  0.8412
       Total |    60606.00    10     6060.60           Root MSE      =  31.025

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |  -139.5833   31.66461    -4.41   0.002    -212.6021   -66.56461
          x2 |       7.55   1.266584     5.96   0.000     4.629251    10.47075
       _cons |   160.5833   41.61545     3.86   0.005     64.61794    256.5487
------------------------------------------------------------------------------
Creating centered variables for the Body Fat dataset from table 7.1, p. 261.
clear
input x1 x2 x3 y
  19.5  43.1  29.1  11.9
  24.7  49.8  28.2  22.8
  30.7  51.9  37.0  18.7
  29.8  54.3  31.1  20.1
  19.1  42.2  30.9  12.9
  25.6  53.9  23.7  21.7
  31.4  58.5  27.6  27.1
  27.9  52.1  30.6  25.4
  22.1  49.9  23.2  21.3
  25.5  53.5  24.8  19.3
  31.1  56.6  30.0  25.4
  30.4  56.7  28.3  27.2
  18.7  46.5  23.0  11.7
  19.7  44.2  28.6  17.8
  14.6  42.7  21.3  12.8
  29.5  54.4  30.1  23.9
  27.7  55.3  25.7  22.6
  30.2  58.6  24.6  25.4
  22.7  48.2  27.1  14.8
  25.2  51.0  27.5  21.1
end

egen my = mean(y)
egen mx1 = mean(x1)
egen mx2 = mean(x2)
egen mx3 = mean(x3)

generate cy = y - my
generate cx1 = x1 - mx1
generate cx2 = x2 - mx2
generate cx3 = x3 - mx3

generate cx1x2 = cx1*cx2
generate cx1x3 = cx1*cx3
generate cx2x3 = cx2*cx3
Fitting the Regression model (7.93), p. 315. The test of cx1x2 cx1x3 cx2x3 is the test of the interaction terms.
regress y cx1 cx2 cx3 cx1x2 cx1x3 cx2x3

      Source |       SS       df       MS              Number of obs =      20
-------------+------------------------------           F(  6,    13) =   10.07
       Model |  407.699483     6  67.9499138           Prob > F      =  0.0003
    Residual |  87.6900304    13  6.74538696           R-squared     =  0.8230
-------------+------------------------------           Adj R-squared =  0.7413
       Total |  495.389513    19  26.0731323           Root MSE      =  2.5972

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         cx1 |   3.437794   3.578665     0.96   0.354    -4.293441    11.16903
         cx2 |  -2.094706   3.036769    -0.69   0.502    -8.655245    4.465834
         cx3 |   -1.61633    1.90721    -0.85   0.412    -5.736607    2.503947
       cx1x2 |   .0088755   .0308505     0.29   0.778    -.0577729    .0755238
       cx1x3 |  -.0847909   .0734178    -1.15   0.269    -.2434004    .0738186
       cx2x3 |   .0904155   .0920013     0.98   0.344    -.1083413    .2891723
       _cons |    20.5269   1.073625    19.12   0.000     18.20747    22.84632
------------------------------------------------------------------------------

test cx1x2 cx1x3 cx2x3

 ( 1)  cx1x2 = 0.0
 ( 2)  cx1x3 = 0.0
 ( 3)  cx2x3 = 0.0

       F(  3,    13) =    0.53
            Prob > F =    0.6699

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