Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Finding individuals that had the same ranking across choices.


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Finding individuals that had the same ranking across choices.
Date   Tue, 27 Nov 2012 18:54:28 +0000

Thanks. The signature there is a repeated "321", so let's put that in
a string variable.

bysort id choice (alt) : gen allrankings = string(ranking[1])
by id choice : replace allrankings = allrankings[_n-1] +
string(ranking) if _n > 1
by id choice : replace allrankings = allrankings[3]
bysort id (allrankings) : gen same = allrankings[1] == allrankings[_N]

See also

http://www.stata.com/support/faqs/data-management/listing-observations-in-group/

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by: step
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q1/02   SJ 2(1):86--102                                  (no commands)
        explains the use of the by varlist : construct to tackle
        a variety of problems with group structure, ranging from
        simple calculations for each of several groups to more
        advanced manipulations that use the built-in _n and _N


Nick

On Tue, Nov 27, 2012 at 6:28 PM, sanja_lutzeyer@ncsu.edu
<slutzey@ncsu.edu> wrote:

> My apologies.... here is an example of the data. Below I show two
> individuals (id 1 and id 2). The first individual always has the same
> ranking across the 8 choices.... 3, 2, 1.
> The second individual has different choices for different questions.
> I want to generate an indicator for individuals who, like id 1 in this
> case, always have the same ranking across choices.
> I hope this makes more sense?
>
> id choice alt ranking
> 1     1      1     3
> 1     1      2     2
> 1     1      3     1
> 1     2      1     3
> 1     2      2     2
> 1     2      3     1
> 1     3      1     3
> 1     3      2     2
> 1     3      3     1
> 1     4      1     3
> 1     4      2     2
> 1     4      3     1
> 1     5      1     3
> 1     5      2     2
> 1     5      3     1
> 1     6      1     3
> 1     6      2     2
> 1     6      3     1
> 1     7      1     3
> 1     7      2     2
> 1     7      3     1
> 1     8      1     3
> 1     8      2     2
> 1     8      3     1
> 2     1      1     3
> 2     1      2     2
> 2     1      3     1
> 2     2      1     2
> 2     2      2     1
> 2     2      3     3
> 2     3      1     3
> 2     3      2     1
> 2     3      3     2
> 2     4      1     1
> 2     4      2     2
> 2     4      3     3
> 2     5      1     3
> 2     5      2     2
> 2     5      3     1
> 2     6      1     3
> 2     6      2     1
> 2     6      3     2
> 2     7      1     2
> 2     7      2     3
> 2     7      3     1
> 2     8      1     1
> 2     8      2     3
> 2     8      3     2
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index