Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Extracting Numbers from Strings


From   jasonm@ucla.edu
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Extracting Numbers from Strings
Date   Wed, 24 Dec 2008 12:51:44 -0800

This seems to work well.

gen y = regexs(1) if regexm(x,".*-([0-9]+)")

will work if the number after the hyphen is always a positive integer. The same approach can be easily modified to accommodate negative and/or decimal numbers (i.e., by modifying the regular expression).

-- Phil

*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index