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?
Related Posts with How to Combine Categorical Variables into One Variable?
Marginal effect after heckpoissonDear All, I am new to stata and I am using Heckpoisson, a poison regression model with endogenous s…
Adding partner data to responding person data in a panel data fileI wish to extend my analysis of panel data to include information about the responding person's part…
how to export Summary Statistics to wordDear Sir/Madam I am working on my thesis on impact of informal credit on household welfare. I try to…
Generate a new variable in a loop in different files and calculating the meanHi, I want to write a loop to generate a new variable called savings (income-expenditure) in two se…
Numbering occurrences of a flag within patients.In the example below I have created OVERLAP_FLAG, which is equal to 1 where two consecutive regimens…
Subscribe to:
Post Comments (Atom)
0 Response to How to Combine Categorical Variables into One Variable?
Post a Comment