Hi Statalist,
I would like to export tabulations for categorical variables to Latex.
Here is one categorical variable I am using:
I would like to export the tabulation of "social18_beer_cat" so that I have the 1) frequency and 2) percentages.
I did some troubleshooting but cannot find the solution.
I tried to use a loop since I have several categorical variable which follows the same structure.
Thank you so much!
I would like to export tabulations for categorical variables to Latex.
Here is one categorical variable I am using:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float social18_beer_cat 0 3 2 2 0 3 0 0 1 end
I did some troubleshooting but cannot find the solution.
I tried to use a loop since I have several categorical variable which follows the same structure.
Code:
global social "social18_one_cat social18_two_cat social18_beer_cat social18_four_cat social18_five_cat social18_six_cat"
unab vars : $social
local n = `: word count `vars''
local i = 1
foreach v of varlist $social {
matrix `v' = J(4,2,.)
tab `v', matcell(freq)
local j = 1
matrix `v'[1,`j'] = r(freq)
local ++j
matrix `v'[1,`j'] = r(percent)
local ++j
mata: `v' = st_matrix("`v'")
mmat2tex `v' using `v'.tex, replace fmt("%12.3f" "%12.3f")
}

Comment