I need to export an overview of several categorical variables to Excel. Even though it appears so trivial there have been roadblocks a lot by now. I have been looking at different options, like tabout
, tab2xl or putexcel but because of the combination of having multiple variables that are categorical in nature I have been unable to apply any of the solutions proposed in other threads to my case.
Because all the variables have the same categories, I would like to have them all in one table. The user-written command tabm
gives me exactly the output I need:
set obs 50
local vlist v1 v2 v3 v4 v5
foreach v of local vlist {
generate byte `v' = 1
replace `v' = 2 if _n>10
replace `v' = 3 if _n>20
replace `v' = 4 if _n>30
}
label define valuelabels 1 "Label 1" 2 "Label 2" 3 "Label 3" 4 "Label 4"
label values v1-v5 valuelabels
tabm v*
The tabm command gives me this output
But now I want Stata to automatically export this into Excel. Because the dataset I am working with is subject to a lot of changes, it's not an option to just manually copy the table every time.