Hi Statalist community,
I have a sample dataset below. It comprises of all the different ways that participants describe their race.
You can see that some individuals list multiple races. I want the first race in an individual's record. I was using the link below and used the suggested code.
https://www.statalist.org/forums/for...rt-of-a-string
In my situation, I have different types of symbols such as "/" and "," and "." and trailing blanks. So I wrote the following code but the syntax is wrong. Is there something that I'm missing. Thanks for your help.
I have a sample dataset below. It comprises of all the different ways that participants describe their race.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str123 Race "African American/Black" "White " "I do not wish to answer." "African American/Black,Hawaiian/Other Pacific Islander" "Asian " "American Indian/Alaskan Native" "African American/Black,American Indian/Alaskan Native" "African American/Black,American Indian/Alaskan Native,White " "African American/Black,White " "American Indian/Alaskan Native,White " "African American/Black,Asian " "White ,American Indian/Alaskan Native" "White ,Hawaiian/Other Pacific Islander" "African American/Black,I do not wish to answer." "African American/Black,American Indian/Alaskan Native,Hawaiian/Other Pacific Islander" "Asian ,White " "American Indian/Alaskan Native,African American/Black,Asian ,White " "American Indian/Alaskan Native,Asian " "African American/Black,Asian ,Hawaiian/Other Pacific Islander" "White ,African American/Black" "Hawaiian/Other Pacific Islander" "Hawaiian/Other Pacific Islander,White " "African American/Black,American Indian/Alaskan Native,Asian ,Hawaiian/Other Pacific Islander,White " "African American/Black,American Indian/Alaskan Native,Asian " "African American/Black,American Indian/Alaskan Native,Asian ,White " "Asian ,Hawaiian/Other Pacific Islander" "American Indian/Alaskan Native,Asian ,White " "African American/Black,American Indian/Alaskan Native,Hawaiian/Other Pacific Islander,White " "American Indian/Alaskan Native,Hawaiian/Other Pacific Islander,White " "White ,I do not wish to answer." "Hawaiian/Other Pacific Islander,African American/Black" "African American/Black,Asian ,White " "African American/Black,Asian ,Hawaiian/Other Pacific Islander,White " "American Indian/Alaskan Native,Hawaiian/Other Pacific Islander" "White ,African American/Black,American Indian/Alaskan Native,Hawaiian/Other Pacific Islander" end
https://www.statalist.org/forums/for...rt-of-a-string
In my situation, I have different types of symbols such as "/" and "," and "." and trailing blanks. So I wrote the following code but the syntax is wrong. Is there something that I'm missing. Thanks for your help.
Code:
gen wanted = substr(Race, 1, strpos(Race, "/" | "," |"." | " ") - 1)
Comment