Calculating Newey-West Standard Errors for a Distributed Lag Model (in R)

Viewed 25

This is my first post, so please suggest any improvements to the title or question itself.

I am regressing two xts objects, and want to re-estimate several distributed lag regression models using Newey-West HAC standard errors.

However, the NeweyWest function doesn't work when using a the 'lag()' structure.

Are there ways to make NeweyWest function with lags or alternative ways to implement HAC standard errors into a linear model?

#Packages used

  library(AER)
  library(xts)
  library(zoo)
  library(dynlm)
#UK Patents data (y)

structure(c(9.8, 10.83, 11.4, 11.41, 13.32, 14.43, 15.45, 16.63, 
17.85, 20.03, 19.03, 19.53, 18.44, 18.6, 16.99, 16.35, 17.06, 
16.2), class = c("xts", "zoo"), index = structure(c(1009843200, 
1041379200, 1072915200, 1104537600, 1136073600, 1167609600, 1199145600, 
1230768000, 1262304000, 1293840000, 1325376000, 1356998400, 1388534400, 
1420070400, 1451606400, 1483228800, 1514764800, 1546300800), tzone = "UTC", tclass = c("POSIXct", 
"POSIXt")), .Dim = c(18L, 1L))
#UK research expenditure data (x) 

structure(c(70.096, 68.022, 103.302, 147.959, 214.128, 264.875, 
276.489, 500.08, 938.86, 614.827, 549.658, 689.796, 574.263, 
633.687, 789.369, 1049.882, 1165.305, 1271.504), class = c("xts", 
"zoo"), index = structure(c(1009843200, 1041379200, 1072915200, 
1104537600, 1136073600, 1167609600, 1199145600, 1230768000, 1262304000, 
1293840000, 1325376000, 1356998400, 1388534400, 1420070400, 1451606400, 
1483228800, 1514764800, 1546300800), tzone = "UTC", tclass = c("POSIXct", 
"POSIXt")), .Dim = c(18L, 1L))
#If manually setting up lags, it can work, but only with a single lag model: 
> NW_VCOV <- NeweyWest(lm(UK_PATENTS_xts[-1] ~ UK_RDDUSDPPP_xts[-18]), 
+                     prewhite = F,
+                     adjust = T)

#But using the lag() structure it doesn't:
> NW_VCOV <- NeweyWest(lm(UK_PATENTS_xts ~ lag(UK_RDDUSDPPP_xts)), 
+                          prewhite = F,
+                          adjust = T)
    
    Error in dimnames(x) <- dn : 
      length of 'dimnames' [1] not equal to array extent

Any advice would be greatly appreciated, as my econometrics lecturer doesn't seem to know either!

0 Answers
Related