Nick Winter
> > 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)
"St8a8" I like. Or perhaps this mutant should be stopped,
NOW!
Another typo: Nick means
substr(string(numvar),1,4)
as something needs to be a string before you
can extract a substring.
Nick
[email protected]
*
* 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/