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

Re: st: counting the time of being in a specific state


From   Edwin Leuven <e.leuven@uva.nl>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: counting the time of being in a specific state
Date   Fri, 3 Sep 2004 14:44:47 +0200 (CEST)

On Fri, 3 Sep 2004, Edwin Leuven wrote:

 id  state  year  count
101   4     1994   1
101   4     1995   2
101   4     1996   3
101   3     1997   1
102   1     1994   1
102   1     1995   2
102   2     1996   1
102   3     1997   1
103   4     1994   1
103   2     1995   1
103   4     1996   1

bysort id state (year): g count = _n
i guess i was too quick: 103 poses a complication

. bysort id: g x= sum(s!=s[_n-1])
. bysort id x: g count = _n

should work

ed.
*
*   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