Bookmark and Share

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]

st: Group identifiers within group


From   <[email protected]>
To   <[email protected]>
Subject   st: Group identifiers within group
Date   Fri, 7 Jun 2013 12:02:30 +0000

Dear all, 

I'm trying to create a new variable with a group identifier, but on a 2nd level.  For the variable "GroupID" I did the following: 

by AnimalID:  gen GroupID = _n

Is it possible to do the same but on the 2nd level (based on AnimalID AND Parity), so that I will get the values as shown in the last variable "2nd level"?
I've tried: by TierID: gen var1 = group(par), but this doesn't seem to do the job.  Data are sorted by AnimalID and then Parity.


AnimalID                             Parity                    GroupID              2nd level?
CH003381451070             3                             1                             1
CH003381451070             4                             1                             2
CH003381451070             4                             1                             2
CH003381462076             2                             2                             1
CH003381462076             3                             2                             2
CH003381462076             3                             2                             2
CH110003099108             10                           3                             1
CH110003099108             10                           3                             1
CH110003099108             11                           3                             2
CH110003099108             11                           3                             2
CH110003099108             11                           3                             2
CH110003099108             12                           3                             3
CH110003099108             12                           3                             3
CH110003099108             12                           3                             3

Thanks for your help!
Isabel

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index