Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: EGEN GROUP where order doesn't matter?

 From Don Ruby To statalist@hsphsun2.harvard.edu Subject Re: st: EGEN GROUP where order doesn't matter? Date Sat, 12 Feb 2011 17:41:52 -0500

```This works great.

Thanks,

Don

On Sat, Feb 12, 2011 at 6:25 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> Here is an example. You need to install -rowsort- first. -search
> 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 <njcoxstata@gmail.com> 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 <goofnmick@gmail.com> 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/
>

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