lag {plm} | R Documentation |
lag, lead, and diff functions for class pseries.
## S3 method for class 'pseries' lag(x, k = 1, ...) ## S3 method for class 'pseries' lead(x, k = 1, ...) ## S3 method for class 'pseries' diff(x, lag = 1, ...)
x |
a |
k |
an integer vector, the number of lags for the |
lag |
the number of lags for the |
... |
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.
The sign of k
in lag.pseries
results in inverse behavior compared to lag
and lag.zoo
.
Yves Croissant
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
.
# 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))