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/