lag {plm} | R Documentation

## lag, lead, and diff for panel data

### Description

lag, lead, and diff functions for class pseries.

### Usage

    ## 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, ...)

### Arguments

`x` | a `pseries` object,

`k`

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,

`lag` | the number of lags for the `diff` method, can also be a vector of length > 1 (see argument `k`) (only non–negative values in argument `lag` are allowed for `diff`),
`...` | further arguments.

### Value

`*` | An object of class `pseries`, if the argument specifying the lag has length 1 (argument `k` in functions `lag` and `lead`, argument `lag` in function `diff`).
`*` | A matrix containing the various series in its columns, if the argument specifying the lag has length > 1.

### Note

The sign of `k` in `lag.pseries` results in inverse behavior compared to `lag` and `lag.zoo`.

### Author(s)

Yves Croissant

### 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

    # 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 and diff at once
    # (each returns matrix)
    lag(z, c(1,2))
    diff(z, c(1,2))

[Package plm version 1.6-6 Index]