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: Create Variable of Groupings


From   Lisa Wang <[email protected]>
To   [email protected]
Subject   st: Create Variable of Groupings
Date   Sat, 2 Nov 2013 17:36:25 +1100

Hi Statalisters,

I want to create a new variable that groups my observations so I can
do something like a panel analysis.

I have variables: identifiers date amount id3. id3 is a concatenation
of identifiers and date.

For instance,

identifiers | date | amount | id3
1007 | 17aug2006 | 10 | 1007 17030
1007 | 17aug2006 | 7 | 1007 17030
1007 | 17aug2006 | 8.5 | 1007 17030
2049 | 26may2009 | 10 | 2049 18043
2049 | 26may2009| 7 | 2049 18043
2049 | 12mar2007 | 7 | 2049 17237
2049 | 12mar2007 | 7 | 2049 17237
2049 |12mar2007 | 7 | 2049 17237

I would like it to output event_id = 1 for 1007 17030, 2 for 2049
18043, 3 for 2049 17237 etc etc....down the page.

But at this point it seems to give me 2681 for 1007 17030, 5130 for
2049 18043 (ie. it is not sequential).

I tried this:
- bysort id* date : gen event_id = _n - but that gives me numbering
WITHIN groups
and also tried:
- egen event_id = group(id3) - but it was not sequential. Do you think
I need to so a by or sort beforehand?


Thank you in advance for all your helpful suggestions as I am
currently stuck and can't proceed.
Lisa
*
*   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