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

Re: st: Extracting Numbers from Strings

To   "" <>
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.

*   For searches and help try:

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