Hello,
Currently, I am working with data that separates each race by gender. See example data below:
[CODE]
input long(wa_male wa_female ba_male ba_female)
21295 22002 4559 5130
1411 1316 362 317
1521 1526 399 374
1658 1620 431 406
1628 1585 502 424
1201 1184 293 312
1234 1223 277 350
Where wa=white and ba=Black
What I want are variables that are the total of each respective race, so that I end up with:
[CODE]
input float(white black)
43297 9689
2727 679
3047 773
3278 837
3213 926
2385 605
2457 627
To obtain the above results, I typed in the following two commands:
egen white=rowtotal(wa_male wa_female)
egen black=rowtotal(ba_male ba_female)
However, I have many race variable that I am working with and I'd like to see if there is an easier way to rowtotal all of them into their own respective race totals, perhaps by using foreach command (or something similar). I just can't find an easier way to do this as I'd still (I think) need to hand-rename the races or hand rowtotal everything. Any advice--including letting me know that how I'm doing it is in fact the easiest/fastest way--is much appreciated.
Thanks,
Brooke
Currently, I am working with data that separates each race by gender. See example data below:
[CODE]
input long(wa_male wa_female ba_male ba_female)
21295 22002 4559 5130
1411 1316 362 317
1521 1526 399 374
1658 1620 431 406
1628 1585 502 424
1201 1184 293 312
1234 1223 277 350
Where wa=white and ba=Black
What I want are variables that are the total of each respective race, so that I end up with:
[CODE]
input float(white black)
43297 9689
2727 679
3047 773
3278 837
3213 926
2385 605
2457 627
To obtain the above results, I typed in the following two commands:
egen white=rowtotal(wa_male wa_female)
egen black=rowtotal(ba_male ba_female)
However, I have many race variable that I am working with and I'd like to see if there is an easier way to rowtotal all of them into their own respective race totals, perhaps by using foreach command (or something similar). I just can't find an easier way to do this as I'd still (I think) need to hand-rename the races or hand rowtotal everything. Any advice--including letting me know that how I'm doing it is in fact the easiest/fastest way--is much appreciated.
Thanks,
Brooke
Comment