Greetings,
I use Stata 18. I have a big dataset (30+K observations) and one of my variables (Unit Index) has more than 100 categories (alphanumeric strings). I want to write a command that generates a new variable and enters 1 for all observations, which unit index starts with the character "J" followed by numbers.
I tried the following codes, but with no success. I appreciate any advice/help, please.
generate newvar = 0
replace newvar = 1 if strpos (UnitInd, "J[0-9]")
OR
gen newvar = ustrregexs (0) if ustrregexs(UnitInd, "J[0-9]")
Thanks,
Eliot
I use Stata 18. I have a big dataset (30+K observations) and one of my variables (Unit Index) has more than 100 categories (alphanumeric strings). I want to write a command that generates a new variable and enters 1 for all observations, which unit index starts with the character "J" followed by numbers.
I tried the following codes, but with no success. I appreciate any advice/help, please.
generate newvar = 0
replace newvar = 1 if strpos (UnitInd, "J[0-9]")
OR
gen newvar = ustrregexs (0) if ustrregexs(UnitInd, "J[0-9]")
Thanks,
Eliot

Comment