Multiple categories of the treatvar
This post shows various examples of using template(table1) when the treatment variable has more than two categories. If you are new to asdocx or to the template(table1), you may like to start with the basic introduction to Table1 template here.
Several asdocx users requested to add support for multiple categories of the treatment variable. In asdocx version 2.1.2 (Aug 17, 2022) this is now possible. Following are few examples:
Example data
use http://fintechprofessor.com/asdocxAddins/table1svy, clear * Create a dummy variable to use it a continuous variable gen pincome = id / 10000 * Create value lable for gener label define genderlable 1 "Female" 0 "Male" * assign values label value gender genderlable
Continuous variables
*1. mean ci - for comparison, firstoutput from Stata mean pincome, over(mi_final) Mean estimation Number of obs = 18,076 -------------------------------------------------------------------- | Mean Std. Err. [95% Conf. Interval] -------------------+------------------------------------------------ c.pincome@mi_final | none | 4.937284 .0184639 4.901093 4.973475 stemi | 4.65329 .4590964 3.753418 5.553163 nstemi | 5.241515 .2427136 4.765773 5.717256 Type 2 | 4.401919 .4269773 3.565002 5.238835 -------------------------------------------------------------------- asdocx tab mi_final pincome , template(table1) replace landscape cont(mean ci)
Table 1: Demographics
Variables | none (n=17932) | stemi (n=21) | nstemi (n=96) | Type 2 (n=27) | Total (18076) | P-value |
---|---|---|---|---|---|---|
pincome | 4.937 (4.901 – 4.973) | 4.653 (3.753 – 5.553) | 5.242 (4.766 – 5.717) | 4.402 (3.565 – 5.239) | 4.938 (4.902 – 4.974) | 0.887 |
P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. |
*2. svy mean ci svyset id [pweight=dwt], vce(linearized) svy: mean income, over(mi_final) -------------------------------------------------------------------- | Linearized | Mean Std. Err. [95% Conf. Interval] -------------------+------------------------------------------------ c.pincome@mi_final | none | 4.937284 .056669 4.826177 5.04839 stemi | 4.653291 .4480933 3.77475 5.531833 nstemi | 5.241515 .248015 4.755251 5.727779 Type 2 | 4.40192 .4190554 3.580311 5.22353 -------------------------------------------------------------------- svy: mean pincome, over(mi_final) asdocx svy: tab mi_final pincome, template(table1) replace /// landscape cont(mean ci)
Table 1: Demographics
Variables | none (n=17932) | stemi (n=21) | nstemi (n=96) | Type 2 (n=27) | Total (18076) | P-value |
---|---|---|---|---|---|---|
pincome | 4.937 (4.826 – 5.048) | 4.653 (3.775 – 5.532) | 5.242 (4.755 – 5.728) | 4.402 (3.580 – 5.224) | 4.938 (4.827 – 5.049) | 0.887 |
P-values by t-test for continuous variables and Chi2 test for binary/categorical variables. |
*3. mean sd mean pincome, over(mi_final) estat sd asdocx tab mi_final pincome, template(table1) replace /// landscape cont(mean sd) *4. svy mean sd svy:mean pincome, over(mi_final) estat sd asdocx svy:tab mi_final pincome , template(table1) /// landscape cont(mean sd) *------------------------------------------------------------------------------ **# Factor variables (gender is a factor variable) *=============================================================================*/ *1. count and cell percentage tab gender mi_final, cell asdocx tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) cell *2. count and row percentage tab gender mi_final, row asdocx tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) row *3. count and column percent tab gender mi_final, col asdocx tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) col *4. svy count and cell svy:tab gender mi_final, cell format(%9.5f) asdocx svy:tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) cell *5. svy count and row svy:tab gender mi_final, format(%9.5f) row asdocx svy:tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) row * 6. svy count and column svy:tab gender mi_final, format(%9.5f) col asdocx svy:tab mi_final pincome gender, template(table1) /// replace landscape cont(mean sd) col