Hi There,

I'm currently working with event-level data (i.e. multiple records/rows per subject) and need to calculate periods of overlapping events for different combinations of events, e.g. A+E or A+B+F etc. The extra complication I have is that an individual can have multiple overlapping records/rows representing the same event, e.g. 3 lots of A that actually overlap and need combining in the first instance, prior to calculating overlapping periods between combinations of distinct events.

I'm unsure how best to tackle this task, but I have provided an extract of the data below for just one subject:

Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double patid str15 event int start_date double end_date
14420018 "A" -21915 -21886
14420018 "A"  11802  11831
14420018 "A"  11935  11964
14420018 "A"  12010  12039
14420018 "A"  12057  12086
14420018 "A"  12095  12124
14420018 "A"  12325  12354
14420018 "A"  12395  12424
14420018 "A"  12570  12599
14420018 "A"  12654  12683
14420018 "A"  12731  12760
14420018 "A"  12759  12788
14420018 "A"  13051  13080
14420018 "A"  13132  13161
14420018 "A"  13193  13222
14420018 "A"  13305  13334
14420018 "A"  13417  13446
14420018 "A"  13585  13614
14420018 "A"  13697  13726
14420018 "A"  13755  13784
14420018 "A"  13893  13922
14420018 "A"  14145  14174
14420018 "A"  14257  14286
14420018 "A"  14340  14369
14420018 "A"  14487  14516
14420018 "A"  14571  14600
14420018 "A"  14602  14631
14420018 "A"  14732  14761
14420018 "A"  14787  14816
14420018 "A"  14866  14895
14420018 "A"  14955  14984
14420018 "A"  15011  15040
14420018 "A"  15033  15062
14420018 "A"  15088  15117
14420018 "A"  15173  15202
14420018 "D"  15204  15233
14420018 "D"  15235  15264
14420018 "D"  15238  15267
14420018 "A"  15257  15286
14420018 "D"  15257  15286
14420018 "D"  15286  15315
14420018 "A"  15364  15393
14420018 "D"  15364  15393
14420018 "A"  15424  15453
14420018 "D"  15424  15453
14420018 "D"  15481  15510
14420018 "A"  15537  15566
14420018 "D"  15537  15566
14420018 "D"  15593  15622
14420018 "A"  15620  15649
14420018 "D"  15652  15681
14420018 "A"  15684  15713
14420018 "A"  15708  15737
14420018 "D"  15708  15737
14420018 "A"  15785  15814
14420018 "D"  15785  15814
14420018 "A"  15847  15876
14420018 "D"  15847  15876
14420018 "A"  15905  15934
14420018 "D"  15905  15934
14420018 "A"  15963  15992
14420018 "D"  15963  15992
14420018 "D"  15988  16017
14420018 "D"  16020  16049
14420018 "D"  16048  16077
14420018 "A"  16076  16105
14420018 "D"  16139  16168
14420018 "A"  16152  16181
14420018 "D"  16152  16181
14420018 "D"  16188  16217
14420018 "A"  16209  16238
14420018 "D"  16209  16238
14420018 "D"  16258  16287
14420018 "A"  16293  16322
14420018 "D"  16293  16322
14420018 "D"  16320  16349
14420018 "A"  16376  16405
14420018 "D"  16376  16405
14420018 "D"  16405  16434
14420018 "A"  16460  16489
14420018 "D"  16460  16489
14420018 "A"  16488  16517
14420018 "D"  16488  16517
14420018 "A"  16516  16545
14420018 "D"  16544  16573
14420018 "D"  16579  16608
14420018 "D"  16635  16664
14420018 "A"  16663  16692
14420018 "D"  16663  16692
14420018 "D"  16691  16720
14420018 "A"  16719  16748
14420018 "D"  16719  16748
14420018 "A"  16775  16804
14420018 "D"  16775  16804
14420018 "D"  16810  16839
14420018 "D"  16838  16867
14420018 "A"  16863  16892
14420018 "D"  16863  16892
14420018 "A"  16894  16923
14420018 "D"  16894  16923
14420018 "D"  16918  16947
14420018 "A"  16951  16980
14420018 "D"  16951  16980
14420018 "A"  17006  17035
14420018 "D"  17006  17035
14420018 "D"  17034  17063
14420018 "D"  17062  17091
14420018 "D"  17090  17119
14420018 "A"  17119  17148
14420018 "D"  17119  17148
14420018 "D"  17146  17175
14420018 "A"  17174  17203
14420018 "D"  17174  17203
14420018 "D"  17230  17259
14420018 "A"  17258  17287
14420018 "D"  17258  17287
14420018 "D"  17286  17315
14420018 "D"  17342  17371
14420018 "B"  17359  17388
14420018 "B"  17370  17399
14420018 "B"  17398  17427
14420018 "B"  17426  17455
14420018 "B"  17450  17479
14420018 "B"  17482  17511
14420018 "B"  17507  17536
14420018 "B"  17538  17567
14420018 "B"  17566  17595
14420018 "B"  17595  17624
14420018 "B"  17622  17651
14420018 "B"  17651  17680
14420018 "B"  17675  17704
14420018 "B"  17706  17735
14420018 "B"  17734  17763
14420018 "B"  17743  17772
14420018 "B"  17764  17793
14420018 "B"  17790  17819
14420018 "B"  17813  17842
14420018 "B"  17818  17847
14420018 "B"  17846  17875
14420018 "B"  17875  17904
14420018 "B"  17902  17931
14420018 "B"  17931  17960
14420018 "B"  17959  17988
14420018 "B"  17987  18016
14420018 "B"  18015  18044
14420018 "B"  18070  18099
14420018 "B"  18098  18127
14420018 "B"  18126  18155
14420018 "B"  18154  18183
14420018 "B"  18183  18212
14420018 "B"  18210  18239
14420018 "B"  18238  18267
14420018 "B"  18266  18295
14420018 "B"  18294  18323
14420018 "B"  18322  18351
14420018 "B"  18351  18380
14420018 "B"  18379  18408
14420018 "B"  18434  18463
14420018 "B"  18462  18491
14420018 "B"  18491  18520
14420018 "B"  18519  18548
14420018 "B"  18549  18578
14420018 "B"  18578  18607
14420018 "B"  18602  18631
14420018 "B"  18631  18660
14420018 "B"  18659  18688
14420018 "B"  18687  18716
14420018 "B"  18714  18743
14420018 "F"  18718  18747
14420018 "B"  18721  18750
14420018 "F"  18730  18759
14420018 "B"  18738  18767
14420018 "B"  18763  18792
14420018 "F"  18763  18792
14420018 "B"  18795  18824
14420018 "F"  18795  18824
14420018 "B"  18826  18855
14420018 "F"  18826  18855
14420018 "B"  18861  18890
14420018 "F"  18861  18890
14420018 "B"  18882  18911
14420018 "F"  18882  18911
14420018 "B"  18917  18946
14420018 "F"  18917  18946
14420018 "B"  18940  18969
14420018 "F"  18940  18969
14420018 "B"  18973  19002
14420018 "F"  18973  19002
14420018 "B"  19001  19030
14420018 "F"  19001  19030
14420018 "B"  19029  19058
14420018 "F"  19029  19058
14420018 "B"  19057  19086
14420018 "F"  19057  19086
14420018 "B"  19082  19111
14420018 "F"  19082  19111
14420018 "B"  19113  19142
14420018 "F"  19113  19142
14420018 "B"  19155  19184
14420018 "F"  19155  19184
14420018 "B"  19183  19212
14420018 "F"  19183  19212
14420018 "B"  19212  19241
14420018 "F"  19212  19241
14420018 "B"  19246  19275
14420018 "F"  19246  19275
14420018 "B"  19275  19304
14420018 "F"  19275  19304
14420018 "B"  19302  19331
14420018 "F"  19302  19331
14420018 "B"  19331  19360
14420018 "F"  19331  19360
14420018 "B"  19358  19387
14420018 "F"  19358  19387
14420018 "B"  19393  19422
14420018 "F"  19393  19422
14420018 "B"  19421  19450
14420018 "F"  19421  19450
14420018 "B"  19442  19471
14420018 "F"  19442  19471
14420018 "B"  19477  19506
14420018 "F"  19477  19506
14420018 "B"  19481  19510
14420018 "F"  19481  19510
14420018 "B"  19533  19562
14420018 "F"  19533  19562
14420018 "B"  19561  19590
14420018 "F"  19561  19590
14420018 "F"  19586  19615
14420018 "B"  19617  19646
14420018 "B"  19645  19674
14420018 "F"  19645  19674
14420018 "B"  19673  19702
14420018 "F"  19673  19702
14420018 "B"  19701  19730
14420018 "F"  19701  19730
14420018 "B"  19729  19758
14420018 "F"  19729  19758
14420018 "B"  19757  19786
14420018 "F"  19757  19786
14420018 "B"  19785  19814
14420018 "F"  19785  19814
14420018 "F"  19810  19839
14420018 "B"  19838  19867
14420018 "F"  19838  19867
14420018 "B"  19870  19899
14420018 "F"  19870  19899
14420018 "B"  19894  19923
14420018 "F"  19894  19923
14420018 "B"  19925  19954
14420018 "F"  19925  19954
14420018 "B"  19948  19977
14420018 "F"  19948  19977
14420018 "B"  19976  20005
14420018 "F"  19976  20005
14420018 "B"  20002  20031
14420018 "B"  20030  20059
14420018 "F"  20030  20059
14420018 "B"  20055  20084
14420018 "F"  20055  20084
14420018 "F"  20081  20110
14420018 "B"  20114  20143
14420018 "F"  20114  20143
14420018 "B"  20153  20182
14420018 "F"  20153  20182
14420018 "B"  20170  20199
14420018 "F"  20170  20199
14420018 "B"  20201  20230
14420018 "F"  20201  20230
14420018 "B"  20208  20237
14420018 "B"  20230  20259
14420018 "F"  20230  20259
14420018 "B"  20258  20287
14420018 "F"  20286  20315
14420018 "B"  20324  20353
14420018 "F"  20324  20353
14420018 "B"  20346  20375
14420018 "F"  20346  20375
14420018 "B"  20382  20411
14420018 "F"  20382  20411
14420018 "B"  20409  20438
14420018 "F"  20409  20438
14420018 "B"  20437  20466
14420018 "F"  20437  20466
14420018 "B"  20472  20501
14420018 "F"  20472  20501
14420018 "B"  20488  20517
14420018 "F"  20503  20532
14420018 "B"  20507  20536
14420018 "B"  20534  20563
14420018 "F"  20534  20563
14420018 "B"  20563  20592
14420018 "F"  20563  20592
14420018 "B"  20594  20623
14420018 "F"  20594  20623
14420018 "B"  20622  20651
14420018 "F"  20622  20651
14420018 "B"  20654  20683
14420018 "F"  20654  20683
14420018 "B"  20710  20739
14420018 "F"  20710  20739
14420018 "B"  20738  20767
14420018 "F"  20738  20767
14420018 "B"  20767  20796
14420018 "F"  20767  20796
14420018 "B"  20794  20823
14420018 "F"  20794  20823
14420018 "B"  20822  20851
14420018 "F"  20822  20851
14420018 "B"  20850  20879
14420018 "F"  20850  20879
14420018 "B"  20878  20907
14420018 "F"  20878  20907
14420018 "B"  20948  20977
14420018 "F"  20948  20977
14420018 "B"  20990  21019
14420018 "F"  20990  21019
end
format %td start_date
format %td end_date
Any insights would be greatly appreciated.

Kind Regards,

Rob.