lag.plm: lag, lead, and diff for panel data

Description Usage Arguments Details Value Note Author(s) See Also Examples

Description

lag, lead, and diff functions for class pseries.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
lead(x, k = 1L, ...)

## S3 method for class 'pseries'
lag(x, k = 1L, shift = c("time", "row"), ...)

## S3 method for class 'pseries'
lead(x, k = 1L, shift = c("time", "row"), ...)

## S3 method for class 'pseries'
diff(x, lag = 1L, shift = c("time", "row"), ...)

Arguments

x

a pseries object,

k

an integer, 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 = -1L) yields the same as lead(x, k = 1L). If k is an integer with length > 1 (k = c(k1, k2, ...)), a matrix with multiple lagged pseries is returned,

...

further arguments (currently none evaluated).

shift

character, either "time" (default) or "row" determining how the shifting in the lag/lead/diff functions is performed (see Details and Examples).

lag

integer, the number of lags for the diff method, can also be of length > 1 (see argument k) (only non–negative values in argument lag are allowed for diff),

Details

This set of functions perform lagging, leading (lagging in the opposite direction), and differencing operations on pseries objects, i. e., they take the panel structure of the data into account by performing the operations per individual.

Argument shift controls the shifting of observations to be used by methods lag, lead, and diff:

For consecutive time periods per individual, a switch of shifting behaviour results in no difference. Different return values will occur for non-consecutive time periods per individual ("holes in time"), see also Examples.

Value

Note

The sign of k in lag.pseries results in inverse behaviour compared to stats::lag() and zoo::lag.zoo().

Author(s)

Yves Croissant and Kevin Tappe

See Also

To check if the time periods are consecutive per individual, see is.pconsecutive().

For further function for 'pseries' objects: between(), Between(), Within(), summary.pseries(), print.summary.pseries(), as.matrix.pseries().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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, 3L)
diff(z, 2L)

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

## demonstrate behaviour of shift = "time" vs. shift = "row"
# delete 2nd time period for first individual (1978 is missing (not NA)):
Em_hole <- Em[-2L, ]
is.pconsecutive(Em_hole) # check: non-consecutive for 1st individual now

# original non-consecutive data:
head(Em_hole$emp, 10) 
# for shift = "time", 1-1979 contains the value of former 1-1977 (2 periods lagged):
head(lag(Em_hole$emp, k = 2L, shift = "time"), 10L)
# for shift = "row", 1-1979 contains NA (2 rows lagged (and no entry for 1976):
head(lag(Em_hole$emp, k = 2L, shift = "row"), 10L)

plm documentation built on Sept. 21, 2021, 3:01 p.m.