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?
General Question about standard error clustering levelHello everyone, My question is not necessarily related to Stata codes but is broadly related to sta…
Examples in did2s stata help commandI did a search in Stata, in the help stata command on 'did2s' and try to run their first example (se…
How do I calculate time duration from date in rows?Hi all, I have an example dataset below. I am trying to calculate the duration between the start "d…
Regression with binary dependent variableDear all, I'm a student and a new user of Stata. I have some problems with the following regression.…
How to label data by keywords using shortcuts?I am trying to label names to ethics in my dataset A, so far I've collected all the names in my data…
Subscribe to:
Post Comments (Atom)
0 Response to How to Combine Categorical Variables into One Variable?
Post a Comment