I am trying to create a sequence that indicates when a value in another variable is not missing. The commands I am using are: sort id dovc
by id:egen maxstop = max(seqstop)
by id:egen maxstart = max(seqstart)
order seqcens seqstart seqstop maxstop maxstart, after(dstp1cens)
A sample of the data (and the results) are below:
| id dovc visnum dstt1 dstp1 seqstart seqstop |
|----------------------------------------------------------------------|
112. | 16 22may2002 1 . . . . |
113. | 16 17may2004 2 01may2002 09mar2012 1 . |
114. | 16 19may2005 3 . 09mar2012 . . |
115. | 16 27may2011 4 . 09mar2012 . . |
116. | 16 22mar2012 5 . 09mar2012 . 1 |
|----------------------------------------------------------------------|
117. | 16 15jul2013 6 16mar2012 . 2 . |
429. | 54 28may2003 1 . . . . |
430. | 54 18may2004 2 . . . . |
431. | 54 20oct2004 3 . . . . |
432. | 54 11feb2005 4 . . . . |
|----------------------------------------------------------------------|
433. | 54 16jun2005 5 . . . . |
434. | 54 20jan2006 6 18aug2005 06mar2013 1 . |
435. | 54 04may2006 7 . 06mar2013 . . |
436. | 54 23nov2006 8 18aug2005 06mar2013 2 . |
437. | 54 23may2007 9 18aug2005 06mar2013 3 . |
|----------------------------------------------------------------------|
438. | 54 23jun2008 10 . 06mar2013 . . |
439. | 54 24aug2010 11 . 06mar2013 . 1 |
440. | 54 04apr2013 12 03may2013 . 4 . |
441. | 54 06jun2014 13 . . . . |
684. | 76 21jul2003 1 . . . . |
|----------------------------------------------------------------------|
685. | 76 02jun2004 2 . . . . |
686. | 76 08jun2005 3 . . . . |
687. | 76 20jul2006 4 . . . . |
688. | 76 05oct2010 5 . . . . |
689. | 76 16mar2011 6 . 10aug2011 . . |
|----------------------------------------------------------------------|
690. | 76 12jan2012 7 06jan2011 10aug2011 1 1 |
691. | 76 23oct2012 8 08jun2012 . 2 . |
+----------------------------------------------------------------------+
My question is why if dstp1 is not missing, is there no value for seqstop. e.g. line 113 should have seqstop == 1; line 114 seqstop ==2 and so on for the id. However, it is only the last line where there is a dstp1 value that seqstop takes a value. On the other hand, seqstart seems to be working OK.
What am I doing wrong.
Many thanks.
Don
by id:egen maxstop = max(seqstop)
by id:egen maxstart = max(seqstart)
order seqcens seqstart seqstop maxstop maxstart, after(dstp1cens)
A sample of the data (and the results) are below:
| id dovc visnum dstt1 dstp1 seqstart seqstop |
|----------------------------------------------------------------------|
112. | 16 22may2002 1 . . . . |
113. | 16 17may2004 2 01may2002 09mar2012 1 . |
114. | 16 19may2005 3 . 09mar2012 . . |
115. | 16 27may2011 4 . 09mar2012 . . |
116. | 16 22mar2012 5 . 09mar2012 . 1 |
|----------------------------------------------------------------------|
117. | 16 15jul2013 6 16mar2012 . 2 . |
429. | 54 28may2003 1 . . . . |
430. | 54 18may2004 2 . . . . |
431. | 54 20oct2004 3 . . . . |
432. | 54 11feb2005 4 . . . . |
|----------------------------------------------------------------------|
433. | 54 16jun2005 5 . . . . |
434. | 54 20jan2006 6 18aug2005 06mar2013 1 . |
435. | 54 04may2006 7 . 06mar2013 . . |
436. | 54 23nov2006 8 18aug2005 06mar2013 2 . |
437. | 54 23may2007 9 18aug2005 06mar2013 3 . |
|----------------------------------------------------------------------|
438. | 54 23jun2008 10 . 06mar2013 . . |
439. | 54 24aug2010 11 . 06mar2013 . 1 |
440. | 54 04apr2013 12 03may2013 . 4 . |
441. | 54 06jun2014 13 . . . . |
684. | 76 21jul2003 1 . . . . |
|----------------------------------------------------------------------|
685. | 76 02jun2004 2 . . . . |
686. | 76 08jun2005 3 . . . . |
687. | 76 20jul2006 4 . . . . |
688. | 76 05oct2010 5 . . . . |
689. | 76 16mar2011 6 . 10aug2011 . . |
|----------------------------------------------------------------------|
690. | 76 12jan2012 7 06jan2011 10aug2011 1 1 |
691. | 76 23oct2012 8 08jun2012 . 2 . |
+----------------------------------------------------------------------+
My question is why if dstp1 is not missing, is there no value for seqstop. e.g. line 113 should have seqstop == 1; line 114 seqstop ==2 and so on for the id. However, it is only the last line where there is a dstp1 value that seqstop takes a value. On the other hand, seqstart seems to be working OK.
What am I doing wrong.
Many thanks.
Don
Comment