Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Creating id number by subgroup


From   lalencar <[email protected]>
To   [email protected]
Subject   st: RE: Creating id number by subgroup
Date   Tue, 6 Jan 2009 10:50:05 -0800

I believe the following will do the job:

egen var1 = group (id title) 

Luciana

Luciana M. Alencar, M.D.
UCSD - Hamilton Glaucoma Center
Tel: 858-5345334 / Fax: 858-8220615
[email protected]
9500 gilman Dr., Dept 0946, room 174
La Jolla, CA; 92093-0946


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Mike Kim
Sent: Tuesday, January 06, 2009 10:06 AM
To: [email protected]
Subject: st: Creating id number by subgroup

Dear statalisters,

I would like to create 'var1' in the following table based on id and title.
I tried "bysort id title: gen var2=_n" and this creates var2 which is 
different from var1.
I also tried "by id: egen var1=group(title)", but egen does not allow 'by'.
How can I create var1?

id  title  var1  var2
1    A      1    1
1    A      1    2
1    B      2    1
1    B      2    2
1    B      2    3
2    C      1    1
2    C      1    2
2    C      1    3
2    D      2    1
2    D      2    2
3    E      1    1
.......

Thank you in advance.
Mike.

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



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