Hi there - probably an easy question for most of you, but I'm new to STATA and can't find the answer to this.
I am trying to create a new variable "ethnicity_Hisp" by searching seven other variables (ethnicity1; ethnicity2; etc) for the string "Hispanic or Latino".
I've tried to do this a couple different ways - shortened to just two variables here for simplicity:
gen variable ethnicity_Hisp=1 if ethnicity1 == "Hispanic or Latino" | ethnicity2 == "Hispanic or Latino"
gen variable ethnicity_Hisp=1 if strpos(ethnicity1, "Hispanic or Latino) | strpos(ethnicity2, "Hispanic or Latino"
I keep getting back "too many variables"
Is there a way to do this without a multistep code where I generate the variable and then replace with 1 for each of the ethnicity variables?
Thanks!
Related Posts with Creating variable from searching multiple strings
Creating and displaying graphs in a loop with dyndocHi, I try to generate standard graphs with every numeric variable in my dataset and create a nice l…
Stata Journal Editors' Prize 2019 is awarded to Matias D. CattaneoThe Editors of the Stata Journal are delighted to announce the award of their 2019 prize to Matias D…
missing("repval") in "export excel options"Hi STATALIST, Could you please advise me how to use missing("repval") options in export excel opti…
Merge daily data with quarterly dataHey! A simple question! I have two panel data sets, one is quarterly, with 3 variables ID date and …
recoding a new generated variableHi everyone, I have a dataset that contains respondents' cognitive functioning and whether they rece…
Subscribe to:
Post Comments (Atom)
0 Response to Creating variable from searching multiple strings
Post a Comment