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" <terra.curtis@cambridgefinance.com>
To   <statalist@hsphsun2.harvard.edu>
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-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Monday, January 23, 2006 6:49 PM
To: statalist@hsphsun2.harvard.edu
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
identifiers
        3/01    How do I create individual identifiers numbered
                from 1 upwards?
                http://www.stata.com/support/faqs/data/group.html

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
of 

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

or 

. 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
identifiers. 

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:
step
        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
n.j.cox@durham.ac.uk 

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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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