Statalist


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

Re: st: Extracting Numbers from Strings


From   Robert A Yaffee <bob.yaffee@nyu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Extracting Numbers from Strings
Date   Wed, 24 Dec 2008 14:48:08 -0500

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

Robert A. Yaffee, Ph.D.
Research Professor
Silver School of Social Work
New York University


Biosketch: http://homepages.nyu.edu/~ray1/Biosketch2008.pdf

CV:  http://homepages.nyu.edu/~ray1/vita.pdf

----- Original Message -----
From: jasonm@ucla.edu
Date: Wednesday, December 24, 2008 2:27 pm
Subject: st: Extracting Numbers from Strings
To: "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>


> I'm trying to extract the first number after a hyphen.
> For example, from x="1234-1" I want to create y=1.
> Thanks.
> 
> *
> *   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/



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