Hello,
I have a dataset with a lot of string variables with a common prefix that I want to use when generating a flag variable. More specifically, I have the variables "xx1a", "xx1b", "xx1c" . . . "xx1h", and I want to write a code like:
But that returns the error: "xx1 ambiguous abbreviation". I realize that "xx1" is an ambiguous abbreviation, as there are multiple variables with that same prefix in there (with suffixes "a" through "h"). What is the correct code for making it such that Stata recognizes the command is including the "or" ("|") operator between each of the if statements for each of the variables with the prefix "xx1", so that I'm basically asking Stata to replace flagvar with a value of 1 if the value for any of the variables with prefix "xx1" equals "yyyy", so that I don't have to manually type in:
Thanks!
Robert
I have a dataset with a lot of string variables with a common prefix that I want to use when generating a flag variable. More specifically, I have the variables "xx1a", "xx1b", "xx1c" . . . "xx1h", and I want to write a code like:
Code:
replace flagvar = 1 if xx1`*' == "yyyy"
Code:
replace flagvar = 1 if xx1a=="yyyy" | if xx1b=="yyyy" | if xx1c=="yyyy" | if xx1d=="yyyy" //etc etc
Robert
Comment