Hi all (though Jeff Pitblado (StataCorp) is probably the most appropriate person to help) -- how do I combine multiple DTables with the same predictors, but different outcomes -- while still retaining the PValues from the tests of each? I've spent hours sifting through this forum trying to use any combination of dtable, collect, collect combine, collect addtags, etc in order to produce the output I'm looking for. Ultimately, I want a table that looks like this, where "Hope" and "Fear" are binary variables and correspond to values from edu_hope[1] and edu_fear[1].
See my dataex snippet below for data that corresponds to the table above.
Now, I can get ALMOST there following some advice from a different thread:
But I can't figure out how to use collect and collect addtags for both the p-value portion of the combined collection, as well as the "eligible" sample for each group, both of which I know I can get if I do the following:
Any advice?
Code:
Table 1
-------------------------------------------------------------------------------
Total Hope PVal Fear Pval
(n=500) (n=109) (n=54)
-------------------------------------------------------------------------------
race_ethnicity
White 97 (19.4%) 21 (19.3%) 0.594 7 (13.0%) 0.502
Black 15 (3.0%) 1 (0.9%) 1 (1.9%)
Hispanic or Latino 325 (65.1%) 75 (68.8%) 39 (72.2%)
Asian 30 (6.0%) 5 (4.6%) 2 (3.7%)
Other 32 (6.4%) 7 (6.4%) 5 (9.3%)
-------------------------------------------------------------------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float race_ethnicity byte(gender edu_hope edu_fear) 3 2 0 0 1 2 0 0 4 1 1 1 3 1 0 0 3 1 0 0 1 2 0 0 3 2 0 1 3 2 0 0 1 2 0 0 3 2 0 0 1 2 0 0 4 2 0 0 3 1 0 0 1 2 1 0 3 2 0 0 1 1 0 0 3 1 1 0 5 1 0 0 3 1 0 1 3 1 0 0 1 2 0 0 5 1 0 0 1 1 0 0 3 1 0 0 3 1 1 0 3 2 0 0 1 1 1 0 3 2 0 0 3 2 0 0 3 1 0 0 5 2 0 0 3 2 0 0 3 1 0 0 3 1 1 0 5 1 0 1 3 1 0 0 3 1 0 0 3 2 0 0 1 2 0 0 3 2 0 0 3 2 0 0 3 2 1 0 3 2 0 0 5 1 1 1 3 2 0 0 3 2 0 0 1 2 0 0 3 2 0 0 1 2 0 0 3 1 0 0 1 1 1 0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 1 2 0 1 1 1 0 0 1 1 0 0 3 1 0 0 3 1 0 0 3 1 0 0 3 2 0 0 3 1 0 0 3 1 1 0 3 2 0 0 3 1 0 0 3 2 1 0 3 1 0 0 3 1 0 0 4 2 0 0 3 1 0 0 3 1 1 0 3 1 1 1 3 1 1 0 3 2 1 0 3 2 1 0 1 1 0 0 3 2 0 0 3 2 0 0 3 2 0 0 3 2 0 0 3 1 1 0 3 1 0 0 3 2 0 0 3 2 1 1 3 2 0 0 3 2 0 0 3 2 0 0 3 2 0 0 3 1 0 0 3 2 0 0 1 1 0 0 3 2 0 1 1 1 0 0 1 1 1 0 3 2 0 0 3 2 0 0 3 1 1 0 3 1 0 0 3 1 0 1 4 2 0 0 3 1 0 0 3 2 0 0 3 1 0 0 3 1 0 0 3 2 1 0 1 2 1 0 1 1 1 0 3 2 0 0 1 2 0 0 3 1 0 0 3 2 1 1 1 1 0 1 3 1 1 1 3 2 1 0 3 1 1 0 3 1 1 0 1 1 0 0 3 2 0 0 5 2 0 1 end label values race_ethnicity la_race_ethnicity label def la_race_ethnicity 1 "White", modify label def la_race_ethnicity 2 "Black", modify label def la_race_ethnicity 3 "Hispanic or Latino", modify label def la_race_ethnicity 4 "Asian", modify label def la_race_ethnicity 5 "Other", modify label values gender gender label def gender 1 "Female", modify label def gender 2 "Male", modify label values edu_hope yesno label values edu_fear yesno label def yesno 0 "No", modify label def yesno 1 "Yes", modify
Code:
collect addtag group[Total]
dtable i.race_ethnicity if edu_hope==1, name(Hope)
collect addtag group[Hope]
dtable i.race_ethnicity if edu_fear==1, name(Fear)
collect addtag group[Fear]
collect combine comb = Total Hope Fear
collect style autolevels group Total Hope Fear
collect style header result[_dtable_stats], title(hide) level(hide)
collect layout (var) (group#result)
Table 1
------------------------------------------------------
Total Hope Fear
------------------------------------------------------
race_ethnicity
White 97 (19.4%) 21 (19.3%) 7 (13.0%)
Black 15 (3.0%) 1 (0.9%) 1 (1.9%)
Hispanic or Latino 325 (65.1%) 75 (68.8%) 39 (72.2%)
Asian 30 (6.0%) 5 (4.6%) 2 (3.7%)
Other 32 (6.4%) 7 (6.4%) 5 (9.3%)
------------------------------------------------------
Code:
dtable i.race_ethnicity, by(edu_hope) dtable i.race_ethnicity, by(edu_fear)

Comment