Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

How to test for autocorrelation after running a panel VAR in R?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...