Announcement

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

  • Esttab results into different MS Excel sheets

    Hello, Statalist!

    I am working on a project where I need to do "summaries" and "ttest" of many variables and copy and paste them into a spreadsheet. Since, I am working with many of these I would like to save results directly to many excel sheets.

    I found a similar problem here: https://www.statalist.org/forums/for...fferent-sheets and I tried to adapt it to my problem.

    Here is the code I used --thanks to Eric Booth on the thread cited above:
    Code:
    clear all
    sysuse auto, clear
      cap rm `"myfile.xlsx"' //get rid of main excel file
    
    *create 5 summary tables
    foreach v in mpg turn head trunk rep78 {
    estpost sum `v' 
    eststo summ_`v'
    esttab summ_`v' ///
           using `"example_`v'.xls"', ///
           replace cells("count mean sd min max") ///
           nomtitles nonumber nostar ///
           title(Table 1. Summary Statistics)
    }
    
    **insheet them and then save to excel in sheets:
    foreach v in mpg turn head trunk rep78 {
    preserve
      insheet using `"example_`v'.xls"', clear nonames
      export excel using `"myfile.xlsx"', sheetreplace sheet("`v'")
      rm `"example_`v'.xls"'  //get rid of extra files
    restore
    }
    It works partially: it saved the output to excel sheets (great!), but differently from the use with "tabout ", here it saved all results like text (in a unique row-cells).

    Any suggestions how to improve this?

    Two comments:
    * I found it easier to format all these outputs with " estpost / eststo / esttab ". But, I am open to other suggestions.
    * I am using Stata 12 (on my private computer). But, I have access to a Stata 15 through the university if the only solution (or best solutions) needs later version.*

  • #2
    Hi Clarice,

    My reply may come too late to help you.

    Instead of using insheet to import the results back to Stata, I suggest that you use
    Code:
    import delimited ....., varname(1)
    It should do the trick.

    Regards,
    Min

    Comment

    Working...
    X