Statalist


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

Re: st: Extracting Numbers from Strings


From   [email protected]
To   "[email protected]" <[email protected]>
Subject   Re: st: Extracting Numbers from Strings
Date   Wed, 24 Dec 2008 12:09:03 -0800

I think I'm interested in something more general. I'm trying to capture the first number after the hyphen (wherever the hyphen may be and without any knowledge of what comes after the number following the hyphen).

However, for right now this should work (note that a negative sign is needed to grab from the back of the string):
gen y=substr(d,-1,1)


 gen y = substr(x,1,1)
 destring y, replace
   should do it.
        Robert

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index