EC228: Example of linear regression
The Stata program
use auto,clear
summ mpg displacement weight foreign
gen displ2 = displacement^2
reg mpg displacement weight
reg mpg displacement weight displ2 foreign
test displ2 foreign
predict mpghat, xb
format mpghat %9.2f
sort mpg
list make mpg mpghat displacement weight foreign
graph mpg mpghat displacement, s(Oo) ti("MPG vs Dis, Dis^2, Wt, Foreign")
The Stata output
. use auto,clear
(1978 Automobile Data)
. summ mpg displacement weight foreign
Variable | Obs Mean Std. Dev. Min Max
-------------+-----------------------------------------------------
mpg | 74 21.2973 5.785503 12 41
displacement | 74 197.2973 91.83722 79 425
weight | 74 3019.459 777.1936 1760 4840
foreign | 74 .2972973 .4601885 0 1
. gen displ2 = displacement^2
. reg mpg displacement weight
Source | SS df MS Number of obs = 74
-------------+------------------------------ F( 2, 71) = 66.79
Model | 1595.40969 2 797.704846 Prob > F = 0.0000
Residual | 848.049768 71 11.9443629 R-squared = 0.6529
-------------+------------------------------ Adj R-squared = 0.6432
Total | 2443.45946 73 33.4720474 Root MSE = 3.4561
------------------------------------------------------------------------------
mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
displacement | .0052808 .0098696 0.54 0.594 -.0143986 .0249602
weight | -.0065671 .0011662 -5.63 0.000 -.0088925 -.0042417
_cons | 40.08452 2.02011 19.84 0.000 36.05654 44.11251
------------------------------------------------------------------------------
. reg mpg displacement weight displ2 foreign
Source | SS df MS Number of obs = 74
-------------+------------------------------ F( 4, 69) = 38.85
Model | 1692.14665 4 423.036664 Prob > F = 0.0000
Residual | 751.312805 69 10.8885914 R-squared = 0.6925
-------------+------------------------------ Adj R-squared = 0.6747
Total | 2443.45946 73 33.4720474 Root MSE = 3.2998
------------------------------------------------------------------------------
mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
displacement | -.0691733 .029221 -2.37 0.021 -.1274676 -.0108791
weight | -.0059021 .001172 -5.04 0.000 -.0082401 -.003564
displ2 | .0001353 .0000525 2.58 0.012 .0000307 .00024
foreign | -2.833556 1.173069 -2.42 0.018 -5.173763 -.4933481
_cons | 47.21469 3.07295 15.36 0.000 41.08432 53.34506
------------------------------------------------------------------------------
. test displ2 foreign
( 1) displ2 = 0.0
( 2) foreign = 0.0
F( 2, 69) = 4.44
Prob > F = 0.0153
. predict mpghat, xb
. format mpghat %9.2f
. sort mpg
. list make mpg mpghat displacement weight foreign
make mpg mpghat displa~t weight foreign
1. Linc. Mark V 12 13.34 400 4,720 Domestic
2. Linc. Continental 12 12.63 400 4,840 Domestic
3. Merc. XR-7 14 14.29 302 4,130 Domestic
4. Peugeot 604 14 16.52 163 3,420 Foreign
5. Cad. Eldorado 14 16.56 350 3,900 Domestic
6. Merc. Cougar 14 14.70 302 4,060 Domestic
7. Linc. Versailles 14 16.06 302 3,830 Domestic
8. Cad. Deville 14 16.70 425 4,330 Domestic
9. Merc. Marquis 15 16.71 302 3,720 Domestic
10. Buick Electra 15 15.50 350 4,080 Domestic
11. Olds Toronado 16 15.80 350 4,030 Domestic
12. Buick Riviera 16 15.56 231 3,880 Domestic
13. Chev. Impala 16 16.60 250 3,690 Domestic
14. Dodge Magnum 16 17.66 318 3,600 Domestic
15. Volvo 260 17 17.99 163 3,170 Foreign
16. Dodge St. Regis 17 16.43 225 3,740 Domestic
17. AMC Pacer 17 18.60 258 3,350 Domestic
18. Audi 5000 17 20.94 131 2,830 Foreign
19. Buick LeSabre 18 16.80 231 3,670 Domestic
20. Pont. Catalina 18 16.62 231 3,700 Domestic
21. Toyota Corona 18 21.78 134 2,670 Foreign
22. Dodge Diplomat 18 17.66 318 3,600 Domestic
23. Merc. Monarch 18 18.49 250 3,370 Domestic
24. Pont. Firebird 18 17.98 231 3,470 Domestic
25. Plym. Volare 18 18.85 225 3,330 Domestic
26. Olds Delta 88 18 16.68 231 3,690 Domestic
27. Toyota Celica 18 23.32 134 2,410 Foreign
28. Buick Skylark 19 18.39 231 3,400 Domestic
29. Pont. Phoenix 19 18.27 231 3,420 Domestic
30. Olds Cutl Supr 19 18.92 231 3,310 Domestic
31. Olds Omega 19 18.57 231 3,370 Domestic
32. Chev. Nova 19 18.14 250 3,430 Domestic
33. Pont. Grand Prix 19 19.51 231 3,210 Domestic
34. Olds Cutlass 19 18.98 231 3,300 Domestic
35. Pont. Le Mans 19 19.57 231 3,200 Domestic
36. Buick Regal 20 19.50 196 3,280 Domestic
37. Merc. Zephyr 20 23.48 140 2,830 Domestic
38. Buick Century 20 19.67 196 3,250 Domestic
39. Olds 98 21 15.62 350 4,060 Domestic
40. Cad. Seville 21 14.26 350 4,290 Domestic
41. Fiat Strada 21 26.04 105 2,130 Foreign
42. Datsun 810 21 20.94 146 2,750 Foreign
43. Ford Mustang 21 24.54 140 2,650 Domestic
44. Chev. Monte Carlo 22 19.79 200 3,220 Domestic
45. AMC Spirit 22 25.24 121 2,640 Domestic
46. Chev. Malibu 22 20.02 200 3,180 Domestic
47. Merc. Bobcat 22 24.96 140 2,580 Domestic
48. AMC Concord 22 23.53 121 2,930 Domestic
49. Audi Fox 23 26.73 97 2,070 Foreign
50. VW Dasher 23 26.20 97 2,160 Foreign
51. Datsun 200 23 24.08 119 2,370 Foreign
52. Pont. Sunbird 24 23.98 151 2,690 Domestic
53. Chev. Monza 24 23.62 151 2,750 Domestic
54. Olds Starfire 24 23.74 151 2,730 Domestic
55. Datsun 510 24 24.61 119 2,280 Foreign
56. Honda Accord 25 25.31 107 2,240 Foreign
57. Plym. Horizon 25 28.46 105 2,200 Domestic
58. VW Rabbit 25 27.91 89 1,930 Foreign
59. VW Scirocco 25 27.20 97 1,990 Foreign
60. BMW 320i 25 22.35 121 2,650 Foreign
61. Buick Opel 26 25.53 304 2,230 Domestic
62. Renault Le Car 26 28.96 79 1,830 Foreign
63. Plym. Sapporo 26 26.03 119 2,520 Domestic
64. Ford Fiesta 28 31.11 98 1,800 Domestic
65. Plym. Arrow 28 20.48 156 3,260 Domestic
66. Honda Civic 28 28.82 91 1,760 Foreign
67. Chev. Chevette 29 26.00 231 2,110 Domestic
68. Dodge Colt 30 29.22 98 2,120 Domestic
69. Mazda GLC 30 27.75 86 1,980 Foreign
70. Toyota Corolla 31 25.96 97 2,200 Foreign
71. Plym. Champ 34 31.64 86 1,800 Domestic
72. Datsun 210 35 27.56 85 2,020 Foreign
73. Subaru 35 26.85 97 2,050 Foreign
74. VW Diesel 41 27.21 90 2,040 Foreign
.
end of do-file