Announcement

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

  • Creating one line of code for logistic regression to reflect coefficients and odds ratio rather than two lines

    Hi
    I am wondering if there is a way or command to incorporate the two outputs e.g. coefficient and odds ratio for logistic regression. Currently, I have to do two lines. E.g. logit price income and logit price income, or It seems tedious that I would then need to put excel for the model without the odds ratio and then paste the columns into the other table's (coefficient) results. Typically we only care for the odds ratios because interpretting coefficients is difficult, but APA standards for some journals require reporting both coefficients and odds ratio in the table.
    Any suggestions?
    Thank you.
    Yours truly
    Lena Gan

  • #2
    If you install estout from SSC, you can take advantage of the -transform()- option, noting that the odds ratios are the exponentiated coefficients. Then export in CSV format which can be opened in MS Excel.

    Code:
    webuse lbw, clear
    eststo m1: logit low c.age##c.age i.race i.smoke
    esttab m1 m1, label transform(exp(@) exp(@), pattern(0 1)) ///
    mlab(Coef. OR, lhs(Variables)) eqlab(none) nobaselevels varwidth(30)
    Res.:

    Code:
    . esttab m1 m1, label transform(exp(@) exp(@), pattern(0 1)) ///
    > mlab(Coef. OR, lhs(Variables)) eqlab(none) nobaselevels varwidth(30)
    
    --------------------------------------------------------------
                                            (1)             (2)   
    Variables                             Coef.              OR   
    --------------------------------------------------------------
    age of mother                         0.311           1.365   
                                         (1.02)          (1.02)   
    
    age of mother # age of mother      -0.00722           0.993   
                                        (-1.13)         (-1.13)   
    
    black                                 1.058*          2.879*  
                                         (2.12)          (2.12)   
    
    other                                 1.042*          2.834*  
                                         (2.56)          (2.56)   
    
    smoker                                1.107**         3.024** 
                                         (2.95)          (2.95)   
    
    Constant                             -4.975         0.00691   
                                        (-1.39)         (-1.39)   
    --------------------------------------------------------------
    Observations                            189             189   
    --------------------------------------------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001

    Comment


    • #3
      Hi, I am trying to use this code (adapted from the answer above) for logit coefficients and odds ratios but I get a table with coefficients only, can someone help please?


      estimates clear

      *** Model 1: Treated + Strata Fixed Effects ***
      eststo m1: logit test Treated i.strata, vce(cluster sess)

      *** Model 2: Basic Controls ***
      eststo m2: logit test Treated marital mother masterdegree academic age stem i.strata, vce(cluster sess)

      *** Model 3: Additional Controls ***
      eststo m3: logit test Treated marital mother masterdegree academic age stem ib2.m_employ ib3.f_empl m_edu f_edu i.strata, vce(cluster sess)

      *** Export table with Coefficients (Panel A) and Odds Ratios (Panel B) ***
      esttab m1 m2 m3 using "${path}/TestResults_Panel.tex", ///
      replace label /// Use variable labels
      se b(3) /// Display standard errors and coefficients with 3 decimals
      transform(exp(@) exp(@) exp(@) exp(@) exp(@) exp(@) , pattern(0 0 0 1 1 1)) /// Exponentiate coefficients for odds ratios (Panel B)
      mlab("Logit Coefficients" "Logit Coefficients" "Logit Coefficients" "Odds Ratios" "Odds Ratios" "Odds Ratios", lhs("Variables")) ///
      eqlab(none) nobaselevels varwidth(30) ///
      booktabs ///
      keep(Treated) ///
      title("Test Takeup: Logit Coefficients & Odds Ratios")

      Comment


      • #4
        Code:
        esttab m1 m2 m3 m1 m2 m3 ...

        Comment


        • #5
          Thank you for your reply Andrew! Unfortunately also adding m1 m2 m3 again does not produce the right table, it gives me a table with the coefficients twice, rather than coefficients and odds ratios

          Comment


          • #6
            Try something like this: (building on Andrew's code in #2)

            Code:
            webuse lbw, clear
            eststo m1: logit low i.race i.smoke
            eststo m2: logit low c.age i.race i.smoke
            eststo m3: logit low c.age##c.age i.race i.smoke
            esttab m1 m1 m2 m2 m3 m3, label transform(exp(@), pattern(0 1 0 1 0 1)) ///
            mlab(Coef. OR Coef. OR Coef. OR, lhs(Variables)) eqlab(none) nobaselevels varwidth(30)
            which produces:

            Code:
            ------------------------------------------------------------------------------------------------------------------------------
                                                    (1)             (2)             (3)             (4)             (5)             (6)   
            Variables                             Coef.              OR           Coef.              OR           Coef.              OR   
            ------------------------------------------------------------------------------------------------------------------------------
            Black                                 1.084*          2.957*          1.011*          2.749*          1.058*          2.879*  
                                                 (2.21)          (2.21)          (2.05)          (2.05)          (2.12)          (2.12)   
            
            Other                                 1.109**         3.030**         1.057**         2.877**         1.042*          2.834*  
                                                 (2.77)          (2.77)          (2.60)          (2.60)          (2.56)          (2.56)   
            
            Smoker                                1.116**         3.053**         1.101**         3.006**         1.107**         3.024** 
                                                 (3.02)          (3.02)          (2.96)          (2.96)          (2.95)          (2.95)   
            
            Age of mother                                                       -0.0349           0.966           0.311           1.365   
                                                                                (-1.04)         (-1.04)          (1.02)          (1.02)   
            
            Age of mother # Age of mother                                                                      -0.00722           0.993   
                                                                                                                (-1.13)         (-1.13)   
            
            Constant                             -1.841***        0.159***       -1.008           0.365          -4.975         0.00691   
                                                (-5.22)         (-5.22)         (-1.17)         (-1.17)         (-1.39)         (-1.39)   
            ------------------------------------------------------------------------------------------------------------------------------
            Observations                            189             189             189             189             189             189   
            ------------------------------------------------------------------------------------------------------------------------------
            t statistics in parentheses
            * p<0.05, ** p<0.01, *** p<0.001

            Comment


            • #7
              It worked, thank you!!

              Comment

              Working...
              X