> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: Thursday, January 16, 2003 9:49 AM
> To: [email protected]
> Subject: st: RE: reduce a variables numbers of digits to 4
> counting from left
>
>
> If there aren't any decimal values in your numeric variable, you may
> destring the variable, i.e.
>
> destring numvar, gen(strvar)
>
> followed by a invoking the substr() function
>
> replace strvar = substr(strvar,1,4)
>
The first step here is going the wrong way, I think. -destring- turns a
string variable into a numeric variable; here we want the reverse.
gen str1 strvar=""
replace strvar = substr(real(numvar),1,4)
Should do the trick in (almost) one step.
In St8a8, it's actually one step:
gen str strvar = substr(real(numvar),1,4)
Nick Winter
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/