I am a new R user. I have a time series cross sectional dataset and, although I have found ways to lag time series data in R, I have not found a way to create lagged time-series cross sectional variables so that I can use them in my analysis.
相关问题
- R - Quantstart: Testing Strategy on Multiple Equit
- Using predict with svyglm
- Reshape matrix by rows
- Extract P-Values from Dunnett Test into a Table by
- split data frame into two by column value [duplica
相关文章
- How to convert summary output to a data frame?
- How to plot smoother curves in R
- Paste all possible diagonals of an n*n matrix or d
- ess-rdired: I get this error “no ESS process is as
- How to use doMC under Windows or alternative paral
- dyLimit for limited time in Dygraphs
- Saving state of Shiny app to be restored later
- How to insert pictures into each individual bar in
For cross-sectional time-series data the package plm is very useful. It has a lag function that takes into account the panel nature of the data.
One problem with the package is that using with (or within or transform) gives you the wrong answer.
So be careful.
Here's how you could use the
lag()
function withzoo
(and panel series data):Lag forward by 1:
Lag backward by 1:
As Dirk mentioned, be careful with the meaning of lag in the different time series packages. Notice how
xts
treats this differently: