Stress test: Template(table1) – SVY with Factor Variables
* Load Example Data
webuse nhanes2b, clear
1. CELL percentages
* Use diabetes as a treatment variables
* To get similar results in Stata, we have to use race as a first variable
* This is reversed in asdocx
svy: tabulate race diabetes , obs
/*
----------------------------------------
| Diabetes status
Race | Not diab Diabetic Total
----------+-----------------------------
White | .851 .0281 .8791
| 8659 404 9063
|
Black | .0899 .0056 .0955
| 1000 86 1086
|
Other | .0248 5.2e-04 .0253
| 191 9 200
|
Total | .9658 .0342 1
| 9850 499 1.0e+04
----------------------------------------
Key: Cell proportion */
* Since asdocx uses the treatment variable as the first one, therefore, change
* the order of the variables
asdocx svy: tabulate diabetes i.race, template(table1) cell
/*
----+------------------------------------------------------------------------------
1 |Variables Not diabetic (n=9850) Diabetic (n = 499) Total (10349) P-value
----+------------------------------------------------------------------------------
2 |Race 0.00*
3 | White 8659 (85.10%) 404 (2.81%) 9063 (87.91%)
4 | Black 1000 (8.99%) 86 (0.56%) 1086 (9.55%)
5 | Other 191 (2.48%) 9 (0.05%) 200 (2.53%)
--------------------------------------------------------------------------------- */
2. ROW percentages
svy: tabulate race diabetes , row obs
/*
----------------------------------------
| Diabetes status
Race | Not diab Diabetic Total
----------+-----------------------------
White | .968 .032 1
| 8659 404 9063
|
Black | .941 .059 1
| 1000 86 1086
|
Other | .9797 .0203 1
| 191 9 200
|
Total | .9658 .0342 1
| 9850 499 1.0e+04
----------------------------------------
Key: Row proportion
Number of observations
Pearson:
Uncorrected chi2(2) = 21.3483
Design-based F(1.52, 47.26) = 15.0056 P = 0.0000
*/
asdocx svy: tabulate diabetes i.race, template(table1) row
/*----+-------------------------------------------------------------------------
1 |Variables Not diabetic (n=9850) Diabetic (n = 499) Total (10349) P-value
----+----------------------------------------------------------------------------
2 |Race 0.00*
3 | White 8659 (96.80%) 404 (3.20%) 9063 (87.91%)
4 | Black 1000 (94.10%) 86 (5.90%) 1086 (9.55%)
5 | Other 191 (97.97%) 9 (2.03%) 200 (2.53%)
-------------------------------------------------------------------------------*/
3. COL percentages
svy: tabulate race diabetes , col obs
/*
----------------------------------------
| Diabetes status
Race | Not diab Diabetic Total
----------+-----------------------------
White | .8812 .8203 .8791
| 8659 404 9063
|
Black | .0931 .1647 .0955
| 1000 86 1086
|
Other | .0257 .0151 .0253
| 191 9 200
|
Total | 1 1 1
| 9850 499 1.0e+04
----------------------------------------
Key: Column proportion
Number of observations
Pearson:
Uncorrected chi2(2) = 21.3483
Design-based F(1.52, 47.26) = 15.0056 P = 0.0000 */
asdocx svy: tabulate diabetes i.race, template(table1) col
/*
----+------------------------------------------------------------------------------
1 |Variables Not diabetic (n=9850) Diabetic (n = 499) Total (10349) P-value
----+------------------------------------------------------------------------------
2 |Race 0.00*
3 | White 8659 (88.12%) 404 (82.03%) 9063 (87.91%)
4 | Black 1000 (9.31%) 86 (16.47%) 1086 (9.55%)
5 | Other 191 (2.57%) 9 (1.51%) 200 (2.53%)
-----------------------------------------------------------------------------------
*/