Hello,
I have a dataset that looks like this:
id date1 date2
10180 3/14/18 1/1/18
10180 9/3/18 6/5/18
10180 9/1/18
Basically, my goal is to find a date2 that is the closest to each of the date1 observations, in this case, 9/3/18 in date1 and 9/1/18 in date2.
and I want to make it look like this so I can actually calculate the day difference between date1 and date2 and pick the smallest (absolute) value.
id date1 date2 day_diff
10180 3/14/18 1/1/18 ..
10180 3/14/18 6/5/18 ..
10180 3/14/18 9/1/18 ..
10180 9/3/18 1/1/18 ..
10180 9/3/18 6/5/18 ..
10180 9/3/18 9/1/18 ..
Bu I do not know of any codes that could help me achieve this transformation. I already tried searching for solutions but I am not even sure of what should I call this problem that I am having.
Any input is largely appreciated. Thank you!
I have a dataset that looks like this:
id date1 date2
10180 3/14/18 1/1/18
10180 9/3/18 6/5/18
10180 9/1/18
Basically, my goal is to find a date2 that is the closest to each of the date1 observations, in this case, 9/3/18 in date1 and 9/1/18 in date2.
and I want to make it look like this so I can actually calculate the day difference between date1 and date2 and pick the smallest (absolute) value.
id date1 date2 day_diff
10180 3/14/18 1/1/18 ..
10180 3/14/18 6/5/18 ..
10180 3/14/18 9/1/18 ..
10180 9/3/18 1/1/18 ..
10180 9/3/18 6/5/18 ..
10180 9/3/18 9/1/18 ..
Bu I do not know of any codes that could help me achieve this transformation. I already tried searching for solutions but I am not even sure of what should I call this problem that I am having.
Any input is largely appreciated. Thank you!
Comment