xtshift: Lag or lead a panel data variable

Description Usage Arguments Details References See Also Examples

Description

Function to lag/lead a panel variable in a data frame with an xtdata attribute. Based on the shift function by TszKin Julian Chan.

Usage

1
  xtshift(data, variable, k = 1)

Arguments

data

a data frame carrying an xtdata attribute.

variable

the variable to lag/lead.

k

the number of lags/leads.

Details

You might want to use the xtlag and xtlead convenience wrappers:

References

Christopher Gandrud, "Slide: one function for lag/lead variables in data frames, including time-series cross-sectional data", http://christophergandrud.blogspot.com/2013/05/slide-one-function-for-laglead.html

See Also

xtdata

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Load QOG demo datasets.
data(qog.demo)
# Subset to a short series.
QOG = xtsubset(qog.ts.demo, year %in% 2008:2012 & cname == "United States")
# Lag by one time period.
QOG$L1.wdi_gdpc = xtlag(QOG, "wdi_gdpc", -1)
# Lead by two time periods.
QOG$F2.wdi_gdpc = xtlead(QOG, "wdi_gdpc", 2)
# Check results.
QOG[, c("year", "wdi_gdpc", "L1.wdi_gdpc", "F2.wdi_gdpc")]
# Full method.
cbind(QOG, sapply(-2:2, xtshift, data = QOG, variable = "wdi_hec"))

briatte/qogdata documentation built on May 13, 2019, 7:43 a.m.