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: [email protected]
Date: Wednesday, December 24, 2008 2:27 pm
Subject: st: Extracting Numbers from Strings
To: "[email protected]" <[email protected]>
> 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/