I am wondering how to test for autocorrelation in the error terms after running a panel VAR in R (using the panelvar package).
In a glm, the procedure would be the following:
library(plm)
#load data
data("Grunfeld", package = "plm")
#estimate de model
g <- plm(inv ~ value + capital, data = Grunfeld, model="random")
#test for serial correlation
pdwtest(g)
With the panel VAR, one could estimate the model doing the following:
library(panelvar)
set.seed(12345)
x = rnorm(240)
z = x + rnorm(240)
y = rep(rnorm(15), each=16) + 2*x + 3*z + rnorm(240)
country = rep(c("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O"), each=16 )
year = rep(seq(1995, 2010), 15)
panel = cbind.data.frame(country,year,x,z,y)
model <- pvargmm(dependent_vars = c("y", "x", "z"),
lags = 1,
transformation = "fod",
data = panel,
panel_identifier=c("country", "year"),
steps = c("twostep"),
system_instruments = FALSE,
max_instr_dependent_vars = 99,
max_instr_predet_vars = 99,
min_instr_dependent_vars = 2L,
min_instr_predet_vars = 1L,
collapse = TRUE
)
However, I have no idea how to test for serial correlation afterwords. I tried the following:
pdwtest(model)
And the result was:
Error in UseMethod("pdwtest") :
no applicable method for 'pdwtest' applied to an object of class "pvargmm"
Any ideas?
question from:
https://stackoverflow.com/questions/65910833/how-to-test-for-autocorrelation-after-running-a-panel-var-in-r