Hello fellow Stata community,
I´m looking for a way to automate my Analysis Output to Excel using Putexcel. I already found this Code by eric_a_booth that helps me create summary tables for each of the four example variables, each on an own sheet:
foreach j of varlist var1 var2 d_var1 d_var2{
di `"`j'"'
su `j'
putexcel A3=rscalars using `"test.xlsx"', sheet("S_`j'") modify keepcellf
putexcel A1=(`" Example for `j' "') using `"test.xlsx"', sheet("S_`j'") modify keepcellf
}
di `"{browse `"test.xlsx"': Click to open `"test.xlsx"' }"'
What I´m now looking for, would be an extension of this. My goal would be creating automated tables like the one attached, displaying the values for each variable over the values of a socio-demographic variable. In a shortened try, I programmed the following:
sum var1
*return list
putexcel A1=("Table 1") B3=("Obs") C3=("Total") D3=("Female") E3=("Male") F3=("Divers") using results, replace
putexcel C4=matrix(r(mean)*100) using results, modify
sum var1 if gender==1
putexcel D4=matrix(r(mean)*100) using results, modify
sum var1 if gender==2
putexcel E4=matrix(r(mean)*100) using results, modify
sum var1 if gender==3
putexcel F4=matrix(r(mean)*100) using results, modify
...
Since I want to run this over dozens of var´s it seems inevitable to create some kind of a loop.
I hope the example table helps understanding where i´m trying to head with this, otherwise I´ll try to further specify my challenge.
Thanks in advance for any help given, I´d be more than thankful for any advise.
Regards
Marvin
Array
Related Posts with Excel Table split by socio-demographics using Putexcel
Error: Option Dynamic Not Allowed in the Command PredictHi, I am doing ex-ante out of sample forecasting for rail freight. Based on the results of the ADF …
Line graphsHi STATALIST, Using line cp50_CTDI cp50_CTDI_withIR cp50_CTDI_withoutIR p50_CTDI I produced …
"Outcome does not vary" errorHi everyone I am trying to run a logit regression: logit employed firmsize and I receive this erro…
Need help on the Margins and marginsplotDear experts, I am a beginner of Stata and I need your help desperately. I have the panel data from…
Combining Datasets and Reformatting DataHello everyone. I have a number of datasets (excel files) with data formatted as SheetName: Year1,…
Subscribe to:
Post Comments (Atom)
0 Response to Excel Table split by socio-demographics using Putexcel
Post a Comment