Learn R Programming

DataCombine (version 0.1.11)

shift: A function for creating lag and lead variables.

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

shift(VarVect, shiftBy)

Arguments

Value

  • a vector

source

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

Details

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

See Also

slide