plm (version 1.6-5)

lag: lag, lead, and diff for panel data


lag, lead, and diff functions for class pseries.


"lag"(x, k = 1, ...) "lead"(x, k = 1, ...) "diff"(x, lag = 1, ...)


a pseries object,
an integer vector, the number of lags for the lag and lead methods (can also be negative). For the lag method, a positive (negative) k gives lagged (leading) values. For the lead method, a positive (negative) k gives leading (lagged) values, thus, lag(x, k = -1) yields the same as lead(x, k = 1). If k is an integer vector with length > 1 (k = c(k1, k2, ...)) a matrix with multiple lagged pseries is returned,
the number of lags for the diff method (only non--negative values for parameter lag are allowed in diff),
further arguments.


These functions return an object of class pseries except if lag (thus also lead) is called with more than one lag (lead), i. e. length(k) > 1, a matrix is returned.

See Also

For further function for 'pseries' objects: between, Between, Within, summary.pseries, print.summary.pseries, as.matrix.pseries. To check if the time periods are consecutive per individual, see is.pconsecutive.


Run this code
# First, create a pdata.frame
data("EmplUK", package = "plm")
Em <- pdata.frame(EmplUK)

# Then extract a series, which becomes additionally a pseries
z <- Em$output

# compute the first and third lag, and the difference lagged twice
lag(z, 3)
diff(z, 2)

# compute negative lags (= leading values)
lag(z, -1)
lead(z, 1) # same as line above
identical(lead(z, 1), lag(z, -1)) # TRUE
# compute more than one lag at once
lag(z, c(1,2))

Run the code above in your browser using DataCamp Workspace