[Solved] Jumping to the next available date when merging panels


It’s more or less the same as your other question. The only change is that you’ll have to set “company,date” as the key columns to perform the join on (note that the order is important – it’ll first sort by company and then by date).

require(data.table) ## 1.9.2
setDT(df)
setDT(event)
setkey(df, company1, date1)
setkey(event, company2, date2)
df[, date := date1]
df[event, roll=-Inf]

   company1      date1 ret1       date    news2
1:        A 02.01.2000  1.1 02.01.2000 blabla11
2:        A 03.01.2000  3.0 03.01.2000 blabla12
3:        A 04.01.2000  1.4 06.01.2000 blabla13
4:        A 08.01.2000  0.6 09.01.2000 blabla14
5:        B 05.01.2000  0.9 06.01.2000 blabla21
6:        B 08.01.2000 -0.1 09.01.2000 blabla22
7:        B 09.01.2000 -0.1 09.01.2000 blabla23

1

solved Jumping to the next available date when merging panels