Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: transforming a variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: transforming a variable
Date   Mon, 6 Jan 2003 15:35:55 -0000

Hans J. Baumgartner

> I would like to transform a variable that contains regional
> classifications in  the form of 333000 into 9333. That is,
> to drop the
> last three digests and ad a leading 9.
>
> I have solved this problem mathematically by dividing with 1000 and
> adding 9000. However, since this is a classification
> category I would
> like to tackle the problem the way described above.
>

Evidently this variable is numeric.

You can do this as a string operation,

e.g. new string variable

. gen str4 new = "9" + substr(string(old),1,3)

(In Stata 8, the -str4- is unnecessary.)

e.g. new numeric variable

. gen new = real("9" + substr(string(old),1,3))

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/



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