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, ...)
- an integer vector, the number of lags for the
leadmethods (can also be negative). For the
lagmethod, a positive (negative)
kgives lagged (leading) values. For the
leadmethod, a positive (negative)
kgives leading (lagged) values, thus,
lag(x, k = -1)yields the same as
lead(x, k = 1). If
kis an integer vector with length > 1 (
k = c(k1, k2, ...)) a
matrixwith multiple lagged
- the number of lags for the
diffmethod (only non--negative values for parameter
lagare allowed in
- further arguments.
These functions return an object of class
lead) is called with more than one lag (lead), i. e.
length(k) > 1, a matrix is returned.
For further function for 'pseries' objects:
as.matrix.pseries. To check if the time periods are consecutive per individual,
# 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 class(z) # compute the first and third lag, and the difference lagged twice lag(z) 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))