shift(x, id, time, delta = 1)
x
id
and time
must yelds to a unique identification of the observations.data(sheston91)
# lag
sheston91$L.pop <- with(sheston91, shift(x = pop, id = country, time = year, delta = 1) )
head(sheston91)
# lead
sheston91$pop.L <- with(sheston91, shift(x = pop, id = country, time = year, delta = -1) )
head(sheston91)
Run the code above in your browser using DataLab