Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating regression tables

    Hello,
    I would greatly appreciate some help with this:

    My code is
    Code:
    regress y x
    predict y_hat, xb
    1) How would I generate a table of y_hat and x?
    2) What is the command for the above for quadratic regression?

    Thank you and help would be much appreciated!

  • #2
    Code:
    . sysuse auto
    (1978 automobile data)
    
    .
    . reg price mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =     20.26
           Model |   139449474         1   139449474   Prob > F        =    0.0000
        Residual |   495615923        72  6883554.48   R-squared       =    0.2196
    -------------+----------------------------------   Adj R-squared   =    0.2087
           Total |   635065396        73  8699525.97   Root MSE        =    2623.7
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
           _cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
    ------------------------------------------------------------------------------
    
    . margins, over(mpg)
    
    Predictive margins                                          Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    Over:       mpg
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |
             12  |   8386.329    580.115    14.46   0.000      7229.89    9542.767
             14  |    7908.54   492.9858    16.04   0.000     6925.791    8891.289
             15  |   7669.645   452.4789    16.95   0.000     6767.645    8571.646
             16  |   7430.751   414.8176    17.91   0.000     6603.827    8257.675
             17  |   7191.857   380.8469    18.88   0.000     6432.652    7951.061
             18  |   6952.962   351.6381    19.77   0.000     6251.985     7653.94
             19  |   6714.068   328.4641    20.44   0.000     6059.287    7368.849
             20  |   6475.174   312.6695    20.71   0.000     5851.879    7098.469
             21  |   6236.279   305.4014    20.42   0.000     5627.473    6845.086
             22  |   5997.385   307.2655    19.52   0.000     5384.862    6609.908
             23  |   5758.491   318.1013    18.10   0.000     5124.367    6392.614
             24  |   5519.596   337.0446    16.38   0.000      4847.71    6191.482
             25  |   5280.702   362.8277    14.55   0.000     4557.418    6003.986
             26  |   5041.808   394.1105    12.79   0.000     4256.163    5827.453
             28  |   4564.019   468.5982     9.74   0.000     3629.886    5498.152
             29  |   4325.125   510.0649     8.48   0.000     3308.329     5341.92
             30  |    4086.23   553.5182     7.38   0.000     2982.812    5189.649
             31  |   3847.336   598.5256     6.43   0.000     2654.197    5040.475
             34  |   3130.653   739.9933     4.23   0.000     1655.503    4605.803
             35  |   2891.759   788.6556     3.67   0.000     1319.602    4463.915
             41  |   1458.392   1089.322     1.34   0.185    -713.1316    3629.917
    ------------------------------------------------------------------------------
    
    .
    . reg price c.mpg##c.mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     18.28
           Model |   215835615         2   107917807   Prob > F        =    0.0000
        Residual |   419229781        71  5904644.81   R-squared       =    0.3399
    -------------+----------------------------------   Adj R-squared   =    0.3213
           Total |   635065396        73  8699525.97   Root MSE        =    2429.9
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -1265.194   289.5443    -4.37   0.000    -1842.529   -687.8593
                 |
     c.mpg#c.mpg |   21.36069   5.938885     3.60   0.001     9.518891    33.20249
                 |
           _cons |   22716.48   3366.577     6.75   0.000     16003.71    29429.24
    ------------------------------------------------------------------------------
    
    . margins, over(mpg)
    
    Predictive margins                                          Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    Over:       mpg
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |
             12  |   10610.09   819.1036    12.95   0.000      8976.84    12243.33
             14  |   9190.453   579.2238    15.87   0.000     8035.514    10345.39
             15  |   8544.719   484.5764    17.63   0.000     7578.501    9510.937
             16  |   7941.707   409.6147    19.39   0.000     7124.958    8758.455
             17  |   7381.415   356.6444    20.70   0.000     6670.287    8092.544
             18  |   6863.845   326.6177    21.01   0.000     6212.588    7515.102
             19  |   6388.997    317.355    20.13   0.000     5756.209    7021.785
             20  |   5956.869   323.4583    18.42   0.000     5311.912    6601.827
             21  |   5567.464   338.5018    16.45   0.000      4892.51    6242.417
             22  |   5220.779   357.2207    14.61   0.000     4508.501    5933.057
             23  |   4916.816   376.2432    13.07   0.000     4166.608    5667.024
             24  |   4655.574   393.8924    11.82   0.000     3870.175    5440.973
             25  |   4437.054   409.8054    10.83   0.000     3619.925    5254.183
             26  |   4261.255   424.6535    10.03   0.000      3414.52     5107.99
             28  |   4037.821    457.996     8.82   0.000     3124.603    4951.039
             29  |   3990.187   481.4974     8.29   0.000     3030.108    4950.265
             30  |   3985.273   513.4196     7.76   0.000     2961.543    5009.003
             31  |   4023.081   556.4856     7.23   0.000      2913.48    5132.682
             34  |   4392.833   769.9765     5.71   0.000     2857.544    5928.123
             35  |   4601.527   871.4917     5.28   0.000     2863.822    6339.232
             41  |   6750.837   1784.108     3.78   0.000     3193.426    10308.25
    ------------------------------------------------------------------------------
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Originally posted by Maarten Buis View Post
      Code:
      . sysuse auto
      (1978 automobile data)
      
      .
      . reg price mpg
      
      Source | SS df MS Number of obs = 74
      -------------+---------------------------------- F(1, 72) = 20.26
      Model | 139449474 1 139449474 Prob > F = 0.0000
      Residual | 495615923 72 6883554.48 R-squared = 0.2196
      -------------+---------------------------------- Adj R-squared = 0.2087
      Total | 635065396 73 8699525.97 Root MSE = 2623.7
      
      ------------------------------------------------------------------------------
      price | Coefficient Std. err. t P>|t| [95% conf. interval]
      -------------+----------------------------------------------------------------
      mpg | -238.8943 53.07669 -4.50 0.000 -344.7008 -133.0879
      _cons | 11253.06 1170.813 9.61 0.000 8919.088 13587.03
      ------------------------------------------------------------------------------
      
      . margins, over(mpg)
      
      Predictive margins Number of obs = 74
      Model VCE: OLS
      
      Expression: Linear prediction, predict()
      Over: mpg
      
      ------------------------------------------------------------------------------
      | Delta-method
      | Margin std. err. t P>|t| [95% conf. interval]
      -------------+----------------------------------------------------------------
      mpg |
      12 | 8386.329 580.115 14.46 0.000 7229.89 9542.767
      14 | 7908.54 492.9858 16.04 0.000 6925.791 8891.289
      15 | 7669.645 452.4789 16.95 0.000 6767.645 8571.646
      16 | 7430.751 414.8176 17.91 0.000 6603.827 8257.675
      17 | 7191.857 380.8469 18.88 0.000 6432.652 7951.061
      18 | 6952.962 351.6381 19.77 0.000 6251.985 7653.94
      19 | 6714.068 328.4641 20.44 0.000 6059.287 7368.849
      20 | 6475.174 312.6695 20.71 0.000 5851.879 7098.469
      21 | 6236.279 305.4014 20.42 0.000 5627.473 6845.086
      22 | 5997.385 307.2655 19.52 0.000 5384.862 6609.908
      23 | 5758.491 318.1013 18.10 0.000 5124.367 6392.614
      24 | 5519.596 337.0446 16.38 0.000 4847.71 6191.482
      25 | 5280.702 362.8277 14.55 0.000 4557.418 6003.986
      26 | 5041.808 394.1105 12.79 0.000 4256.163 5827.453
      28 | 4564.019 468.5982 9.74 0.000 3629.886 5498.152
      29 | 4325.125 510.0649 8.48 0.000 3308.329 5341.92
      30 | 4086.23 553.5182 7.38 0.000 2982.812 5189.649
      31 | 3847.336 598.5256 6.43 0.000 2654.197 5040.475
      34 | 3130.653 739.9933 4.23 0.000 1655.503 4605.803
      35 | 2891.759 788.6556 3.67 0.000 1319.602 4463.915
      41 | 1458.392 1089.322 1.34 0.185 -713.1316 3629.917
      ------------------------------------------------------------------------------
      
      .
      . reg price c.mpg##c.mpg
      
      Source | SS df MS Number of obs = 74
      -------------+---------------------------------- F(2, 71) = 18.28
      Model | 215835615 2 107917807 Prob > F = 0.0000
      Residual | 419229781 71 5904644.81 R-squared = 0.3399
      -------------+---------------------------------- Adj R-squared = 0.3213
      Total | 635065396 73 8699525.97 Root MSE = 2429.9
      
      ------------------------------------------------------------------------------
      price | Coefficient Std. err. t P>|t| [95% conf. interval]
      -------------+----------------------------------------------------------------
      mpg | -1265.194 289.5443 -4.37 0.000 -1842.529 -687.8593
      |
      c.mpg#c.mpg | 21.36069 5.938885 3.60 0.001 9.518891 33.20249
      |
      _cons | 22716.48 3366.577 6.75 0.000 16003.71 29429.24
      ------------------------------------------------------------------------------
      
      . margins, over(mpg)
      
      Predictive margins Number of obs = 74
      Model VCE: OLS
      
      Expression: Linear prediction, predict()
      Over: mpg
      
      ------------------------------------------------------------------------------
      | Delta-method
      | Margin std. err. t P>|t| [95% conf. interval]
      -------------+----------------------------------------------------------------
      mpg |
      12 | 10610.09 819.1036 12.95 0.000 8976.84 12243.33
      14 | 9190.453 579.2238 15.87 0.000 8035.514 10345.39
      15 | 8544.719 484.5764 17.63 0.000 7578.501 9510.937
      16 | 7941.707 409.6147 19.39 0.000 7124.958 8758.455
      17 | 7381.415 356.6444 20.70 0.000 6670.287 8092.544
      18 | 6863.845 326.6177 21.01 0.000 6212.588 7515.102
      19 | 6388.997 317.355 20.13 0.000 5756.209 7021.785
      20 | 5956.869 323.4583 18.42 0.000 5311.912 6601.827
      21 | 5567.464 338.5018 16.45 0.000 4892.51 6242.417
      22 | 5220.779 357.2207 14.61 0.000 4508.501 5933.057
      23 | 4916.816 376.2432 13.07 0.000 4166.608 5667.024
      24 | 4655.574 393.8924 11.82 0.000 3870.175 5440.973
      25 | 4437.054 409.8054 10.83 0.000 3619.925 5254.183
      26 | 4261.255 424.6535 10.03 0.000 3414.52 5107.99
      28 | 4037.821 457.996 8.82 0.000 3124.603 4951.039
      29 | 3990.187 481.4974 8.29 0.000 3030.108 4950.265
      30 | 3985.273 513.4196 7.76 0.000 2961.543 5009.003
      31 | 4023.081 556.4856 7.23 0.000 2913.48 5132.682
      34 | 4392.833 769.9765 5.71 0.000 2857.544 5928.123
      35 | 4601.527 871.4917 5.28 0.000 2863.822 6339.232
      41 | 6750.837 1784.108 3.78 0.000 3193.426 10308.25
      ------------------------------------------------------------------------------
      Hey Maarten, thank you so much for this! The linear regression makes sense to me.

      Would you be able to give me some more clarity on the quadratic regression bit?
      As in how would I regress y and x quadratically and obtain the x vs predicted table?

      Thank you again

      Comment


      • #4
        That is the second regression model in my example. For more type in Stata help fvvarlist
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X