Announcement

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

  • help with -esttab- (how to show variable names in csv output)

    Hello,

    I recently learned how to use -esttab- to export my regression output in csv format but I cannot figure out to how to get the csv output to contain variable names. In the attached example output (csv output attached), I can see only variable labels but not the variable names. Can someone please advise how to get the variable names to show in the csv output?

    Currently, the csv/excel output looks like this:
    Table 1. Odds ratios
    Model 1
    birthweight<2500g
    age of mother 0.966 (0.0323)
    white 1 (.)
    black 2.749* (1.357)
    other 2.877** (1.168)
    smoked during pregnancy 3.006** (1.118)

    I want the csv/excel output to show variable names like this:
    low
    birthweight<2500g
    age
    age of mother 0.966 (0.0323)
    race
    white 1 (.)
    black 2.749* (1.357)
    other 2.877** (1.168)
    smoke
    smoked during pregnancy 3.006** (1.118)

    My current Stata code is:

    * data
    webuse lbw // opening data

    * logit
    logit low age i.race smoke, or // regression
    estimates store M1 // store output


    * export
    esttab M1 using esttab_test.csv, eform se ///
    replace label wide ///
    title(Table 1. Odds ratios) /// table title
    nonumber mtitles("Model 1") /// labels for columns
    addnotes("Source: lbw") // note at bottom of table


    Thank you in advance for your time!
    Attached Files
    Last edited by Irina Chukhray; 24 May 2021, 19:05.

  • #2
    esttab is from the Stata Journal (FAQ Advice #12).

    I can see only variable labels but not the variable names. Can someone please advise how to get the variable names to show in the csv output?
    You specified the -label- option in your command. Remove it.

    Comment


    • #3

      Andrew Musau, thank you for the suggestion. Unfortunately, when I remove the -label- option, the variable names still do not show.

      With -label- option removed, my csv/excel output looks like this:
      Table 1. Odds ratios
      Model 1
      low
      age 0.966 (0.0323)
      1.race 1 (.)
      2.race 2.749* (1.357)
      3.race 2.877** (1.168)
      smoke 3.006** (1.118)



      Comment


      • #4
        Unfortunately, when I remove the -label- option, the variable names still do not show.
        What is your definition of a variable name? In the birthweight dataset, "age" is a variable name and its variable label is "age of mother". Paying more attention to #1, It appears that you want both the variable name and variable label displayed. This is unusual as most people opt for either, but it is certainly doable. A combination of the options -refcat- -mlabels- and -collabels- will do it. Changes highlighted in red.

        Code:
        * data
        webuse lbw // opening data
        
        * logit
        logit low age i.race smoke, or // regression
        estimates store M1 // store output
        
        * export
        esttab M1, refcat(1.race {bf:race} age {bf:age} smoke {bf:smoke}, nolabel ) ///
        replace  wide label collabels(coefficient "std. err.", lhs(`:var lab `e(depvar)'')) ///
        title(Table 1. Odds ratios) eqlabel(none)  mlabels( "" , lhs({bf:`e(depvar)'})) ///
        nonumber eform se addnotes("Source: lbw")
        Res.:

        Code:
        Table 1. Odds ratios
        -------------------------------------------------
        low                                        
        birthweight<2500g     coefficient       std. err.
        -------------------------------------------------
        age                                       
        age of mother               0.966        (0.0323)
        race                                        
        white                           1             (.)
        black                       2.749*        (1.357)
        other                       2.877**       (1.168)
        smoke                                      
        smoked during preg~y        3.006**       (1.118)
        -------------------------------------------------
        Observations                  189                
        -------------------------------------------------
        Exponentiated coefficients; Standard errors in parentheses
        Source: lbw
        * p<0.05, ** p<0.01, *** p<0.001
        Last edited by Andrew Musau; 26 May 2021, 01:40.

        Comment


        • #5
          Andrew Musau : this works great!! Thank you so much! I also really appreciate how you showed the changes in red, made it very easy to follow! The reason I need both the variable name and variable label is because for my full dataset, I have many yes/no variables (from survey questions)...the output simply shows coefficients for "yes" and "no" variables repeatedly without the variable names, which makes it difficult to interpret. Now, it is very easy with both the variable names and labels. Thank you!

          QUESTION: when I search "help esttab," I do not see the options you added such as "refcat" and "eqlabel"...would you mind sharing where I can find these options?

          Comment


          • #6
            QUESTION: when I search "help esttab," I do not see the options you added such as "refcat" and "eqlabel"...would you mind sharing where I can find these options?
            esttab is a wrapper program for estout. You actually don't need to separately install esttab if you have installed estout - as it (and other related programs e.g., eststo, estpost, etc.) is bundled with the installation. So these are estout options. See

            Code:
            help estout

            Comment

            Working...
            X