Hi,
I am working on recurrent events analysis. I have to merge two data sets. The first data set has ID variable as well as t0 (time at the beginning of risk) and t1 (time at event). The second data set has dates of supply of relevant medication. Each ID variable has multiple records in both datasets.

DataSet 1
ID t0 t1 Record
A 01 Jan 2017 01 Jun 2017 1
A 01 Jun 2017 31 Dec 2017 2
B 01 Feb 2018 31 Dec 2018 1
B 31 Dec 2018 30 Jun 2019 2
DataSet 2
ID Date of Supply
A 01 Nov 2016
A 01 Jan 2017
A 01 Sept 2017
A 01 Oct 2017
B 01 Jan 2018
B 01 Sept 2018
B 01 May 2019
B 01 July 2019
B 01 Sept 2019
When I merge 2 datasets either by joinby or m:m merge , I get the following (after deleting _merge variable).
ID t0 t1 Record Date of Supply
A 01 Jan 2017 01 Jun 2017 1 01 Nov 2016
A 01 Jun 2017 31 Dec 2017 2 01 Jan 2017
A 01 Jun 2017 31 Dec 2017 2 01 Sept 2017
A 01 Jun 2017 31 Dec 2017 2 01 Oct 2017
B 01 Feb 2018 31 Dec 2018 1 01 Jan 2018
B 31 Dec 2018 30 Jun 2019 2 01 Sept 2018
B 31 Dec 2018 30 Jun 2019 2 01 May 2019
B 31 Dec 2018 30 Jun 2019 2 01 July 2019
B 31 Dec 2018 30 Jun 2019 2 01 Sept 2019
As I am interested in cumulative dose of medication for each Record, I am keen for guidance on
a. The best way to match the Date of Supply to Record

I thank you in advance.

Regards,
Sateesh