3

I'd like to get some help for rolling window vector error correction model (VECM) estimation in R. I have a data of almost 1600 observations and I would like to estimate the VECM by using a rolling window that consists of let's say 300 observations. (First three estimation windows should be [1:300], [2:301], [3:302], ...)

I'd like to collect the error correction coefficients of every estimation window and observe how they change in time. I'm not so familiar with R.

I have already used rollapplyr method and one form of the code I have used goes like this:

vec <- function(x) lineVar(x, lag=1, include="const", model="VECM", estim="ML")
rollapplyr(data5, 300, vec, by.column = FALSE )

or alternatively:

vec <- function(x) c(VECM(x, lag=2, r = 1, include = c("const", "trend", "none", "both"), beta = NULL, estim = c("2OLS", "ML"), LRinclude = c("none", "const","trend", "both"), exogen = NULL)) 
rollapplyr(data5, 300, vec, by.column = FALSE )

However, these gives me this for every row:

[1,] Numeric,2796 Numeric,8    2 1398 1400 8    4     "linear" Numeric,2796  Numeric,5592 "const" 1   Numeric,8400 1394        FALSE  0         
[2,] Numeric,2796 Numeric,8    2 1398 1400 8    4     "linear" Numeric,2796  Numeric,5592 "const" 1   Numeric,8400 1394        FALSE  0         
[3,] Numeric,2796 Numeric,8    2 1398 1400 8    4     "linear" Numeric,2796  Numeric,5592 "const" 1   Numeric,8400 1394        FALSE  0
...

And this:

   model.specific
[1,] List,9        
[2,] List,9        
[3,] List,9
....

This rollapplyr method works when I use simple linear regression model. However, when I'm trying to estimate VECM this seems not be the case. What should I do?

drump
  • 31
  • 3
  • Please make any package dependencies explicit in your question. What package includes the `VECM()` function you're using? – ulfelder Oct 27 '15 at 11:40
  • @ulfelder For VECM() estimation I am using tsDyn package and for rollapplyr() I am using the zoo package. – drump Nov 02 '15 at 20:15
  • I finally managed to make the model work. The code I'm using is this: `fun <- function(x) coef(lineVar(x, lag=2, include="const", model="VECM", estim="ML"), data = as.data.frame(x))` and `belgroll<- rollapplyr(belgia, 521, fun, by.column = FALSE)` I would still like to have P values next to the printed coefficients. How could that be done? – drump Nov 02 '15 at 20:15

0 Answers0