I have data like this:
and I want to match the first occurrence of a six-digit number, with missing otherwise, in Stata 13.1. I can do this:
but is there a way to abbreviate this? Many programming languages and software packages allow for syntax like this:
to match exactly six occurrences, or something like this, to match anywhere from 3-6 occurrences:
or
The POSIX standard allows this, and Stata's documentation claims that its syntax is "nearly identical" to this standard. Is this supported in Stata?
Thank you,
Michael Anbar
Code:
clear input str14 var1 "a_123456" "b_456789" "777888_c" "12345_d_000111" end
Code:
gen num = regexs(1) if regexm(var1, "([0-9][0-9][0-9][0-9][0-9][0-9])")
Code:
gen num = regexs(1) if regexm(var1, "([0-9]){6}")
Code:
gen num = regexs(1) if regexm(var1, "([0-9]){3,6}")
Code:
gen num = regexs(1) if regexm(var1, "([0-9])\{3,6\}")
The POSIX standard allows this, and Stata's documentation claims that its syntax is "nearly identical" to this standard. Is this supported in Stata?
Thank you,
Michael Anbar
Comment