Hello,
I have using a similar code as below to create customizable tables using the Collect system. This system has been very handy!
Above code results in the following table:
My Question:
Currently, the resultant table above, reports the percentages of the levels of the Race predictor (i.e. White, Black, Other) across the column. In other words, it shows, for example, "what percentage among all people who do not have High Blood Pressure are White, Black, or Other" . However, I want to report percentage levels of the Race predictor across the row (e.g. "what percentage among all persons who are White do not have High Blood Pressure? And what percentage among all persons who are White have High Blood Pressure?")
What would be the best approach to report composition percentage of the covariates across levels of the outcome, as opposed to within the levels of the covariate itself (as the code above shows)?
Thank you so much in advance!
I have using a similar code as below to create customizable tables using the Collect system. This system has been very handy!
Code:
clear
webuse nhanes2l
tab highbp
collect clear
collect layout, clear
* Obtain an initial table with necessary statistics
collect: table ///
(var) ///
(highbp), ///
statistic(mean age) ///
statistic(sd age) ///
statistic(fvfrequency race) ///
statistic(fvpercent race)
* The highbp level value labeled "Total" can later be tagged with a p-value interest
collect label list highbp, all
* Calculate a p-value for association between highbp and age
ologit highbp c.age
* Consume that p-value and attach tags to it for the layout command later on to know where it should be placed
collect get manual_pvalue = e(p), tags(var[age] highbp[.m])
* Calculate a p-value for the association between highbp and race
tab race highbp, chi2 nolabel // note the value of the first level "White". Will use this value for correct tagging/position placement of the Pvalue in next command
* Consume that p-value and attach tags to it for the layout command later on to know where it should be placed
collect get manual_pvalue = r(p), tags(var[1.race] highbp[.m])
* Add a custom formatted footnote for the p-values, corresponding to the p-values obtained in table
collect stars manual_pvalue 0.01 "***" 0.05 "**" 0.1 "*", ///
attach(manual_pvalue) shownote
* Update the formatting for easier readability
collect style cell result[manual_pvalue], nformat(%5.2f) minimum(.01)
* Recode the levels of the result dimension to allow combined placement of the statistic of interest later in the shared cells in the final table
collect recode result ///
fvfrequency = variable_measure ///
fvpercent = variable_spread ///
mean = variable_measure ///
sd = variable_spread //
*Add labels to the mentioned combined levels for better table readability
collect label levels result variable_measure "Count / Mean" variable_spread "% / (SD)"
collect label levels result manual_pvalue "P-Value"
*Create the final table
collect layout ///
(var) ///
(highbp#result[variable_measure variable_spread] result[manual_pvalue])
Code:
-----------------------------------------------------------------------------------------------------
| High blood pressure P-Value
| 0 1 Total
| Count / Mean % / (SD) Count / Mean % / (SD) Count / Mean % / (SD)
------------+----------------------------------------------------------------------------------------
Age (years) | 42.16502 16.77157 54.97281 14.90897 47.57965 17.21483 <0.01***
Race=White | 5317 88.98745 3748 85.64899 9065 87.57608 <0.01***
Race=Black | 545 9.121339 541 12.36289 1086 10.49174
Race=Other | 113 1.891213 87 1.988117 200 1.93218
-----------------------------------------------------------------------------------------------------
*** p<.01, ** p<.05, * p<.1
My Question:
Currently, the resultant table above, reports the percentages of the levels of the Race predictor (i.e. White, Black, Other) across the column. In other words, it shows, for example, "what percentage among all people who do not have High Blood Pressure are White, Black, or Other" . However, I want to report percentage levels of the Race predictor across the row (e.g. "what percentage among all persons who are White do not have High Blood Pressure? And what percentage among all persons who are White have High Blood Pressure?")
What would be the best approach to report composition percentage of the covariates across levels of the outcome, as opposed to within the levels of the covariate itself (as the code above shows)?
Thank you so much in advance!

Comment