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

Re: recode, was: Re: st: Re: multiple )))brackets, is there a moreefficient way?


From   Chris Wallace <[email protected]>
To   [email protected]
Subject   Re: recode, was: Re: st: Re: multiple )))brackets, is there a moreefficient way?
Date   Wed, 26 May 2004 13:09:18 +0100

"Annelies Vos" <[email protected]> writes:

> recoding might work (you may have noticed that I'm not a stata expert),
> but like Nick Cox mentioned, it's important to me that I can easily look
> up what I did months later, and for that I don't think recoding is very
> clear.
> But, what would happen if i would use recode, and some of the old country
> specific codes are the same as the new origin (country group)codes? (this
> is, in fact, the case).
>
> example (fake):
> natio 1 = south africa
> natio 2 = somalia
> natio 3 = argentina
> natio 4 = russia
> natio 5 = slovenia
> natio 6 = the netherlands
> -gen origin = natio
> -recode origin 1 2=4 3=3 4 5=2 6=1
> now I should have:
> origin 1 (netherlands) includes natio 6(netherlands)
> origin 2 (eastern europe) includes natio 4, 5 (russia, slovenia)
> origin 3 (latin america) includes natio 3 (argentina)
> origin 4 (africa) includes natio 1, 2 (south africa, somalia)
>
> but I think I would have:
> origin 1 does not exist, it's overwritten because it first became 4, but
> then 4 was recoded in 2, so that now origin 2 (eastern europe) includes
> not only natio 4 and 5, but also natio 1 and 2 (africa)...
> etc.
>
> of course it's easy to check this out in a little fake dataset. But the
> point I'd like to make is that if this is true, recode is not suitable for
> data that are not coded in the same sequence as you want to group them in

Well, it might have been quicker for you to actually check this in a
fake dataset than write that whole email!  As you can see (below),
recode does not do the re-recoding you worried about, but does exactly
what (I think) you wanted:

. input natio

         natio
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. end

. gen origin=natio

. recode origin 1 2=4 3=3 4 5=2 6=1
(origin: 5 changes made)

. l

     +----------------+
     | natio   origin |
     |----------------|
  1. |     1        4 |
  2. |     2        4 |
  3. |     3        3 |
  4. |     4        2 |
  5. |     5        2 |
     |----------------|
  6. |     6        1 |
     +----------------+

Chris.

*
*   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