Announcement

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

  • Exporting results from "table" command to csv

    I have a seemingly simple question that I find no good solution to.

    I am creating a table in stata running a command that looks like this:

    Code:
    table var1 var2 [pw=weight], statistic(mean var3) nformat(%8.3g) statistic(freq)
    and I want to send the table that is displayed in the results window toa csv-file, so that when I change something in the data and run the command again, I don's have to manually change all the numbers or copy-and-paste and format everything again. Surprisingly, I cannot find a way to do this in a convenient way. The closest fit was created using logfile,

    Code:
    cd "$OUT"
    logout, save("test.csv") excel replace: table var1 var2 [pw=weight], contents(mean var3 freq)
    but that creates a table in csv where I have to manually reformat a lot. I have also unsuccessfully tried using tabout, estout, putdocx and putexcel. The main problem seems to be that table doesn't save any information other than the number of observations in r(), so it seems impossible to extract the information I want and write it to a csv file.

    Maybe someone had this problem already and found a good solution? Any advice would be highly appreciated.

  • #2
    After table you can use collect export to export the table to a variety of formats. csv is not one of those, but maybe the others are even closer to what you need.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you so much for your quick and perfect answer! This works unbelievably well and may be my new favourite command!

      Comment

      Working...
      X