shiftCols | R Documentation |
Create n-lagged/leaded/differenced columns in a data frame with automatic names.
shiftCols(data, panel, type = c("lag", "lead", "difference"), shifts, columns)
data |
data of class |
panel |
the panel or cross-section variable name in the data |
type |
shift type. either "lag", "lead" or "difference" |
shifts |
the number of lags, leads or differences |
columns |
the columns in 'data' to be lagged, leaded or differenced |
data.frame
/ data.table
with new variables
The function will automatically coerce the data.frame object to a data.table
object. (data.table
objects retain their data.frame
class.)
Lawrence R De Geest, lrdegeest@gmail.com
# Using the hours and wages data provided by the panelGMM package:
data("hours_wages")
# shiftCols() is designed to work nicely with the pipe operator `%>%` from `magrittr`:
hours_wages_gmm = hours_wages %>%
shiftCols(data = ., panel=id, type = "difference", shifts = 1, columns=c("lnhr", "lnwg", "kids", "age", "agesq", "disab")) %>%
shiftCols(data = ., panel=id, type = "lag", shifts = 1:4, columns=c("lnhr", "lnwg", "kids", "age", "agesq", "disab"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.