UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Linear Statistical Models by Neter, Kutner, et. al.
Chapter 1: Linear Regression with One Predictor Variable

Inputting the Toluca Company data.
input x y
   80  399
   30  121
   50  221
   90  376
   70  361
   60  224
  120  546
   80  352
  100  353
   50  157
   40  160
   70  252
   90  389
   20  113
  110  435
  100  420
   30  212
   50  268
   90  377
  110  421
   30  273
   90  468
   40  244
   80  342
   70  323
end

label var x "lot size"
label var y "work hrs"
save toluca
Table 1.1, page 21.
quietly summarize x
generate xdif = x - r(mean)
quietly summarize y
generate ydif = y - r(mean)
generate crp = ydif*xdif
generate xdif2 = xdif^2
generate ydif2 = ydif^2

list

             x          y       xdif       ydif        crp      xdif2      ydif2
  1.        80        399         10      86.72      867.2        100   7520.358
  2.        30        121        -40    -191.28     7651.2       1600   36588.04
  3.        50        221        -20     -91.28     1825.6        400   8332.038
  4.        90        376         20      63.72     1274.4        400   4060.239
  5.        70        361          0      48.72          0          0   2373.638
  6.        60        224        -10     -88.28      882.8        100   7793.358
  7.       120        546         50     233.72      11686       2500   54625.04
  8.        80        352         10      39.72      397.2        100   1577.678
  9.       100        353         30      40.72     1221.6        900   1658.119
 10.        50        157        -20    -155.28     3105.6        400   24111.88
 11.        40        160        -30    -152.28     4568.4        900    23189.2
 12.        70        252          0     -60.28          0          0   3633.678
 13.        90        389         20      76.72     1534.4        400   5885.958
 14.        20        113        -50    -199.28       9964       2500   39712.52
 15.       110        435         40     122.72     4908.8       1600    15060.2
 16.       100        420         30     107.72     3231.6        900    11603.6
 17.        30        212        -40    -100.28     4011.2       1600   10056.08
 18.        50        268        -20     -44.28      885.6        400   1960.718
 19.        90        377         20      64.72     1294.4        400   4188.679
 20.       110        421         40     108.72     4348.8       1600   11820.04
 21.        30        273        -40     -39.28     1571.2       1600   1542.918
 22.        90        468         20     155.72     3114.4        400   24248.72
 23.        40        244        -30     -68.28     2048.4        900   4662.158
 24.        80        342         10      29.72      297.2        100   883.2784
 25.        70        323          0      10.72          0          0   114.9184
Figure 1.10, page 22.
graph twoway scatter y x, xlabel(0(50)150) ylabel(0(100)600)
graph twoway (scatter y x) (lfit y x), xlabel(0(50)150) ylabel(0(100)600)
Fig. 1.11, page 23.
regress y x


      Source |       SS       df       MS              Number of obs =      25
-------------+------------------------------           F(  1,    23) =  105.88
       Model |  252377.581     1  252377.581           Prob > F      =  0.0000
    Residual |  54825.4592    23  2383.71562           R-squared     =  0.8215
-------------+------------------------------           Adj R-squared =  0.8138
       Total |   307203.04    24  12800.1267           Root MSE      =  48.823

------------------------------------------------------------------------------
           y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           x |   3.570202   .3469722    10.29   0.000     2.852435    4.287969
       _cons |   62.36586   26.17743     2.38   0.026     8.213711     116.518
------------------------------------------------------------------------------
Table 1.2, page 24.
predict yhat
predict res, residual
generate res2 = res^2

list x y yhat res res2

             x          y       yhat        res       res2
  1.        80        399    347.982   51.01798   2602.834
  2.        30        121   169.4719  -48.47192   2349.527
  3.        50        221    240.876  -19.87596   395.0538
  4.        90        376   383.6841  -7.684041   59.04448
  5.        70        361     312.28      48.72   2373.638
  6.        60        224    276.578  -52.57798   2764.444
  7.       120        546   490.7901    55.2099   3048.133
  8.        80        352    347.982    4.01798   16.14416
  9.       100        353    419.386  -66.38606   4407.109
 10.        50        157    240.876  -83.87596   7035.177
 11.        40        160   205.1739  -45.17394   2040.685
 12.        70        252     312.28     -60.28   3633.678
 13.        90        389   383.6841   5.315959   28.25942
 14.        20        113   133.7699   -20.7699   431.3887
 15.       110        435   455.0881  -20.08808    403.531
 16.       100        420    419.386   .6139394   .3769216
 17.        30        212   169.4719   42.52808   1808.638
 18.        50        268    240.876   27.12404   735.7136
 19.        90        377   383.6841  -6.684041    44.6764
 20.       110        421   455.0881  -34.08808   1161.997
 21.        30        273   169.4719   103.5281   10718.06
 22.        90        468   383.6841   84.31596   7109.181
 23.        40        244   205.1739   38.82606   1507.463
 24.        80        342    347.982   -5.98202   35.78457
 25.        70        323     312.28      10.72   114.9184

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.