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

st: RE: Duration and panel data


From   Stephen McKay <[email protected]>
To   [email protected]
Subject   st: RE: Duration and panel data
Date   Wed, 8 Oct 2003 12:55:26 +0100

There are -reshape-rs and there are -expand-ers for this task.  Nick 
has shown -reshape-,  you might alternatively want to try  -expand-, 
simple example follows.

. list

            id    failure      start        end
  1.         1          1          1          4
  2.         2          1          2          5
  3.         3          0          4          7

. gen duration= end - start

* Note: you probably want to add 1 to this  command given how
* your months are coded

. expand duration

. bysort id: gen month=start + _n -1
* Next command means series of 0s till failure time
. by id: replace failure=0 if failure==1 & _n<_N


. list id month failure start end duration

            id      month    failure      start        end   duration
  1.         1          1          0          1          4          3
  2.         1          2          0          1          4          3
  3.         1          3          1          1          4          3
  4.         2          2          0          2          5          3
  5.         2          3          0          2          5          3
  6.         2          4          1          2          5          3
  7.         3          4          0          4          7          3
  8.         3          5          0          4          7          3
  9.         3          6          0          4          7          3

If, as it sounds, you have multiple observations per id then clearly 
you'll need to include relevant additional var 'id occasion' in place 
of id in these commands.




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index