Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Create the count of occurances in a panel


From   Matt Dobra <mattdobra@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Create the count of occurances in a panel
Date   Fri, 22 Apr 2005 15:59:23 +1000

If the variable name for your ids is "id", and assuming your variable for years is named "year", you could do:

collapse (count) year, by(id)

Which would turn (making up numbers for years here), for example:

id year
4001 1990
4001 1991
4001 1992
4002 1990
4002 1991
4003 1992
4003 1993
4003 1994
4003 1995
4004 1992
4004 1993
4004 1994
4008 1998
4172 1995
4172 1996

into

id year
4001 3
4002 2
4003 4
4004 3
4008 1
4172 2

Matt

wying1@umbc.edu wrote:


Dear users,

I have a list of person ids as follows.

1. 4001
2. 4001
3. 4001
4. 4002
5. 4002
6. 4003
7. 4003
8. 4003
9. 4003
10. 4004
11. 4004
12. 4004
13. 4008
14. 4172
15. 4172

The number of occurances represents the years they are in a panel
dataset. For example, person 4001 have appeared three years in the
panel, and person 4003 has occured four years in the panel.

I am trying to create a count of years those individuals occur in the
panel, i.e., 3 for person 4001, 4 for person 4003, 3 for person 4004, 1
for person 4008, etc. I have some thoughts to do this by reshaping the
data, but doubt that is the most efficient way to do. Is there any fast
way to do it in STATA?


Thanks,
Ying

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index