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
Testing for heteroskedasticty using FE OLS and RE GLSHi everyone, I am currently trying to test for heteroskedasticity using an unbalanced panel and FE …
export `sjlog` when error is included in the code I would like to put the following code: Code: sjlog using "${route_sjlog_files}\example_35" , rep…
Merging several columns to categories of one variableHi, I have to merge the five columns (poor to excellent) as five categories of one variable health …
Time formatHello all, I have a dataset read in from Excel and I have a problem with the variable of the date. I…
Linear regressionHi, I would really appreciate if someone could help me with this question. "Given the linear model, …
Subscribe to:
Post Comments (Atom)
0 Response to Creating variable from searching multiple strings
Post a Comment