Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: -group- within varlist

From   "Terra Curtis" <>
To   <>
Subject   st: RE: RE: -group- within varlist
Date   Tue, 24 Jan 2006 09:22:28 -0500

Thank you, Nick.  Indeed I have subscribed to this list for some time now,
and I have been able to learn a lot about Stata because of it.  I do always
check the FAQ and the archived list postings before asking a question to the
list, but I suppose sometimes I just need a little help being directed to
the answers.  

Again, thank you for your response.  After looking through the FAQ you
suggested, I feel as though I now have a better understanding of the -egen,
group()- function.     

-----Original Message-----
[] On Behalf Of Nick Cox
Sent: Monday, January 23, 2006 6:49 PM
Subject: st: RE: -group- within varlist

You have been on this list for some time and asked many questions, but it
doesn't seem that you are making much use of the help facilities, including
-search- and the FAQs. 

I am not clear what the precise underlying question is here, but the answer
is definitely Yes. 
There are many alternatives. 

Much depends on what you mean by identifier. I take that to mean ideally
that each observation can be identified uniquely. If no such variable
exists, it can always be created with 

. gen long id = _n 

For much more discussion, see

FAQ     . . . . . . . . . . . . . . . . . . . . . . Creating group
        3/01    How do I create individual identifiers numbered
                from 1 upwards?

As far as -egen, group()- is concerned, -by:- indeed can't be used with it.
But that functionality is completely unnecessary. If -by:- were allowed it
would just act if it were the first variable you specified. So whatever
variable you want as a -by:- argument should be the first named. So instead

. egen group = group(b a), by(c) 


. by c: egen group = group(b a) 

you just go 

. egen group = group(c b a) 

But -group()- generates grouping variables, which in general are not

Either way: -egen, group()- is just an application of -by:- in any case. For
more control in this and many other problems, you need to master -by:-
directly. There is a tutorial at 

SJ-2-1  pr0004  . . . . . . . . . . Speaking Stata:  How to move step by:
        Q1/02   SJ 2(1):86-102                                   (no
        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


Terra Curtis
> Since the -egen- function -group- cannot be combined with "by", does 
> anyone know if there is an alternative method (or Stata function) for 
> creating an ID within a varlist?
> PS - I am using Stata 8. 

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index