Hello everyone, please, I need to create a variable that selects pairs of cases that between their MRI dates the distance is <= 18 months.

Thanks !!!


----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str9 id float(nmri date_mri)
"10019723"  1 17015
"10019723"  2 21587
"10054335"  1 20746
"10054335"  2 21517
"10054335"  3 21977
"10087618"  1 14741
"10087618"  2 15810
"10087618"  3 16217
"10087618"  4 16579
"10103855"  1 16528
"10103855"  2 16748
"10103855"  3 17242
"10171615"  1 17455
"10171615"  2 21367
"10171615"  3 21755
"10239623"  1 15756
"10239623"  2 15951
"10239623"  3 16245
"10239623"  4 17465
"10239623"  5 17821
"10239623"  6 19354
"10243938"  1 15282
"10243938"  2 15649
"10243938"  3 21584
"10323354"  1 18499
"10323354"  2 18943
"10323354"  3 19306
"10323354"  4 19708
"10323354"  5 19810
"10323354"  6 20105
"10323354"  7 20248
"10323354"  8 20653
"10323354"  9 20973
"10323354" 10 21168
"10323354" 11 21733
"10323354" 12 21930
"10380065"  1 18290
"10380065"  2 19633
"10380065"  3 21025
"10380065"  4 21453
"10380065"  5 21453
"10398574"  1 15401
"10398574"  2 15552
"10398574"  3 15846
"10446691"  1 13724
"10446691"  2 15585
"10446691"  3 17227
"10446691"  4 18863
"10446691"  5 19057
"10451113"  1 18116
"10451113"  2 19731
"10451113"  3 20168
"10456635"  1 20746
"10482466"  1 20464
"10482466"  2 21913
"10490935"  1 13986
"10490935"  2 18936
"10490935"  3 18936
"10541670"  1 17352
"10541670"  2 17353
"10541670"  3 19159
"10541670"  4 20510
"10541670"  5 20972
"10541670"  6 21615
"10541670"  7 22082
"10571702"  1 16813
"10580120"  1 15240
"10580120"  2 15651
"10580120"  3 17367
"10580120"  4 19496
"10580120"  5 20840
"10580120"  6 21284
"10582578"  1 15596
"10582578"  2 15846
"10582578"  3 16273
"10582578"  4 17274
"10582578"  5 18116
"10582578"  6 19096
"10582578"  7 19118
"10600267"  1 15226
"10600267"  2 15637
"10600267"  3 15637
"10638696"  1 16029
"10638696"  2 16420
"10718399"  1 17165
"10718399"  2 17387
"10718399"  3 18943
"10718399"  4 20707
"10718399"  5 21691
"10746760"  1 19697
"10746760"  2 20504
"10840543"  1 15603
"10840543"  2 16013
"10840543"  3 19918
"10840543"  4 20242
"10840543"  5 20482
"10840543"  6 20724
"10840543"  7 21089
"10840543"  8 21560
"10840543"  9 21895
end
format %tdDD/NN/CCYY date_mri
------------------ copy up to and including the previous line ------------------