[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: transforming a variable
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))
* For searches and help try: