Tried to merge and used the condition afterwards. It seemed to work,
However the section 2) below raised another question. I have several
observations per id in both files, does it matter?
Kit Baum wrote:
1) joinby is rarely the answer to a question. It is a quite
specialised tool corresponding to the outer join in database lingo.
It will not help you here; it would combine each obs on id (first ds)
with each obs on id (second ds) leading to observations belonging to
2) If you have single records in each database per id, it is a
straightforward one-to-one merge on the id field.
3) After merging you may apply the if condition to the result with
keep if start_date1<=start_date2 & end_date1>=end_date2
Dataset 1 has variables:
id start_date1 end_date1 sum1
Dataset 2 has variables:
id start_date2 end_date2 sum2
I need to join/merge these files by variable id and a condition:
start_date1<=start_date2 & end_date1>=end_date2