Hi,
I'd like to export a frequency (one-way) table using svyset. The table would include:
* the number of observations
* the proportion
* the number of weighted observation
* the proportion of weighted observation.
I'm able to generate the four matrices but am struggling to combine them into a single matrix, as well as including the region names (not the numeric value)
Any suggestion on how to do it, either to export in Latex or Word format? Asdoc and putdocx do not allow pweights. Moreover, I would like to loop the above code over a significant number of variables so would like to automatize the process.
Thank you
I'd like to export a frequency (one-way) table using svyset. The table would include:
* the number of observations
* the proportion
* the number of weighted observation
* the proportion of weighted observation.
I'm able to generate the four matrices but am struggling to combine them into a single matrix, as well as including the region names (not the numeric value)
Code:
webuse nhanes2
svyset psu [pweight=finalwgt], strata(strata)
svy: tabulate region, count se
local row=e(r)
local tot_obs=e(N)
mat b1=e(b)
* Weighted proportions
mat wp1=e(Prop)
* obs
mat obs=e(Obs)
mata: sum(st_matrix("e(b)"))
* Weighted obs
matrix weighted_obs=J(`row', 1, 0)
forvalues i=1/`row' {
matrix weighted_obs[`i', 1]=b1[1, `i']
}
* Proportions
matrix prop=J(`row', 1, 0)
forvalues i=1/`row' {
matrix prop[`i', 1]=round(100*obs[`i', 1]/`tot_obs', 0.01)
}
* Weighted Proportions
matrix weighted_prop=J(`row', 1, 0)
forvalues i=1/`row' {
matrix weighted_prop[`i', 1]=round(100*wp1[`i', 1], 0.01)
}
* Obs
mat li obs
* Proportion
mat li prop
* Weighted obs
mat li weighted_obs
* Weighted prop
mat li weighted_prop
Thank you

Comment