I'm cross tabulating in Stata 17 with one column variable and multiple row variables. However, two issues: 1. I do not want the row variables to be nested within each other. they should be separate, with each row variable only crosstabulation with the column variable. 2. I want the percentages to be those of the row category. so for instance, the displayed percentage values in the row of say, the Male category under Gender, should be the percentage of males who are core voters and the percentage of Males who are swing voters. Here is a sample table which I had to generate and combine in excel. I couldn't also get the right percentages in this sample table:
I used the codes:
table age swing_voter, statistic(percent age) nototal
table gender swing_voter, statistic(percent gender) nototals
table marital_status swing_voter, statistic(percent marital_status ) nototals
How do I run a code that creates one table at once with all the variables I want to have in the row column without it nesting each variable within the previous variable?
------------------ copy up to and including the previous line ------------------
Voted for the same party? | ||
core | swing | |
Age | ||
18-30 | 8.21 | 4.77 |
31-40 | 17.13 | 13.78 |
41-50 | 15.59 | 10.68 |
51-60 | 11.77 | 8.25 |
60+ | 5.16 | 4.67 |
Gender | ||
Male | 19.51 | 14.26 |
Female | 39.57 | 26.66 |
Marital Status | ||
unmarried | 0 | 0 |
married | 58.26 | 41.74 |
table age swing_voter, statistic(percent age) nototal
table gender swing_voter, statistic(percent gender) nototals
table marital_status swing_voter, statistic(percent marital_status ) nototals
How do I run a code that creates one table at once with all the variables I want to have in the row column without it nesting each variable within the previous variable?
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(swing_voter age gender marital_status) 1 3 1 1 1 2 1 0 0 3 1 1 1 2 1 1 0 2 1 1 0 2 2 1 1 3 2 0 0 3 1 1 1 5 1 1 1 5 2 1 0 2 2 1 0 2 2 1 0 3 1 1 1 3 2 1 0 1 1 0 1 3 1 1 0 2 2 1 1 3 2 1 0 1 1 0 0 1 2 0 1 2 2 1 0 2 2 1 1 1 2 0 1 2 1 1 1 3 2 1 0 1 2 0 0 2 2 1 1 2 1 0 0 3 1 1 0 4 2 1 0 3 2 1 1 2 2 1 1 2 2 1 0 2 2 0 0 2 2 0 1 2 2 1 1 1 2 0 0 5 1 1 1 5 1 0 1 4 2 0 0 3 2 1 0 5 1 0 0 3 1 1 1 2 2 1 0 3 1 1 1 2 2 1 1 4 1 1 0 2 1 1 0 5 2 1 1 3 2 0 1 2 1 1 0 4 2 1 1 1 1 0 1 3 2 1 0 1 2 0 0 1 1 0 0 1 2 0 0 3 2 0 1 2 2 1 1 2 2 1 1 2 2 1 1 1 2 0 1 2 1 0 1 5 1 0 0 3 1 1 0 1 1 0 0 3 1 1 1 2 2 1 1 1 2 0 1 4 2 1 0 1 1 0 1 2 1 1 1 2 1 1 0 1 2 0 1 2 1 1 0 2 2 1 0 4 1 1 1 2 2 1 1 4 1 1 0 2 1 1 0 3 1 0 1 4 1 1 0 2 1 1 1 1 2 0 0 3 2 1 1 2 1 0 1 3 1 1 0 3 1 1 0 4 1 1 0 3 1 1 1 2 1 0 0 5 1 1 0 2 1 1 0 2 2 1 0 1 2 1 0 2 1 1 1 4 2 1 0 3 1 1 1 1 2 0 0 1 1 0 end label values swing_voter swingvoter label def swingvoter 0 "core", modify label def swingvoter 1 "swing", modify label values age labels0 label def labels0 1 "18-30", modify label def labels0 2 "31-40", modify label def labels0 3 "41-50", modify label def labels0 4 "51-60", modify label def labels0 5 "60+", modify label values gender labels1 label def labels1 1 "Male", modify label def labels1 2 "Female", modify label values marital_status marriage label def marriage 0 "unmarried", modify label def marriage 1 "married", modify
Comment