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

Re: st: Recoding strategy


From   wgould@stata.com (William Gould)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Recoding strategy
Date   Wed, 03 Jul 2002 16:39:40 -0500

Nick Winter <nwinter@policystudies.com> wrote, 

> I've got six variables, wherein respondents ranked the importance of each of
> six strategies.  For the vast majority of cases, respondents assigned one
> rank of "1", one of "2" and so on.
>
> Some respondents, however, ranked more than one strategy with the same rank.
> This takes many forms: [...]
>
> We want to do the following [...]  For multiple identical rankings, randomly
> order them, and then rank subsequent ranks sequentially from there.  So, for
> example, if the data look like this for two cases:
>
>      S1 S2 S3 S4 S5 S6
>       1  1  2  3  4  5
>       3  1  1  4  5  6
>
> I would want to change it to:
>
>      S1 S2 S3 S4 S5 S6
>       1  2  3  4  5  6
>       3  1  2  4  5  6
 
I suggest

        . reshape long S, i(id)
        . gen u = uniform()
        . sort id S u
        . by id: replace S = _n
        . reshape wide S, i(id)

where id is a variable that uniquely identifies each of the observations.

-- Bill
wgould@stata.com
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index