Greetings Stata Users:

I am trying to generate a variable that has the categories of the outcome of interest (1 being the outcome of interest) that I generated from another variable (race and place of residence).

gen whiteurban = (race_r == 0) & (placeofresidence == 1)

. gen latinxurban = (race_r == 1) & (placeofresidence == 1)

. gen blackurban = (race_r == 2) & (placeofresidence == 1)

. gen asianurban = (race_r == 3) & (placeofresidence == 1)

.
. gen whiterural = (race_r == 0) & (placeofresidence == 2)

. gen latinxrural = (race_r == 1) & (placeofresidence == 2)

. gen blackrural = (race_r == 2) & (placeofresidence == 2)

. gen asianrural = (race_r == 3) & (placeofresidence == 2)

I want to make each of these variables its own category with the 1 category in the constructed variables being just one of the categories of the combined variable ( whiteurban category 1- its own category, latinxurban category 1- its own category, blackurban category 1- its own category, etc.) in the new constructed variable


tab whiteurban, nol m

whiteurban | Freq. Percent Cum.
------------+-----------------------------------
0 | 4,104 50.94 50.94
1 | 3,953 49.06 100.00
------------+-----------------------------------
Total | 8,057 100.00

I got this after trying to do the above

gen placerace = (whiteurban == 1)+(latinxurban == 1)+(blackurban == 1)+(asianurban == 1)+(whiterural == 1)+(latinxrural == 1)+(blac
> krural == 1)+(asianrural == 1)

.
end of do-file

. do "C:\Users\rjohn123\AppData\Local\Temp\STD908_00000 0.tmp"

. tab placerace, nol

placerace | Freq. Percent Cum.
------------+-----------------------------------
1 | 8,057 100.00 100.00
------------+-----------------------------------
Total | 8,057 100.00

But that's not what I want. I just want to make a composite variable made up of different categorical variables. Can someone please help me?