R +1 Lag

In the last post I gave an example of how to use R to lag a variable in a time-series cross-sectional data set by one time unit. In other words, the value of the lagged variable at time \( t \) the lag would be the value of the unlagged variable at \( t-1 \).

Using the same example variables (Country, Year, Variable) here is how you would lag the variable (VariableLag1) back a year. So, in time t the value of VariableLag would be the value of Variable in \( t+1 \)).

Here is the code:


    library(plyr)
    Data <- ddply(Data, .(country), transform, VariableLag1 =
                            c(Variable[2:(length(Variable))], NA)