Hi,
if you know the number is there and everything is going to be fine
than one line is enough:
generate y=real(substr(x,strpos(x,"-")+1,length(x)-strpos(x,"-")))
otherwise you may be more cautios:
generate y=substr(x,strpos(x,"-")+1,length(x)-strpos(x,"-"))
destring y, generate(y_num)
Best wishes,
Sergiy Radyakin
On Wed, Dec 24, 2008 at 3:09 PM, <[email protected]> wrote:
> 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/
>
*
* 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/