Hi everyone,
I'm having trouble to create a lagged variable using dplyr
. I have a panel dataset with 13 variables that I would like to lag.
NUTS2 Year GDP GDP_lag
1 2000 11689.00 11689.00
2 2000 4797.11 4797.11
3 2000 33533.84 33533.84
4 2000 57659.46 57659.46
5 2000 12378.81 12378.81
1 2001 13589.00 11689.00
2 2001 4959.32 4959.32
3 2001 34117.68 33533.84
4 2001 57659.46 57659.46
5 2001 12378.81 12378.81
My current code is
group_by(NUTS2_CODE) %>%
dplyr::mutate(lag1 = dplyr::lag(GDP, n = 1, default = NA)) %>%
as.data.frame()
Data_long2_lagged
The code runs through and I get the same values for the year and NUTS2 region.
Can someone help me and tell me what I am doing wrong?
May thanks!