I am trying to get a table that has percent distribution of some categorical variables, 95% CIs for the percent, and p-value from a chi2 test comparing two levels of the 'by' variable. My code goes like this:
dtable i.sex i.hdage i.white, by(ld10, nototals tests) svy
collect style autolevels result _dtable_test, clear
collect: proportion sex hdage white [iw=gross4_ind], percent over(ld10)
collect composite define _r_ci = _r_lb _r_ub, delimiter(",") trim replace
collect style cell result[_r_ci], sformat("(%s)") nformat(%6.0f)
collect style cell result[fvpercent], sformat("%s%%") nformat(%6.0f)
collect style autolevels result fvpercent _r_ci _dtable_test
collect layout (colname var) (ld10#result)
The table below is the closest to what I am trying to achieve, but obviously I want the p-values to be in the upper half of the table and I don't need the bottom half of the table. I understand that I need to use collect recode (or collect remap). I have spent a lot of time trying this but to no good result. How do I identify what I need to collect recode, and to what? Thanks in advance!

dtable i.sex i.hdage i.white, by(ld10, nototals tests) svy
collect style autolevels result _dtable_test, clear
collect: proportion sex hdage white [iw=gross4_ind], percent over(ld10)
collect composite define _r_ci = _r_lb _r_ub, delimiter(",") trim replace
collect style cell result[_r_ci], sformat("(%s)") nformat(%6.0f)
collect style cell result[fvpercent], sformat("%s%%") nformat(%6.0f)
collect style autolevels result fvpercent _r_ci _dtable_test
collect layout (colname var) (ld10#result)
The table below is the closest to what I am trying to achieve, but obviously I want the p-values to be in the upper half of the table and I don't need the bottom half of the table. I understand that I need to use collect recode (or collect remap). I have spent a lot of time trying this but to no good result. How do I identify what I need to collect recode, and to what? Thanks in advance!
Comment