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

st: RE: recoding variables by abbreviating answer categories


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: recoding variables by abbreviating answer categories
Date   Mon, 5 May 2003 11:22:31 +0100

Heleen Sinte Maartensdijk
>
>
> Is there a possibility to abbreviate the answer categories
> of a variable.
> For example: A variable has answercategories existing of 5
> numbers. These
> are codes, and only the first number of the answercategorie
> is important. So
> you want to change the values of the particular variable
> from the 5 numbers
> to only the first number. Say 58722  53879 have to become
> 5, and 38905 39648
> have to become 3, etcetera. How can you reach this result?

If your codes are held as a string variable, use

gen str1 newcode = substr(code,1,1)

In Stata 8 the "str1" is unnecessary.

If your codes are held as a numeric variable

gen newcode = real(substr(string(code),1,1))

or

gen newcode = int(code/10000)

Either way, you are well advised for future reference to check out the
functions available.

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