Announcement

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

  • Putexcel command for logistic regression

    Hello there

    I'm trying to make a nice table for my logistic regression results using putexcel command but I couldn't find the scalars I need. The framework would be Odds ratio, 95% Confidence intervals and p-value.

    Now I ran the command:
    logit top i.gest_c, base level(95)

    and then ereturn list:

    scalars:
    e(rank) = 2
    e(N) = 1474
    e(ic) = 4
    e(k) = 3
    e(k_eq) = 1
    e(k_dv) = 1
    e(converged) = 1
    e(rc) = 0
    e(ll) = -889.8136445574683
    e(k_eq_model) = 1
    e(ll_0) = -922.7348412688314
    e(df_m) = 1
    e(chi2) = 65.84239342272622
    e(p) = 4.88461896337e-16
    e(N_cdf) = 0
    e(N_cds) = 0
    e(r2_p) = .0356778515766175

    macros:
    e(cmdline) : "logit top i.gest_c, base level(95)"
    e(cmd) : "logit"
    e(estat_cmd) : "logit_estat"
    e(predict) : "logit_p"
    e(marginsok) : "default Pr"
    e(marginsnotok) : "stdp DBeta DEviance DX2 DDeviance Hat Number Residuals RStandard SCore"
    e(title) : "Logistic regression"
    e(chi2type) : "LR"
    e(opt) : "moptimize"
    e(vce) : "oim"
    e(user) : "mopt__logit_d2()"
    e(ml_method) : "d2"
    e(technique) : "nr"
    e(which) : "max"
    e(depvar) : "top"
    e(properties) : "b V"

    matrices:
    e(b) : 1 x 3
    e(V) : 3 x 3
    e(Cns) : 1 x 4
    e(mns) : 1 x 3
    e(rules) : 1 x 4
    e(ilog) : 1 x 20
    e(gradient) : 1 x 3

    I couldn't fine what I need to export the results

    thanks

  • #2
    It would seem much easier to use esttab (Stata Journal, authored by Ben Jann) or a related command to export the estimation results rather than coding it in putexcel.

    Code:
    findit esttab

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      It would seem much easier to use esttab (Stata Journal, authored by Ben Jann) or a related command to export the estimation results rather than coding it in putexcel.

      Code:
      findit esttab
      You are totally right. Can I be selective of what I'm exporting? I only need 5 things (unadjusted/adjusted ORs & CIs) plus the final p-value.

      Thanks much

      Comment


      • #4
        The results you are looking for are actually in r(table) -- if you type
        Code:
        return list
        as opposed to
        Code:
        ereturn list
        it will pop up. You can then extract the ORs, pvalues and upper and lower bounds from that matrix.

        Comment


        • #5
          Originally posted by Isaac Maddow-Zimet View Post
          The results you are looking for are actually in r(table) -- if you type
          Code:
          return list
          as opposed to
          Code:
          ereturn list
          it will pop up. You can then extract the ORs, pvalues and upper and lower bounds from that matrix.
          Hi Isaac, Thanks for your help. How can I extract the scalars from the matrix? any tips? thanks !

          Comment


          • #6
            Something like below?

            Code:
            webuse lbw
            logit low age lwt i.race
            esttab using myfile.xls, ci scalars(N r2_p)



            Code:
            . esttab, ci scalars(N r2_p)
            
            --------------------------------------
                                            (1)   
                                            low   
            --------------------------------------
            low                                   
            age                         -0.0256   
                               [-0.0907,0.0396]   
            
            lwt                         -0.0143*  
                             [-0.0271,-0.00155]   
            
            1.race                            0   
                                          [0,0]   
            
            2.race                        1.003*  
                                 [0.0274,1.979]   
            
            3.race                        0.444   
                                 [-0.262,1.150]   
            
            _cons                         1.305   
                                 [-0.792,3.401]   
            --------------------------------------
            N                               189   
            r2_p                         0.0511   
            --------------------------------------
            95% confidence intervals in brackets
            * p<0.05, ** p<0.01, *** p<0.001

            You can specify more options, add more stats, etc. See

            Code:
            help esttab

            Comment


            • #7
              If you prefer the putexcel route, it would be something like below:

              Code:
              webuse lbw
              logistic low age lwt i.race
              mat temp = r(table)'
              mat results = temp[1..., "b"], temp[1..., "ll"], temp[1..., "ul"], temp[1..., "pvalue"]
              mat list results
              You can then putexcel the full matrix to excel (assuming you've already "putexcel set" the excel sheet, it would just be something like:

              Code:
              putexcel A1 = matrix(results), names

              Comment

              Working...
              X