Announcement

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

  • saving logistic regression output as .dta file

    Dear Statalist

    I would like to save the output (odds ratio, ci, pval, se) of a simple logistic regression as a .dta file. I have tried using statsby, but cant work out how to save the output as odds ratios. I can view the output using r(table) - but cant work out how to save them as a .dta file. Any help would be much appreciated

    Best Wishes

    Joe

  • #2
    Odds ratios are just exponentiated (log odds) coefficients.

    Code:
    webuse lbw, clear
    logistic low age smoke ht i.race
    di _b[age]
    di exp(_b[age])
    Res.:

    Code:
    .
    . logistic low age smoke ht i.race
    
    Logistic regression                             Number of obs     =        189
                                                    LR chi2(5)        =      19.48
                                                    Prob > chi2       =     0.0016
    Log likelihood = -107.59429                     Pseudo R2         =     0.0830
    
    ------------------------------------------------------------------------------
             low | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .9642515   .0328974    -1.07   0.286     .9018823    1.030934
           smoke |   3.043852   1.144877     2.96   0.003     1.456341     6.36186
              ht |   3.260856   2.025573     1.90   0.057     .9651256    11.01741
                 |
            race |
          black  |   2.596016   1.297455     1.91   0.056     .9747382    6.913957
          other  |    2.91195   1.194677     2.61   0.009     1.303058    6.507347
                 |
           _cons |    .344826   .3025262    -1.21   0.225     .0617754    1.924796
    ------------------------------------------------------------------------------
    Note: _cons estimates baseline odds.
    
    .
    . di _b[age]
    -.03640311
    
    .
    . di exp(_b[age])
    .96425151

    The derivation of the standard errors is not that much more difficult. See my example in #11 of the following link:
    https://www.statalist.org/forums/for...ch-observation




    I can view the output using r(table) - but cant work out how to save them as a .dta file.
    You can save -r(table)- as a matrix and convert this to a dataset using svmat. See

    Code:
    help svmat
    Last edited by Andrew Musau; 17 Mar 2021, 08:15.

    Comment

    Working...
    X