Hello everyone,
I am using dtable in Stata to summarize binary variables (hasSepsis, hasInfection, hasUTI, hasOther) by a treatment variable (treated). However, my table output is not quite how I would like.
I would like to have the results on one row with the corresponding variable name.
I know how to hide the rows with the variable names and only show the rows with the results, but i'd rather not have to manually re-label all the "1"s to something meaningful. Rather I'm looking for a way to shift the results up to the variable name.
Current output:
Desired output, with results on one row with the variable name:
My code:
I am using dtable in Stata to summarize binary variables (hasSepsis, hasInfection, hasUTI, hasOther) by a treatment variable (treated). However, my table output is not quite how I would like.
I would like to have the results on one row with the corresponding variable name.
I know how to hide the rows with the variable names and only show the rows with the results, but i'd rather not have to manually re-label all the "1"s to something meaningful. Rather I'm looking for a way to shift the results up to the variable name.
Current output:
Code:
--------------------------------------------
Control Treated All
--------------------------------------------
N 3 (30.0%) 7 (70.0%) 10 (100.0%)
hasSepsis
1 1 (33.3%) 0 (0.0%) 1 (10.0%)
hasInfection
1 2 (66.7%) 0 (0.0%) 2 (20.0%)
hasUTI
1 0 (0.0%) 1 (14.3%) 1 (10.0%)
hasOther
1 0 (0.0%) 0 (0.0%) 0 (0.0%)
--------------------------------------------
Desired output, with results on one row with the variable name:
Code:
-------------------------------------------------
Control Treated All
-------------------------------------------------
N 3 (30.0%) 7 (70.0%) 10 (100.0%)
hasSepsis 1 (33.3%) 0 (0.0%) 1 (10.0%)
hasInfection 2 (66.7%) 0 (0.0%) 2 (20.0%)
hasUTI 0 (0.0%) 1 (14.3%) 1 (10.0%)
hasOther 0 (0.0%) 0 (0.0%) 0 (0.0%)
-------------------------------------------------
Code:
clear input float treated byte(hasSepsis hasInfection hasUTI hasOther) 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 end label values treated treated_lab label def treated_lab 0 "Control" 1 "Treated", modify dtable 1.has*, /// by(treated) /// column(by(hide) total(All) test(P-value))

Comment