Been trying to figure this one out but keep getting roadblocks. Wondered if anyone else here has any suggestions.
Basically I am trying to send the results of multiple tabulated variables to excel in a usable format (i.e. output the variable names, e(b), e(pct) , e(cumpct) all outputted in the same respective columns). See below for context.
I can get as far as getting Stata to compute all the tables in a similar format - which I currently then copy paste into excel. This works, but is clunky, slow, and error prone. Is it possible to have Stata send this output into excel all in one hit (i.e. starting from a particular cell)?
Thanks in advance
Code:
putexcel set "$RESULTS/Tables/Main Table.xlsx", sheet("Descriptives") modify foreach var of varlist CVD_total /// sex edlevel09 social_class smokstat prev_dm_base_dmdrg /*dmdrg*/ antihyp lipid antidep /// fh_cvd fh_mi fh_cva fh_ca fh_dm { estpost tabulate `var' if incl_ex_prevCVD==1 //ALL (analytic sample) matrix freq = e(b) matrix pct = e(pct) matrix mtx_`var' = freq \ pct matrix mtx_`var'_long = mtx_`var'' } matrix dir // FROM HERE SOMEHOW PUTEXCEL THE LARGE OUTPUT OF TABLES TO EXCEL IN ONE HIT (STARTING FROM A CERTAIN CELL (e.g. A1)
Array
Hope I am making sense
0 Response to Multiple variables in one matrix - to putexcel
Post a Comment