asdocx: Export from Stata to Word, Excel, LaTeX & HTML › Forums › asdocx Forum › How to report row percentage and confidence interval using table1 template › Reply To: How to report row percentage and confidence interval using table1 template
I have added the requested feature. First update asdocx with
asdocx_update
. Here is an example.
* Create a toy example *generate random number of observations clear set obs 200 * create variable for using sleeping pills gen use_pills = round(runiform(0,1)) label define use_pills 0 "Yes" 1 "No" label val use_pills use_pills label var use_pills "Used sleeping pills in the last month" *create variable for male and female gen gender = round(runiform(0,1)) label define gender 0 "Female" 1 "Male" label val gender gender replace use_pills = 1 if gender == 1 & use_pills == 0 & runiform()<0.7 replace use_pills = 0 if gender == 0 & use_pills == 1 & runiform()<0.3
Row percentage with confidence intervals
* if row percentages are required
asdocx tab use_pills gender, template(table1) row cat(% ci) replace
Table 1: Demographics
Variables | Yes (n=79) | No (n=121) | Total (200) | P-value |
---|---|---|---|---|
gender | 0.000 | |||
Female
|
64.444% (53.921 - 73.735) | 35.556% (26.265 - 46.079) | 100.000% | |
Male
|
19.091% (12.731 - 27.622) | 80.909% (72.378 - 87.269) | 100.000% | |
P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. |
* If the total column is not required, use option nototal * Add option table_layout(auto) for auto adjust columns for contents asdocx tab use_pills gender, template(table1) row cat(% ci) /// replace nototal table_layout(auto)
Table 1: Demographics
Variables | Yes (n=79) | No (n=121) | P-value |
---|---|---|---|
gender | 0.000 | ||
Female
|
64.444% (53.921 - 73.735) | 35.556% (26.265 - 46.079) | |
Male
|
19.091% (12.731 - 27.622) | 80.909% (72.378 - 87.269) | |
P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. |
Column percentages
* If col percentages
asdocx tab use_pills gender, template(table1) col categorical(% ci) replace
Table 1: Demographics
Variables | Yes (n=79) | No (n=121) | Total (200) | P-value |
---|---|---|---|---|
gender | 0.000 | |||
Female
|
73.418% (62.455 - 82.097) | 26.446% (19.294 - 35.097) | 45.0% (38.203 - 51.989) | |
Male
|
26.582% (17.903 - 37.545) | 73.554% (64.903 - 80.706) | 55.0% (48.011 - 61.797) | |
P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. |