I have some variable look like this.
And I want to create cross-tabulation for age and income, by group city and gender, summarizing mean and sd
like this:
I tried tabulate,
tabulate gender city, summarize(age) nofreq, wrap
it works well but can only summarize one variable at once. I can't do something like summarize(age income)
I also tried tabstat
tabstat age income, by(city) stat(mean sd)
it can only tabulate one category as by(city). I can't do something like by(city gender)
I finally tried table
table city gender, contents(mean age sd age mean age sd age)
It returns the numbers I want, but in an ugly display since it put all the statistics in one cell without notation.
like
I also read about tabout and tablemat. And a little bit confused now.
It seems that tabout just put those tables in a beautiful look but actually.
And tablemat keeps alerting me invalid name, or asking me "Please provide only one statistic at a time"
tablemat age income, stat(mean sd) by(city gender)
When I tried put only one statistic
tablemat age income, stat(mean) by(city gender)
tablemat provides me something definitely not what I want.
Please help me with this problem.
I'm running out of solutions.
Any help will be highly appreciated.
Thanks a lot!
city | gender | age | income |
A | Female | 23 | 309 |
A | Male | 14 | 456 |
A | Female | 67 | 342 |
A | Female | 45 | 653 |
B | Male | 42 | 155 |
B | Female | 24 | 678 |
B | Female | 35 | 256 |
B | Male | 49 | 432 |
like this:
female | male | |||
age | income | age | income | |
A | mean | |||
sd | ||||
B | ||||
tabulate gender city, summarize(age) nofreq, wrap
it works well but can only summarize one variable at once. I can't do something like summarize(age income)
I also tried tabstat
tabstat age income, by(city) stat(mean sd)
it can only tabulate one category as by(city). I can't do something like by(city gender)
I finally tried table
table city gender, contents(mean age sd age mean age sd age)
It returns the numbers I want, but in an ugly display since it put all the statistics in one cell without notation.
like
female | male | |
A | mean(age) | |
sd(age) | ||
mean(income) | ||
sd(income) | ||
B | ||
It seems that tabout just put those tables in a beautiful look but actually.
And tablemat keeps alerting me invalid name, or asking me "Please provide only one statistic at a time"
tablemat age income, stat(mean sd) by(city gender)
When I tried put only one statistic
tablemat age income, stat(mean) by(city gender)
tablemat provides me something definitely not what I want.
All | city_A | city_B | gender_F | gender_M | |
age | 37.375 | 37.25 | 37.5 | 38.8 | 35 |
income | 410.125 | 440 | 80.25 | 447.6 | 347.6667 |
Please help me with this problem.
I'm running out of solutions.
Any help will be highly appreciated.
Thanks a lot!
Comment