Hello,
I've been trying to use the regexm command to match certain keywords within a string variable. However, I was wondering if anyone knows how to get an exact match for a word within a sentence? I've been using the code below and can figure out how to match something at the beginning or end of the string, but often the word I'm looking for is in the middle of the string. For certain words it will also pick up the word within a another word. (eg. I want to pick up the word STI but it also picks up other words like STITCH or STILL. Thanks. The code I've tried using STATA 13/SE is below:
gen STI_extracted = 1 if(regexm(lab_comments1, "(STI)|(SHS)|(ROUTINE)"))
gen STI_extracted = 1 if(regexm(lab_comments1, "(^STI)|(SHS)|(ROUTINE)"))
Thanks
I've been trying to use the regexm command to match certain keywords within a string variable. However, I was wondering if anyone knows how to get an exact match for a word within a sentence? I've been using the code below and can figure out how to match something at the beginning or end of the string, but often the word I'm looking for is in the middle of the string. For certain words it will also pick up the word within a another word. (eg. I want to pick up the word STI but it also picks up other words like STITCH or STILL. Thanks. The code I've tried using STATA 13/SE is below:
gen STI_extracted = 1 if(regexm(lab_comments1, "(STI)|(SHS)|(ROUTINE)"))
gen STI_extracted = 1 if(regexm(lab_comments1, "(^STI)|(SHS)|(ROUTINE)"))
Thanks
Comment