Announcement

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

  • Prediction out of sample using a data frame of coefficients

    Hi everyone,

    I have run an OLS regression on a different software than STATA and stored estimated coefficients. I want to use these estimated coefficients to make predictions in STATA. How can I do that?

    Thanks.

  • #2
    The easiest way is to estimate the model again in Stata. The OLS command is regress. In any case, predictions are straightforward in linear regression models.

    Code:
    sysuse auto, clear
    regress mpg price weight
    predict mpghat1, xb
    mat l e(b)
    gen mpghat2= (-.00009351*price) + (-.00581754*weight) + 39.439656
    format %9.3f mpghat1 mpghat2
    l mpghat1 mpghat2 in 1/10, sep(0)
    Res.:

    Code:
    . regress mpg price weight
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     66.85
           Model |  1595.93249         2  797.966246   Prob > F        =    0.0000
        Residual |  847.526967        71  11.9369995   R-squared       =    0.6531
    -------------+----------------------------------   Adj R-squared   =    0.6434
           Total |  2443.45946        73  33.4720474   Root MSE        =     3.455
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           price |  -.0000935   .0001627    -0.57   0.567     -.000418    .0002309
          weight |  -.0058175   .0006175    -9.42   0.000    -.0070489   -.0045862
           _cons |   39.43966   1.621563    24.32   0.000     36.20635    42.67296
    ------------------------------------------------------------------------------
    
    . 
    . predict mpghat1, xb
    
    . 
    . mat l e(b)
    
    e(b)[1,3]
             price      weight       _cons
    y1  -.00009351  -.00581754   39.439656
    
    . 
    . gen mpghat2= (-.00009351*price) + (-.00581754*weight) + 39.439656
    
    . 
    . format %9.3f mpghat1 mpghat2
    
    . 
    . l mpghat1 mpghat2 in 1/10, sep(0)
    
         +-------------------+
         | mpghat1   mpghat2 |
         |-------------------|
      1. |  22.011    22.011 |
      2. |  19.507    19.507 |
      3. |  23.726    23.726 |
      4. |  20.082    20.082 |
      5. |  14.972    14.972 |
      6. |  17.548    17.548 |
      7. |  26.050    26.050 |
      8. |  19.873    19.873 |
      9. |  15.898    15.898 |
     10. |  19.278    19.278 |
         +-------------------+

    Comment

    Working...
    X