Hello,
I have a string variable called relationship that describes the relationship between 2 people. Each observation is a person. I am trying to generate a new variable that consolidates the various spellings into one spelling. In the dataex example below, I would want to generate a new variable called relationship_cleaned with the 4 values shown below equal to "Acquaintance". The only way I know how to do this is:
generate relationship_cleaned=.
replace relationship_cleaned = "Acquaintance" if relationship == " Acquaintance" | relationship=="Acquaintance - former roommate"| ....
Could someone please tell me of a way to do the same thing but rather than writing out all the different spellings, changing the value of the new variable if the variable relationship starts with the characters "Acquaintance"? Thank you very much for your time and help!
input str30(relationship)
relationship
1. "Acquaintance"
2. "Acquaintance - former roommate"
3. "Acquaintance - classmate"
4. "Acquaintances"
5. end
Related Posts with replacing values of newly generated string variable if old string variable contains certain characters
Exporting two way table to latexHi, I have two string variables Var1 and Var2 each with 7 categories. I want to create a two way ta…
CMP mata error 3900Hi all, I was trying to use State to run a CMP model with random coefficient. And I got the error b…
Importing data - 1st row (names) not correctlyHello, I want to import an excel spredsheet and use the first row as the name of the variable. For t…
Generate a date variable from another date variable with an if conditionHere I am trying to create a start date (AESTDAT) and end date (AEENDAT) variables from the list bel…
Function HandlesIs there something similar to MATLAB's function handles in MATA? It seems like it would be similar t…
Subscribe to:
Post Comments (Atom)
0 Response to replacing values of newly generated string variable if old string variable contains certain characters
Post a Comment