Announcement

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

  • Export summary statistics using tabstat and estpost (esttab)

    Hello,

    after reading through the forum I found that esttab often causes issues. I hope you can help me with my problem.
    I am trying to create a table in stata and export it to Word. In Stata this works fine, but as soon as I export it all the data is lost.

    My data contains survey results. I have data from two groups (marked by either 1 or 2).

    This is how my table looks like in Stata:

    group | e(Y1_5) e(Y6_10) e(totalY) e(totalX)
    -------------+----------------------------------------------------------------
    1 | 2.886792 3.924528 6.811321 1.867925
    2 | 3.041667 3.8125 6.854167 1.708333

    Code:
     
    global list1 var1 var2 var3 var4
    global format1 rtf
    
    estpost tabstat $list1, by(group) stat(mean)
    esttab . using Table1.$format1, replace label cells("mean(fmt(%12.0fc)")
    1. I would like to have stata use my labels instead of variable names.
    2. I would like to export this into Word. So far I used the code (see above) but that did not work (i.e. I got an empty table).

    This is what I get in Word:
    (1)
    mean
    Observations 101

    Thank you so much in advance!

  • #2
    1. Your problem is unrelated to exporting to Word. A good first troubleshooting step with esttab is just dumping it to the Stata results window instead of exporting it to a file. You can do this by simply omitting using Table1.$format1 from the command.
    2. A second good troubleshooting step is copying from the documentation and modifying from there.
    3. cells() should be avoided with esttab when possible. It's an estout option, not an esttab option. It can work, but it can also cause unexpected behavior.
    Try this:
    Code:
    global list1 var1 var2 var3 var4
    global format1 rtf
    
    estpost tabstat $list1, by(group) columns(statistics)
    esttab . using Table1.$format1, main(mean %12.0fc) not nostar unstack nomtitle nonumber nonote noobs label replace
    To understand what all the options are for, I recommend removing the using Table1.$format1, and then dropping one option at a time and comparing the results.

    Comment


    • #3
      Hello Nils,

      thank you for your quick response. The thing is (and I should have been more clear about that) is that I can create the table in Stata and it looks like I want it to look like (see below for a screenshot). My problem is that I can't export this to either Word nor Excel. I tried estout and esttab but they give me empty sheets. I also removed any extra options and tried the command as is:

      Code:
      esttab . using Table1a.csv,  replace
      
      estout . using Table1a.csv,  replace
      The same goes for the rtf format. Female and group are both just a 0 or 1 dummy.

      Any further help would be very much appreciated.


      Click image for larger version

Name:	table_stata.JPG
Views:	1
Size:	34.7 KB
ID:	1343669

      Comment


      • #4
        I am confused by several things.

        The thing is (and I should have been more clear about that) is that I can create the table in Stata and it looks like I want it to look like (see below for a screenshot).
        Your screenshot shows the results-window output from tabstat, but not from esttab or estout. If you can coax esttab or estout to give you the desired results in the results window, then it should be trivial to export those results to an RTF or CSV.

        I tried estout and esttab but they give me empty sheets.
        In your first post, you got an RTF that was not empty. It had a model number, a dependent variable name, and a number of observations. Is this what you meant by "empty"?

        I also removed any extra options and tried the command as is: [...] The same goes for the rtf format. Female and group are both just a 0 or 1 dummy.
        Firstly, you will certainly not get the intended results without specifying the option main(mean). Secondly, I am unsure what the exact RTF results are from your description. The first RTF table you posted did not contain the words "female" or "group". Did this have something to do with the RTF/CSV export, or was it just additional information about your data?

        Please show me exactly what you run, and exactly what results you receive. I suggest removing using Table1.$format1 from the command, and showing me what esttab or estout writes to the results window. Copy the commands and results straight from the results window and paste them here in a code block. Once we have that figured out, exporting to RTF or CSV should be trivial.
        Last edited by Nils Enevoldsen; 02 Jun 2016, 08:19.

        Comment


        • #5
          Dear Nils,

          thank you for your answer! You are right I was a bit confusing again because I missunderstood what you wanted to see from me.
          To your comments:

          In your first post, you got an RTF that was not empty. It had a model number, a dependent variable name, and a number of observations. Is this what you meant by "empty"?
          Yes this is what I meant. I was a bit overdramatic. Empty is what I showed in my first screenshot.

          Firstly, you will certainly not get the intended results without specifying the option main(mean).
          Yes this was the problem all along! It was the cells command that was wrong. I feel a bit stupid now but this was all that was missing. With this added my exported table has now data in it. Thank you for your help!

          To close this subject here is the code I have now that works:

          Code:
          *create list
              global list2   q1_5 q6_10 total_scoreMC total_scoreOF
              
          *create Table1b with full data
          
              estpost tabstat $list2, by(female) stat(mean) col(stat)
              
              esttab . using Table1b.rtf,  main(mean) replace
          The result looks like this as a screenshot from my word file. I can work with that:

          Click image for larger version

Name:	table_word.JPG
Views:	1
Size:	20.9 KB
ID:	1343699

          Thanks again!

          Comment


          • #6
            Great! You're welcome. As I said in my first reply, you may want something more like
            Code:
            esttab . using Table1b.rtf, main(mean %12.0fc) not nostar unstack nomtitle nonumber nonote noobs label replace
            I'll leave the details up to you, though.

            Comment


            • #7
              Hello there,

              I realize that this is an older thread, but since my problem is so similar I thought I'd rather post here. I also want to export summary statistics to word/excel and I manage to get the following steps to work:

              1) estpost summarize Length DefaultStart DefaultEnd GDPgidy AvGDPgipd etc.

              2) esttab, cells("mean sd min max") nomtitle nonumber noobs

              3) esttab using Table1, main(mean) label replace

              However, while the table I get is beautiful, I would like to add 3 more columns with SD, min and max. Also, I would like to add a title e.g. title(Table 1. Summary statistics). I tried to add sd min max into the main() parenthesis, but it doesn't work.

              Any advice much appreciated.

              Comment


              • #8
                Hi Fabian,
                Not sure if this is too late. You could try combining the esttab commands. That is,

                esttab . using Table1.rtf, cells("mean sd min max") title("Table 1. Summary Statistics") nonumber noobs label replace

                This worked in my case for exporting a 4-column summary stats table to MS Word.

                Comment


                • #9
                  Dear friends, why it does not work when I use

                  Code:
                   
                   esttab . using Table1.$format1, main(sd %9.3fc) not nostar unstack nomtitle nonumber nonote noobs label replace
                  to format sd statistics?

                  Comment


                  • #10
                    I cannot transfer my tabstat table into excel:
                    estpost tabstat VA ort fa, stat(N mean median sd min max) by(sz_cls4) col(stat)
                    esttab using stataexample.xls

                    Comment

                    Working...
                    X