I want to make a table with multiple observations per participant given certain conditions.
The conditions are:
1) the follow-up starts when event 1 occurs for the first time
2) The participant isn't included if event 1 does not occur.
3) the time to event is calculated between the first time for event 1 and the following firstevent 2.
4) If event 2 occurs prior to event 1, it isn't counted.
So below is the example tables:
What I have
id | event1 | event2 |
1 | 20100108 | . |
1 | . | 20110108 |
2 | . | 20110305 |
2 | | 20130110 |
3 | . | 20110510 |
3 | | 20140510 |
3 | 20160510 | . |
4 | 20100210 | |
4 | 20100310 | |
4 | | 20150220 |
What I want
id | event1 | event2 | censored | days |
1 | 20100108 | 20110108 | 0 | 365.5 |
3 | 20160510 | . | 1 | 1827.5 |
4 | 20100210 | 20150220 | 0 | 1470 |
Could you please help me to write the code?
Thank you very much.