Announcement

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

  • Exporting data from Logs Into Excel

    Hi All,
    I'm trying to export some of my survey data from Stata to excel. I currently have Stata capturing logs of the output, but would much prefer an excel sheet of my data. I noticed that there is an Export feature in the GUI (see https://www.stata.com/features/overv...mport-export/#) , but this seems to require one to enter the expressions manually and is very cumbersome. The GUI also displays the code used per action, but this is not compatible with many functions. For example, the following errored out.

    Code:
    . putexcel (A1) = (tab acaint expansion), overwritefmt
    tab not found r(111);
    I attached a log of an example of data I'm trying to export into excel directly.

    For the above that I attempted in the excel export GUI, this is the code I would have run if it were stata directly exporting to a log:
    Code:
    tab acaint expansion

    Thank you!


    Attached Files

  • #2
    Save the log file as SMCL, not text. You can then open the log file, select a table, right-click and "Copy table", and paste the table to Excel.

    For a solution with putexcel, read "Export tables to Excel" from the Stata blog.

    Comment


    • #3
      That actually worked surprisingly well for all fields except some, where two cells are joined as one (see attached image). Any solution for that? Thanks!
      Click image for larger version

Name:	Screen Shot 2017-09-17 at 11.24.14.png
Views:	1
Size:	35.5 KB
ID:	1410771

      Comment


      • #4
        Could you share the commands that create such a table in the log file?

        Comment


        • #5
          Sorry!

          Code:
          proportion hlthpln1, over(acaint)
          
          Proportion estimation             Number of obs   =  1,024,928
          
                _prop_1: hlthpln1 = 0
                _prop_2: hlthpln1 = 1
          
                      0: acaint = 0
                      1: acaint = 1
          
          --------------------------------------------------------------
                       |                                   Logit
                  Over | Proportion   Std. Err.     [95% Conf. Interval]
          -------------+------------------------------------------------
          _prop_1      |
                     0 |   .1584305   .0005014      .1574502    .1594158
                     1 |   .1021603   .0004306      .1013194    .1030073
          -------------+------------------------------------------------
          _prop_2      |
                     0 |   .8415695   .0005014      .8405842    .8425498
                     1 |   .8978397   .0004306      .8969927    .8986806
          --------------------------------------------------------------
          
          . 
          end of do-file






          Comment


          • #6
            The "Copy Table" process is, as Ameen has discovered, fallible. Sometimes where you expect a tab, there are just spaces and that messes things up.

            I think what would work more reliably than trying to export results from log files to a spreadsheet is to do it directly when the program generating the log files is running. For example, after the -proportion- command, Ameen can capture all of those results by running -matrix M = r(table)-. He probably would prefer to export the transpose of M so that it looks like the output in the Results window. So -matrix M = M'- handles that. Then he can send that to his spreadsheet with -putexcel-.

            Comment

            Working...
            X