Results to XML
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 xmlsave 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= "" preserve keep group keep in 1/1 save "d:\statatemp\temp.dta", replace restore capture program drop maketable program define maketable preserve 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 restore end 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 list drop in 1 xmlsave "c:\tables\means.xml", doctype(excel) replaceBack to: Exporting Stata Results to MS Office?
Another topic?


