lag
From plm v1.65
by Yves Croissant
lag, lead, and diff for panel data
lag, lead, and diff functions for class pseries.
 Keywords
 classes
Usage
"lag"(x, k = 1, ...)
"lead"(x, k = 1, ...)
"diff"(x, lag = 1, ...)
Arguments
 x
 a
pseries
object,  k
 an integer vector, the number of lags for the
lag
andlead
methods (can also be negative). For thelag
method, a positive (negative)k
gives lagged (leading) values. For thelead
method, a positive (negative)k
gives leading (lagged) values, thus,lag(x, k = 1)
yields the same aslead(x, k = 1)
. Ifk
is an integer vector with length > 1 (k = c(k1, k2, ...)
) amatrix
with multiple laggedpseries
is returned,  lag
 the number of lags for the
diff
method (only nonnegative values for parameterlag
are allowed indiff
),  ...
 further arguments.
Value

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.
Note
The sign of k
in lag.pseries
results in inverse behavior compared to lag
and lag.zoo
.
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
.
Examples
library(plm)
# 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))
Community examples
Looks like there are no examples yet.