I have data which looks like this:
N = 10
ISIC <- c(111, 112, 113, 114, 115, 111, 112, 113, 114, 115)
n_workers <- rnorm(N)
year_month <- c(201801, 201801, 201802, 201801, 201802, 201901, 201902, 201901, 201902, 201903)
year <- c(2018, 2018, 2018, 2018, 2018, 2019, 2019, 2019, 2019, 2019)
month <- c(01, 01, 02, 01, 02, 01, 02, 01, 02, 03)
df <- data.frame(ISIC, n_workers, year_month, year, month)
How do I add leads and lags for the variable n_workers
based on both ISIC
, month
and year
in this situation? So, the 1 year lead ISIC == 111
for 201801
should be ISIC == 111
in 201901
.
Thank you.