shift: A function for creating lag and lead variables.

Description Usage Arguments Details Value Source See Also

Description

The function shifts a vector up or down to create lag or lead variables. Note: your data needs to be sorted by date. The date should be ascending (i.e. increasing as it moves down the rows).

Usage

1
shift(VarVect, shiftBy, reminder = TRUE)

Arguments

VarVect

a vector you would like to shift (create lag or lead).

shiftBy

numeric value specifying how many rows (time units) to shift the data by. Negative values shift the data down–lag the data. Positive values shift the data up–lead the data.

reminder

logical. Whether or not to remind you to order your data by the GroupVar and time variable before running shift.

Details

shift a function for creating lag and lead variables, including for time-series cross-sectional data.

Value

a vector

Source

Largely based on TszKin Julian's shift function: http://ctszkin.com/2012/03/11/generating-a-laglead-variables/.

See Also

slide


DataCombine documentation built on May 2, 2019, 11:26 a.m.