Hello! New Stata user and still learning. Would appreciate help.
I have 2 string variables - "RaceFinal" and "RGrpRace".
RaceFinal contains the all race categories that a person has identified themselves as (for example from my dataex below: ""EastEur Slavic WestEur..."). Most observations have only one selection, but some have identified up to 7 race selections.
RGrpRace is currently empty (gen RGrpRace = "")
My question: I want to use the rarest group method (I have a list which orders race categories from fewest/rarest in the population to largest) to impute a single race into the RGrpRace variable, if RaceFinal contains the substring race identified . So, from the example above, I would want the code to return "Slavic" into RGrpRace, since we have fewer Slavic people in our state then the other 2 groups identified.
Here is what I've written so far: replace RGrpRace = RaceFinal if RGrpRace == "" & RaceFinal (contains "Slavic")
Would I use regexm? strpos? Please help.
Thank you!
----------------------- copy starting from the next line -----------------------
------------------ copy up to and including the previous line ------------------
---
I have 2 string variables - "RaceFinal" and "RGrpRace".
RaceFinal contains the all race categories that a person has identified themselves as (for example from my dataex below: ""EastEur Slavic WestEur..."). Most observations have only one selection, but some have identified up to 7 race selections.
RGrpRace is currently empty (gen RGrpRace = "")
My question: I want to use the rarest group method (I have a list which orders race categories from fewest/rarest in the population to largest) to impute a single race into the RGrpRace variable, if RaceFinal contains the substring race identified . So, from the example above, I would want the code to return "Slavic" into RGrpRace, since we have fewer Slavic people in our state then the other 2 groups identified.
Here is what I've written so far: replace RGrpRace = RaceFinal if RGrpRace == "" & RaceFinal (contains "Slavic")
Would I use regexm? strpos? Please help.
Thank you!
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str33 RaceFinal str1 RGrpRace
"North African" ""
"American Indian" ""
"Middle Eastern" ""
"Native Hawaiian" ""
"Native Hawaiian" ""
"Indigenous Mex/Cen/So American" ""
"African American" ""
"Native Hawaiian" ""
"American Indian" ""
"Native Hawaiian" ""
"African American" ""
"Filipino/A" ""
"Other White" ""
"Latinx Mexican" ""
"African American" ""
"Alaska Native" ""
"Other White" ""
"Multiracial" ""
"Filipino/A" ""
"Other Pacific Islander" ""
"Other Black" ""
"African American" ""
"Other White" ""
"American Indian" ""
"Alaska Native" ""
"Korean" ""
"African American" ""
"Native Hawaiian" ""
"Indigenous Mex/Cen/So American" ""
"African American" ""
"Latinx Mexican" ""
"Western European" ""
"Other White" ""
"Eastern European" ""
"Eastern European" ""
"Other White" ""
"African American" ""
"African American" ""
"Other Pacific Islander" ""
"Canadian Inuit/Metis/First Nation" ""
"Other White" ""
"African American" ""
"Other White" ""
"African American" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Other White" ""
"Other White" ""
"Western European" ""
"Alaska Native" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Japanese" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Indigenous Mex/Cen/So American" ""
"Filipino/A" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Other White" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Latinx Mexican" ""
"EastEur Slavic WestEur" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
"Western European" ""
end
---
Comment