Conditional merge, based an event happening between two panel observations
问题 I have a panel dataset: panel and a dataset with a list of events: Events . For the panel dataset, an equal panelID shows that two observations belong together. panelID = c(1:50) year= c(2001:2010) country = c("NLD", "GRC", "GBR") n <- 2 library(data.table) set.seed(123) Panel <- data.table(panelID = rep(sample(panelID), each = n), country = rep(sample(country, length(panelID), replace = T), each = n), year = c(replicate(length(panelID), sample(year, n))), some_NA = sample(0:5, 6), some_NA