I'm using sqlite through the RSQLite package in R.
I have two tables: Table 1 has important columns 'PERMCO' and 'Reporting_Period'. ('Reporting_Period' is an integer date)
Table 2 has important columns 'PERMCO' and 'date'. ('date' is an integer date)
I want to do a left join with table 1 as the left table. Thing is that 'PERMCO' is not unique (row-wise, many duplicates) in the second table.
For a given row of table 1, I want the match from the second table to be the row from table 2 with matching PERMCO that is closest in absolute date to 'Reporting_Period' in the first table.
Not really sure how to do this...
Thank you