It seems that this topic has been discussed before, but I thought I would ask if anyone has a decent workaround for the following problem. If I've missed an answer to this question elsewhere, my apologies. I am doing a standard descriptive analysis and am using the -tabout- feature to create tables in LaTeX that report the N and % of binary or categorical variables by a binary 'case' variable (case or control). I want to add to this table the means and SDs of continuous variables, also by this binary 'case' variable.
The final result should ideally look like the following (In order to easily follow along, I am using the 'auto' dataset):
LaTeX code works pretty well with the categorical variable (in this case, [rep78]):
tabout rep78 foreign using "file.txt", replace style(tex) font(bold) bt cells(freq col) layout(col) format(1) ptotal(none)
However, attempting to summarize continuous variables by levels of a binary variable (as in the last row of the table, for [mpg]) proves difficult. I believe there may be a workaround by using 'do' loops to write tables within tables, but am not sure how to code this. I also know there are workarounds that provide levels of the continuous variable in the columns and levels of the binary variable in rows, but I do not want to orient my table that way.
Hope the question is clear, and I will be eternally grateful for any advice you can give.
The final result should ideally look like the following (In order to easily follow along, I am using the 'auto' dataset):
Characteristic | Foreign | Domestic |
Repair record 1978: N (%) | ||
1 | 0 (0) | 2 (4.2) |
2 | 0 (0) | 8 (16.7) |
3 | 3 (14.3) | 27 (56.3) |
4 | 9 (42.9) | 9 (18.8) |
5 | 9 (42.9) | 2 (4.2) |
Miles per gallon: mean +/- SD | 24.8 +/- 6.6 | 19.8 +/- 4.7 |
tabout rep78 foreign using "file.txt", replace style(tex) font(bold) bt cells(freq col) layout(col) format(1) ptotal(none)
However, attempting to summarize continuous variables by levels of a binary variable (as in the last row of the table, for [mpg]) proves difficult. I believe there may be a workaround by using 'do' loops to write tables within tables, but am not sure how to code this. I also know there are workarounds that provide levels of the continuous variable in the columns and levels of the binary variable in rows, but I do not want to orient my table that way.
Hope the question is clear, and I will be eternally grateful for any advice you can give.
Comment