How do I generate a dummy variable which is zero before year and takes the value 1 from year and onwards to 2019?
Original data:
structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8), Year = c(2017, 
2015, 2018, 2018, 2018, 2018, 2018, 2018)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -8L))
what I need:
structure(list(id = c(1, 2, 3, 4, 5, 6, 7, 8), Year = c(2017, 
2015, 2018, 2018, 2018, 2018, 2018, 2018), `2015` = c(NA, 1, 
NA, NA, NA, NA, NA, NA), `2016` = c(NA, 1, NA, NA, NA, NA, NA, 
NA), `2017` = c(1, 1, NA, NA, NA, NA, NA, NA), `2018` = c(1, 
1, 1, 1, 1, 1, 1, 1), `2019` = c(1, 1, 1, 1, 1, 1, 1, 1)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -8L))
 
    