Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: generating duration-variable with multi-line spells


From   "Henrik Lindegaard Andersen" <[email protected]>
To   [email protected]
Subject   st: generating duration-variable with multi-line spells
Date   Fri, 1 Dec 2006 11:35:09 +0100

Dear Statalisters,

I want to generate a variable that counts the duration in some state. My data 
looks like this:

id  start   end     state   next_state
1   1       60      1       2
1   61      72      2       3
1   73      204     3       .
2   1       60      2       1
2   61      65      1       1
2   66      67      1       1
2   68      69      1       3
2   70      204     3       .

If the state does not change (as for id 2 from 61 to 69) I want the new 
variable to be missing for all but one line. Therefore
 
gen duration = end - start + 1 if state != next_state

works from some of the spells. But what will work for the spells that are 
split over several lines?



Regards

Henrik Lindegaard

Research Associate
AKF, Institute of Local Government Studies - Denmark
Nyropsgade 37, DK-1602 Copenhagen V

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