asdocx table1 : row percentage


Stata’s tabulate command with the option row displays the relative frequency of each cell within its row in a two-way table. Let’s load the nhanes2b, data from the web and create a two way table of diabetes by race.

webuse nhanes2b, clear
tabulate race diabetes ,  row

Here is how the table looks like.

Tabulation of agegrp diabetes
No diabetes Total
age20-29 2305 15 2320
99.353 0.647 100
age30-39 1600 21 1621
98.705 1.295 100
age40-49 1229 42 1271
96.696 3.304 100
age50-59 1219 72 1291
94.423 5.577 100
age60-69 2622 238 2860
91.678 8.322 100
age 70+ 875 111 986
88.742 11.258 100
Total 9850 499 10349
95.178 4.822 100

Table1 with asdocx


To create the above table in Table1 format, we need to change the variable order so that the treatement variable is written first. The asdocx command for Table 1 template is

asdocx tabulate diabetes i.agegrp ,  template(table1) row replace
Table 1: Demographics
Variables 0 (n=9850) 1 (n = 499) Total (10349) P-value
Age groups 1-6 0.00
age20-29
2305 (99.35%) 15 (0.65%) 2320 (100.00%)
age30-39
1600 (98.70%) 21 (1.30%) 1621 (100.00%)
age40-49
1229 (96.70%) 42 (3.30%) 1271 (100.00%)
age50-59
1219 (94.42%) 72 (5.58%) 1291 (100.00%)
age60-69
2622 (91.68%) 238 (8.32%) 2860 (100.00%)
age 70+
875 (88.74%) 111 (11.26%) 986 (100.00%)