Hello,
I would like to search strings for the the numbers "5438", and recode the variable "find" = 1 only if the first 4 variables in one of the lists of ops_ko* = "5438".
Here is an example of my code:
My code is obviously wrong, because it extracts all 5438 findings, no matter in which position of the string they are:
Do you have an advice for me?
Thank you very much in advance!
Philip
I would like to search strings for the the numbers "5438", and recode the variable "find" = 1 only if the first 4 variables in one of the lists of ops_ko* = "5438".
Here is an example of my code:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str6(ops_ko1 ops_ko2 ops_ko3 ops_ko4) "543871" "" "89310" "" "5438a" "" "" "" "14447" "575438" "548435" "" "3206" "3203" "545438" "" "545541" "" "" "" end
Code:
gen find=0 foreach var of varlist ops_ko* { recode find 0=1 if regexm(`var', "5438") }
Thank you very much in advance!
Philip
Comment