UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

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

Inputting the data shown on page 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 x1 "targtpop"
label var x2 "dispoinc"
Creating the x1x2 variable to be used in Fig. 6.7.
generate x1x2 = x1*x2
Figure 6.4a, page 237. Scatterplot matrix.
graph matrix y x1 x2, half
Fig. 6.4b, p. 237. Correlation matrix.
summarize y x1 x2

    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
           y |      21    181.9048    36.1913      137.2      244.2
          x1 |      21    62.01905   18.62033       38.4       91.3
          x2 |      21    17.14286   .9703461       15.8       19.1

corr y x1 x2
(obs=21)

             |        y       x1       x2
-------------+---------------------------
           y |   1.0000
          x1 |   0.9446   1.0000
          x2 |   0.8358   0.7813   1.0000
Fig. 6.5a and b, p. 241.
regress y x1 x2

      Source |       SS       df       MS              Number of obs =      21
-------------+------------------------------           F(  2,    18) =   99.10
       Model |  24015.2826     2  12007.6413           Prob > F      =  0.0000
    Residual |  2180.92749    18  121.162638           R-squared     =  0.9167
-------------+------------------------------           Adj R-squared =  0.9075
       Total |  26196.2101    20   1309.8105           Root MSE      =  11.007

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |    1.45456   .2117818     6.87   0.000     1.009623    1.899497
          x2 |   9.365501   4.063958     2.30   0.033     .8274414    17.90356
       _cons |  -68.85708   60.01695    -1.15   0.266     -194.948    57.23386
------------------------------------------------------------------------------

predict fitted
predict resid, rresid
Show all variables, including fitted and residual as shown in Fig. 6.5b, p. 24.
list y x1 x2 fitted resid

             y         x1         x2     fitted      resid
  1.     174.4       68.5       16.7   187.1841  -12.78413
  2.     164.4       45.2       16.8   154.2294   10.17057
  3.     244.2       91.3       18.2   234.3963   9.803662
  4.     154.6       47.8       16.3   153.3285   1.271483
  5.     181.6       46.9       17.3   161.3849   20.21508
  6.     207.5       66.1       18.2   197.7414   9.758573
  7.     152.8       49.5       15.9   152.0551   .7449242
  8.     163.2         52       17.2   167.8666  -4.666642
  9.     145.4       48.9       16.6   157.7382  -12.33821
 10.     137.2       38.4         16    136.846   .3539732
 11.     241.9       87.9       18.3   230.3874   11.51263
 12.     191.1       72.8       17.1   197.1849  -6.084922
 13.       232       88.4       17.4   222.6857   9.314301
 14.     145.3       42.9       15.8   141.5184    3.78156
 15.     161.1       52.5       17.8   174.2132   -13.1132
 16.     209.7       85.7       18.4   228.1239  -18.42389
 17.     146.4       41.3       16.5    145.747   .6530005
 18.       144       51.7       16.3   159.0013  -15.00131
 19.     232.6       89.6       18.1    230.987   1.612983
 20.     224.1       82.7       19.1   230.3161  -6.216054
 21.     166.5       52.3         16   157.0644   9.435602
Figure 6.7, page 246, showing 4 different diagnostic plots.
rvfplot, ylabel(-25(10)25) xlabel(120(50)270)
rvpplot x1, ylabel(-25(10)25) xlabel(30(10)100)
rvpplot x2, ylabel(-25(10)25) xlabel(15(1)20)
graph twoway scatter resid x1x2, ylabel(-25(10)25) xlabel(500(500)2000)
Figure 6.8a, page 247.
generate absresid = abs(resid)

graph twoway scatter absresid fitted, ylabel(0(5)25) xlabel(120(50)270)
Figure 6.8b, page 247, normal quantile plot.
qnorm resid, ylabel(-30(10)30) xlabel(-30(10)30)
Estimation of Mean Response and Prediction Limits for New Observations, p. 249-251.
Adding extra lines of data in order to predict.
clear
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
  65.4  17.6    .  
  53.1  17.7    .  
end
Getting the predicted value and the CI's for E[Yh] and Yh(new), p. 249-251.
Upper and Lower CLMean is for E[Yh] and Upper and Lower CL is for Yh(new). Note: This includes observation 22 and 23.
regress y x1 x2 

      Source |       SS       df       MS              Number of obs =      21
