I want to merge some tables horizontally. I'm using Stata 18 and it looks like -table- and -collect- are the preferred way of doing this, but I can't understand the documentation on them deeply enough to know how to do so.
Here's an example that's analogous to what I want to achieve. I can make the three tables that would go into this, and following hints on this forum I've worked out how to spread the numbers and percentages wider:
I would like to create a version that merges columns from these horizontally. Ideally, I would just get the subset of columns that I'm interested in, but I would be fairly happy with just merging them all and then deleting the unnecessary columns after I've exported it.
I would ideally like the columns for:
* Health status
* Overall N (5th column of numbers from the first wide table)
* Diabetics n (3rd column from first wide table)
* Diabetics % (4th column from first wide table)
* Heart attack frequency among non-diabetics (3rd column, second wide table)
* Heart attack % among non-diabetics (4th column, second wide table)
* Either diabetes or heart attack frequency (3rd column, third wide table)
* Either diabetes or heart attack % (4th column, third wide table)
Thanks in advance.
Here's an example that's analogous to what I want to achieve. I can make the three tables that would go into this, and following hints on this forum I've worked out how to spread the numbers and percentages wider:
Code:
webuse nhanes2, clear generate diab_or_htat = max(diabetes, heartatk) * Table of frequencies and percentages of people with diabetes, by health status table hlthstat diabetes, statistic(frequency) statistic(percent, across(diabetes)) * Wide version collect layout (var hlthstat) (diabetes#result) * Table of frequencies and percentages of people without diabetes who have had heart attacks, by health status table hlthstat heartatk if diabetes == 0, statistic(frequency) statistic(percent, across(hlthstat)) * Wide version collect layout (var hlthstat) (heartatk#result) * Table for frequencies and percentages of having diabetes or heart attach, by health status table hlthstat diab_or_htat , statistic(frequency) statistic(percent, across(diab_or_htat)) * Wide version collect layout (var hlthstat) (diab_or_htat#result)
I would ideally like the columns for:
* Health status
* Overall N (5th column of numbers from the first wide table)
* Diabetics n (3rd column from first wide table)
* Diabetics % (4th column from first wide table)
* Heart attack frequency among non-diabetics (3rd column, second wide table)
* Heart attack % among non-diabetics (4th column, second wide table)
* Either diabetes or heart attack frequency (3rd column, third wide table)
* Either diabetes or heart attack % (4th column, third wide table)
Thanks in advance.
Comment