Sorry, my previous post was incomplete...
Dear all,
I've a question about mata. I'm working with the -regexm()- function in
mata.
-regexm()- function seems to work fine with vectors. The same is not
true for -regexs()-, because a loop is needed.
Is there a way to use -regexs()- function in mata with vectors?
The following is an example:
********************************************************************
clear
input str18 date
20jan2007
16June06
06sept1985
21june04
4july90
9jan1999
6aug99
19august2003
end
*** -regexs()- function works perfectly with stata
gen day = regexs(0) if regexm(date, "^[0-9]+")
list day
tomata
capture mata: mata drop example()
mata
real matrix example(var)
{
/// -regexm()- function seems to work directly with vectors
one = regexm(var, "^[0-9]+")
one
two = J(8, 1, "")
/// the same is not true for -regexs()-. I need a loop. Is there a
faster alternative way?
for (i=1; i<=rows(var); i++) {
if (regexm(var[i], "^[0-9]+")) two[i,1] = regexs(0)
}
two
}
example(date)
end
********************************************************************
Tks in advance, Federico
--
Federico Belotti
Faculty of Economics
Department of Financial and Quantitative Economics
Tor Vergata University
tel: +39 06 7259 5624/25
e-mail: [email protected]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/