Dear STATAlist

I have a dataset with a starting date (different for each id), and different events which can occur repeatedly. What I am interested in, is the cumulative time duration of each event as a function of follow up time. In the end, this would result in a graph which shows follow up time on the x-axis, and cumulative time duration of each type of event (in this case being hospitalized) over the entire population on the y-axis.

Example based on code below

For event1, ID 8 has the first occurence of the event 16 days after F/U start., with only one day of duration (start and end at same day). So up to day = 15 the cumulative event duration for the entire population would be zero, after this 1. This would remain 1 until after 27 days ID 5 experiences an event with duration of 2 days. So at t = 27 cumulative event duration would be 2, and at t=28 would be 3, and so on.

In this case I present 2 types of events (event1_x and event2_x), there are more. I would like to calculate and visualize cumulative event durations at specific time points (365 days, 730 days etc) and present this in a graph a) separately for each event and b) cumulative over multiple events.

Thank you

Kevin Damman

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double id long(date_fu_start date_start_event1_1 date_end_event1_1 date_start_event1_2 date_end_event1_2 date_start_event2_1 date_end_event2_1 date_start_event2_2 date_end_event2_2)
 1 21024 21722 21728 21954 21957 22057 22064     .     .
 2 19323     .     .     .     .     .     .     .     .
 3 19340     . 19340 20927 20927     .     .     .     .
 4 19558     .     .     .     . 19649 19668 19866 19870
 5 19852 19879 19880 20231 20235     .     .     .     .
 6 19890     .     .     .     .     .     .     .     .
 7 20303 20509 20509     .     . 20328 20359 20425 20425
 8 20493 20509 20509     .     .     .     .     .     .
 9 20521     .     .     .     . 21051 21115     .     .
10 21767     .     .     .     .     .     .     .     .
end
format %tdD_m_Y date_fu_start
format %tdD_m_Y date_start_event1_1
format %tdD_m_Y date_end_event1_1
format %tdD_m_Y date_start_event1_2
format %tdD_m_Y date_end_event1_2
format %tdD_m_Y date_start_event2_1
format %tdD_m_Y date_end_event2_1
format %tdD_m_Y date_start_event2_2
format %tdD_m_Y date_end_event2_2