Oops! Thanks for the correction Nick. I am tempted to pass the blame onto
my new resolution of skipping that morning cup of java. Sorry for the
confusion.
> -----Original Message-----
> From: Nick Winter [mailto:[email protected]]
>
> > -----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)
*
* 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/