I built a sample description table in Stata 17 and have recently switched over to Stata 18. I want to combine two tables. The first table summarizes the sample selection criterion and tells me how many people are included in the regressions. The second table summarizes the sex and age only for those people included. My MRE looks like this at the moment:
I have tried using the collect combine command but the combination does not show the right order of the variables. The goal is to create one table to put into Word using putdocx.
Crosspost from Stackoverflow: https://stackoverflow.com/questions/...lect-and-table
Code:
clear all input id inclusion age sex 1 1 35 0 2 1 56 1 3 0 78 1 3 1 43 1 4 0 3 0 5 1 40 0 6 1 5 0 7 0 55 1 8 1 31 0 9 1 26 0 10 0 34 1 11 0 45 1 12 0 67 0 end putdocx begin table () () (), statistic(mean inclusion) statistic(sd inclusion) statistic(min inclusion) statistic(max inclusion) nformat(%6.2f mean sd) collect layout (var) (result) collect label levels result mean "Mean" sd "SD" min "Min." max "Max.", modify putdocx pagebreak putdocx paragraph, style(Heading1) putdocx text ("Table 2: Sample description") putdocx collect table ( ) () () if inclusion == 1, /* */ statistic(mean age) statistic(sd age) statistic(min age) statistic(max age) /* */ statistic(mean sex) statistic(sd sex) statistic(min sex) statistic(max sex) collect layout (var) (result) collect label levels result mean "Mean" sd "SD" min "Min." max "Max.", modify putdocx collect putdocx save Tables, append
Code:
* putdocx begin table () () (), statistic(mean inclusion) statistic(sd inclusion) statistic(min inclusion) statistic(max inclusion) nformat(%6.2f mean sd) collect layout (var) (result) collect label levels result mean "Mean" sd "SD" min "Min." max "Max.", modify collect rename Table table21 table ( ) () () if inclusion == 1, /* */ statistic(mean age) statistic(sd age) statistic(min age) statistic(max age) /* */ statistic(mean sex) statistic(sd sex) statistic(min sex) statistic(max sex) collect layout (var) (result) collect label levels result mean "Mean" sd "SD" min "Min." max "Max.", modify collect rename Table table22 collect combine Table2 = table21 table22, layout(right) style(right) collect preview
Comment