-------------+------------------------------           F(  2,    18) =   99.10
       Model |  24015.2826     2  12007.6413           Prob > F      =  0.0000
    Residual |  2180.92749    18  121.162638           R-squared     =  0.9167
-------------+------------------------------           Adj R-squared =  0.9075
       Total |  26196.2101    20   1309.8105           Root MSE      =  11.007

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
          x1 |    1.45456   .2117818     6.87   0.000     1.009623    1.899497
          x2 |   9.365501   4.063958     2.30   0.033     .8274414    17.90356
       _cons |  -68.85708   60.01695    -1.15   0.266     -194.948    57.23386
------------------------------------------------------------------------------

predict fitted
predict resid, resid
predict stdp, stdp
predict stdf, stdf
generate umean = fitted+2.101*stdp
generate lmean = fitted -2.101*stdp
generate upre = fitted+2.101*stdf
generate lpre = fitted-2.101*stdf

list y fitted lmean umean lpre upre resid

             y     fitted      lmean      umean       lpre       upre      resid
  1.     174.4   187.1841   179.1144   195.2539   162.6901   211.6782  -12.78413
  2.     164.4   154.2294   146.7588   161.7001   129.9262   178.5326   10.17057
  3.     244.2   234.3963   224.7565   244.0361   209.3412   259.4515   9.803662
  4.     154.6   153.3285   146.5358   160.1212   129.2251    177.432   1.271483
  5.     181.6   161.3849   152.0774   170.6924   136.4557   186.3141   20.21508
  6.     207.5   197.7414   188.5421   206.9408   172.8524   222.6305   9.758573
  7.     152.8   152.0551   143.2948   160.8153    127.325   176.7852   .7449242
  8.     163.2   167.8666   160.8681   174.8651   143.7044   192.0289  -4.666642
  9.     145.4   157.7382   151.5134    163.963   133.7886   181.6878  -12.33821
 10.     137.2    136.846   128.4265   145.2656   112.2345   161.4575   .3539732
 11.     241.9   230.3874   221.5607   239.2141   205.6336   255.1411   11.51263
 12.     191.1   197.1849   190.0186   204.3513   172.9735   221.3963  -6.084922
 13.       232   222.6857   211.3806   233.9908   196.9439   248.4275   9.314301
 14.     145.3   141.5184   132.7499    150.287   116.7854   166.2515    3.78156
 15.     161.1   174.2132    163.629   184.7975   148.7797   199.6467   -13.1132
 16.     209.7   228.1239   219.4649   236.7829   203.4295   252.8183  -18.42389
 17.     146.4    145.747   137.9038   153.5902   121.3267   170.1673   .6530005
 18.       144   159.0013    152.167   165.8357   134.8861   183.1165  -15.00131
 19.     232.6    230.987   221.7056   240.2685   206.0675   255.9065   1.612983
 20.     224.1   230.3161    218.105   242.5271   204.1637   256.4684  -6.216054
 21.     166.5   157.0644    148.494   165.6347   132.4009   181.7279   9.435602
 22.         .   191.1039   185.2909    196.917    167.258   214.9499          .
 23.         .   174.1494   164.4877   183.8111   149.0858    199.213          .
 
predict rsta, rsta
predict rstu, rstu
predict cooksd, cooksd

list rsta rstu cooksd 

          rsta       rstu     cooksd
  1.  -1.23931  -1.259317   .0709783
  2.  .9763196   .9749785   .0370185
  3.  .9798224   .9786732    .067294
  4.  .1208419   .1174848   .0004596
  5.  2.006145    2.21261    .259292
  6.  .9662861   .9644076   .0585049
  7.  .0731241   .0710744   .0002986
  8. -.4448118  -.4346749   .0066487
  9. -1.163855  -1.176185   .0352674
 10.  .0345273   .0335556   .0000607
 11.   1.13156    1.14101   .0727753
 12. -.5814227  -.5704232   .0119696
 13.   .969979   .9682962   .0984742
 14.  .3712687   .3621978   .0077142
 15. -1.339868  -1.372351    .158554
 16. -1.805076  -1.938412   .1770856
 17.  .0630611   .0612912   .0001723
 18. -1.426554  -1.472072   .0649107
 19.  .1599861   .1555892   .0016381
 20. -.6649696  -.6543212   .0569788
 21.  .9229192   .9189219   .0451999
 22.         .          .          .
 23.         .          .          .

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