It 'looks like' you have characters that represent dates rather than being actual R dates. so my example accounts for that.
df1 <- data.frame(
stringsAsFactors = FALSE,
Personcode = c(1L, 1L, 2L, 3L, 3L, 3L),
startdate = c("01.01.2010","01.10.2010",
"02.02.2012","05.06.2014","02.02.2018","04.06.2018"),
enddate = c("05.01.2010","15.10.2010",
"10.09.2012","06.06.2014","06.02.2018","04.06.2018"),
eventdate = c("10.10.2010", NA, NA, "23.06.2014", NA, NA)
)
library(tidyverse)
library(lubridate)
(df2 <- tibble(df1) %>% mutate(across(-Personcode,dmy)))
(pcal <- df2 %>% distinct(Personcode,
startdate,
enddate))
(pev <- df2 %>% distinct(Personcode,
eventdate) %>% na.omit())
(rejoin <- full_join(pcal,pev))
(df3 <- rejoin %>% rowwise() %>%
mutate(had_event = between(x = eventdate,
left = startdate,
right = enddate)))
(fin <- tidyr::replace_na(df3,
list(had_event=FALSE)))