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: EGEN GROUP where order doesn't matter?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: EGEN GROUP where order doesn't matter?
Date
Sat, 12 Feb 2011 11:25:24 +0000
Here is an example. You need to install -rowsort- first. -search
rowsort- to identify download location. The method applies to any
number of variables.
. l
+-------------+
| var1 var2 |
|-------------|
1. | 1 2 |
2. | 2 1 |
3. | 3 4 |
4. | 4 3 |
+-------------+
. rowsort var*, gen(svar1 svar2)
. l
+-----------------------------+
| var1 var2 svar1 svar2 |
|-----------------------------|
1. | 1 2 1 2 |
2. | 2 1 1 2 |
3. | 3 4 3 4 |
4. | 4 3 3 4 |
+-----------------------------+
. egen group = group(svar*)
. l
+-------------------------------------+
| var1 var2 svar1 svar2 group |
|-------------------------------------|
1. | 1 2 1 2 1 |
2. | 2 1 1 2 1 |
3. | 3 4 3 4 2 |
4. | 4 3 3 4 2 |
+-------------------------------------+
On Sat, Feb 12, 2011 at 10:07 AM, Nick Cox <[email protected]> wrote:
> As I understand you, you seek a group identifier and your rules are
> that (e.g.) x_1 = 1 and x_2 = 2 are equivalent to x_2 = 1 and x_1 = 2.
> If so, -egen, group()- will not do what you want and there is no
> subverting it to do so through an option. Same point with any number
> of variables.
>
> You need another method. Perhaps -egen, rowtotal()- will do. Or you
> need to sort your variables across rows first so that you apply -egen,
> group()- to the row-sorted identifier data.
>
> There was a review of row stuff in
>
> SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata: Rowwise
> (help rowsort, rowranks if installed) . . . . . . . . . . . N. J. Cox
> Q1/09 SJ 9(1):137--157
> shows how to exploit functions, egen functions, and Mata
> for working rowwise; rowsort and rowranks are introduced
>
> Nick
>
> Brandon, a.k.a. Don Ruby <[email protected]> wrote:
>
>> Note, I have 4-tuple identifiers, not just a pair.
>
>
>>> I understand that egen id=group(id1 id2) will create a list such that
>>> the pair (id1.1 id2.1)=1, (id1.2 id2.2)=2 etc. But, the order of the
>>> pair (id1 id2) matters so that the pair (id1.1 id2.1) will not yield
>>> the same value as (id2.1 id1.1).
>>>
>>> How can i make it so that the same value is generated, regardless of
>>> the varlist order?
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/