[R-SIG-Finance] Vector autoregression with Newey-West standard errors

Liviu Andronic landronimirc at gmail.com
Wed Jun 10 15:57:27 CEST 2009


Dear Matthieu,

On Tue, Jun 9, 2009 at 7:34 PM, Matthieu
Stigler<matthieu.stigler at gmail.com> wrote:
> to get it working you should replace:
>        attr(equation[[colnames(yend)[i]]]$terms, "intercept") <- 1
> by:
>        attr(equation[[colnames(yend)[i]]]$terms, "intercept") <- NULL
>
I modified the source as suggested, and rebuilt the package, and it
indeed solves the issue for the dummy example that I posted. It does
not, strangely, solve the issue for the real data I'm working on [1];
to be precise, it generates a different error.
[1] http://s000.tinyupload.com/index.php?file_id=00314428626037547016

> require(vars)
> head(tempqdf)
  yldave3 spread5 gdpc1LogRetLag1
1   3.588  0.4850           4.624
2   3.532  0.4454           5.416
3   3.604  0.3874           1.072
4   3.880  0.1964           9.716
5   3.992  0.1086           5.368
6   3.864  0.2300           8.032
> temp <- VAR(tempqdf[,c("yldave3", "spread5", "gdpc1LogRetLag1")], p=1,
+ 	type="const")
> #coef(temp)
> class(temp)
[1] "varest"
> temp.varest.lm <- (temp$varresult$yldave3)
> class(temp.varest.lm)
[1] "lm"
> head(model.matrix(temp.varest.lm))
  yldave3.l1 spread5.l1 gdpc1LogRetLag1.l1 const
1      3.588     0.4850              4.624     1
2      3.532     0.4454              5.416     1
3      3.604     0.3874              1.072     1
4      3.880     0.1964              9.716     1
5      3.992     0.1086              5.368     1
6      3.864     0.2300              8.032     1
> meat(temp.varest.lm)
                   yldave3.l1 spread5.l1 gdpc1LogRetLag1.l1   const
yldave3.l1            138.940    -1.8838           -18.3958 12.0313
spread5.l1             -1.884     3.0398             3.3658  0.1875
gdpc1LogRetLag1.l1    -18.396     3.3658            30.7899 -0.5654
const                  12.031     0.1875            -0.5654  1.1552
> bread(temp.varest.lm)
Error in if (attr(z$terms, "intercept")) sum((f - mean(f))^2) else sum(f^2) :
  argument is of length zero
> vcovHC(temp.varest.lm)
Error in if (attr(z$terms, "intercept")) sum((f - mean(f))^2) else sum(f^2) :
  argument is of length zero


# On JGR, the error above starts popping up after executing the line below.
> temp.varest.lm <- (temp$varresult$yldave3)
> Error in if (attr(z$terms, "intercept")) sum((f - mean(f))^2) else sum(f^2) :
  argument is of length zero

Is there a way to  work around this error?


> B: I was working myself on a Eicker -White cov-mat and implemented it in a
> package (dev version of tsDyn) that also contains VAR, so you could use this
> one.
>
Thank you for the pointer. For the moment I would prefer to stick to
VAR(), mostly for the extensive methods and functions applicable to
varest models.

Thank you,
Liviu



More information about the R-SIG-Finance mailing list