Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[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 <[email protected]>
To
[email protected]
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, [email protected]
<[email protected]> 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/