Results to Excel

Now let's suppose you want to make a table of these same means with separate rows for each of seven subpopulations. You could run the svy:mean, keep, and export excel commands seven times and copy the results into a single table, or you could write a program to do it for you. Admittedly, the data management is a bit complex, but it may be worthwhile if you expect to run this analysis repeatedly.

use "c:\data\mydata.dta",clear
gen str7 group= ""
keep group
keep in 1/1
save "d:\statatemp\temp.dta", replace

capture program drop maketable
program define maketable
   replace group= "`2'"
   svy, subpop(subpop if groupnum == `1'): mean var1 var2 var3
   matrix emeans=e(b)
   gen meanvar1= emeans[1,1]
   gen meanvar2= emeans[1,2]
   gen meanvar3= emeans[1,3]
   keep group mean*
   keep  in 1/1
   save "d:\statatemp\temp1.dta", replace
   use "d:\statatemp\temp.dta", clear
   append using "d:\statatemp\temp1.dta"
   save "d:\statatemp\temp.dta", replace
maketable 1 "Group 1"
maketable 2 "Group 2"
maketable 3 "Group 3"
maketable 4 "Group 4"
maketable 5 "Group 5"
maketable 6 "Group 6"
maketable 7 "Group 7"

use "d:\statatemp\temp.dta",clear
drop  in 1
export excel "c:\tables\means.xlsx", firstrow(variables)

Back to: Exporting Stata Results to MS Office?


Another topic?

Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme