I have a dataset with start (dt_ini) and end date (dt_fim) of different procedures per hospilalization (id_aih). I would like to know the duration of each hospitalization. The complexity lies in the distribution of different procedures for the same hospitalization over time, since they can either overlap or not. So I need to add the duration of different procedures that do not overlap and take the difference from the max end date to the min start date of procedures which do not overlap. I can have both kind of procedures for the same hospitalization and there is no fixed number of procedures per hospitalization. Below I give some examples of what can happen in my dataset. I am looking for a command which woud give me a final column which total numbers of day for each hospitalization (so, a column with same values for same hospitalizations).
Thank you so much.
Thank you so much.
Code:
input int id_aih int(dt_ini dt_fim) 1 13165 13208 1 13165 13239 1 13165 13269 1 13165 13179 2 13200 13201 2 13205 13208 2 13110 13112 3 13165 13170 3 13168 13172 3 13180 13185 4 13170 13188 4 13165 13300 4 13185 13190 4 13200 13210 end format dt_ini dt_fim %td