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

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


From   Thomas Mählmann <maehlmann@wiso.uni-koeln.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   AW: st: counting the time of being in a specific state
Date   Fri, 3 Sep 2004 19:21:40 +0200

Dear Edwin,

This is an excellent suggestion! Thanks a lot!

Greetings,

Thomas

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu]Im Auftrag von Edwin Leuven
Gesendet: Freitag, 3. September 2004 14:45
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: counting the time of being in a specific state


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/

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