我有我的数据集,它看起来像这样
然后我用我的r代码
install.packages("vars")
library(vars)
install.packages("plm")
library(plm)
install.packages("panelvar")
library(panelvar)
data <- read.csv("economistdata.csv")
data$year <- as.integer(data$year)
pdata <- pdata.frame(data, index=c("country", "year"), drop.index = TRUE)
summary(pdata)
var_model <- pvargmm(cbind(interest.rates, inflation) ~ 1, data=pdata, lags=2)
granger_test <- causality(var_model, cause="inflation")
summary(granger_test)
granger_test1 <- causality(var_model, cause="interest.rates")
summary(granger_test1)`
我得到错误Error in .subset(x, j) : invalid subscript type 'list'
我试着把它变成一个矢量,但它告诉我年份或国家不存在
我希望它能简单地进行回归分析
我被告知要发布我的数据集,所以:
structure(list(year = c(2019, 2019, 2019, 2019, 2019, 2019, 2019,
2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019,
2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019,
2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019, 2019,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020,
2020, 2020, 2020, 2020, 2020, 2020, 2020, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022,
2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022,
2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022,
2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2022, 2023,
2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023,
2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023,
2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023, 2023,
2023, 2023, 2023, 2023, 2023, 2023), country = c("United States",
"China", "Japan", "Britain", "Canada", "Euro area", "Austria",
"Belgium", "France", "Germany", "Greece", "Italy", "Netherlands",
"Spain", "Czech Republic", "Denmark", "Norway", "Poland", "Russia",
"Sweden", "Switzerland", "Turkey", "Australia", "Hong Kong",
"India", "Indonesia", "Malaysia", "Pakistan", "Philippines",
"Singapore", "South Korea", "Taiwan", "Thailand", "Brazil", "Chile",
"Colombia", "Mexico", "Peru", "Israel", "South Africa", "United States",
"China", "Japan", "Britain", "Canada", "Euro area", "Austria",
"Belgium", "France", "Germany", "Greece", "Italy", "Netherlands",
"Spain", "Czech Republic", "Denmark", "Norway", "Poland", "Russia",
"Sweden", "Switzerland", "Turkey", "Australia", "Hong Kong",
"India", "Indonesia", "Malaysia", "Pakistan", "Philippines",
"Singapore", "South Korea", "Taiwan", "Thailand", "Brazil", "Chile",
"Colombia", "Mexico", "Peru", "Israel", "South Africa", "United States",
"China", "Japan", "Britain", "Canada", "Euro area", "Austria",
"Belgium", "France", "Germany", "Greece", "Italy", "Netherlands",
"Spain", "Czech Republic", "Denmark", "Norway", "Poland", "Russia",
"Sweden", "Switzerland", "Turkey", "Australia", "Hong Kong",
"India", "Indonesia", "Malaysia", "Pakistan", "Philippines",
"Singapore", "South Korea", "Taiwan", "Thailand", "Brazil", "Chile",
"Colombia", "Mexico", "Peru", "Israel", "South Africa", "United States",
"China", "Japan", "Britain", "Canada", "Euro area", "Austria",
"Belgium", "France", "Germany", "Greece", "Italy", "Netherlands",
"Spain", "Czech Republic", "Denmark", "Norway", "Poland", "Russia",
"Sweden", "Switzerland", "Turkey", "Australia", "Hong Kong",
"India", "Indonesia", "Malaysia", "Pakistan", "Philippines",
"Singapore", "South Korea", "Taiwan", "Thailand", "Brazil", "Chile",
"Colombia", "Mexico", "Peru", "Israel", "South Africa", "United States",
"China", "Japan", "Britain", "Canada", "Euro area", "Austria",
"Belgium", "France", "Germany", "Greece", "Italy", "Netherlands",
"Spain", "Czech Republic", "Denmark", "Norway", "Poland", "Russia",
"Sweden", "Switzerland", "Turkey", "Australia", "Hong Kong",
"India", "Indonesia", "Malaysia", "Pakistan", "Philippines",
"Singapore", "South Korea", "Taiwan", "Thailand", "Brazil", "Chile",
"Colombia", "Mexico", "Peru", "Israel", "South Africa"), interest.rates = c(2.3,
3, 0, 1.2, 1.9, 0.2, 0.5, 0.6, 0.5, 0.2, 3.7, 2.8, 0.2, 1.2,
1.9, 0.3, 1.7, 2.9, 8.5, 0.3, -0.3, 14.9, 2.1, 1.8, 7.7, 7.8,
3.9, 13.1, 6.4, 2.2, 2, 0.8, 2.2, 7.1, 4.1, 6.6, 8.2, 5.6, 2,
8.7, 1, 2.5, 0, 0.5, 1, -0.6, -0.4, -0.3, -0.2, -0.6, 1.2, 1,
-0.5, 0.3, 1.2, -0.6, 1.1, 1.7, 6.1, -0.3, -0.8, 11.3, 0.7, 0.9,
6.2, 6.5, 2.8, 11, 4.2, 1.4, 1.3, 0.5, 0.8, 3.8, 3.4, 5.5, 6.3,
3.9, 0.4, 8.9, 1.4, 3.1, 0, 0.8, 1.3, -0.3, -0.1, -0.1, -0.1,
-0.3, 1, 0.7, -0.4, 0.3, 1.7, -0.2, 1.4, 1.5, 6.9, 0.4, -0.3,
12.9, 1.7, 1.3, 6.2, 6.5, 3.1, 10.2, 4, 1.4, 2, 0.4, 1.6, 8.3,
2.9, 5.5, 5.7, 4.3, 1.1, 9, 1.9, 2.6, 0, 1.5, 1.8, 0, 0.4, 0.4,
0.6, 0, 2.4, 1.6, -0.2, 1.1, 3, 0.3, 1.4, 4.1, 12.5, 0.4, 0.1,
23.1, 2.1, 1.7, 6.8, 6.6, 3.7, 11, 5.3, 1.8, 2.6, 0.7, 2, 11.3,
5.7, 9.4, 8, 6.2,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, 5, 4.6, 12.6, 7.3, 5.6, 2.2, 40.8, 3.8, 2.3, 5.3, 3.9,
2.3, 9.9, 5.7, 3.1, 2.8, 1.6, 2.2, 4.8, 7.5, 9.7, 5.9, 6.9, 3.4,
5.1)), class = "data.frame", row.names = c(NA, -200L))
1条答案
按热度按时间8hhllhi21#
包
lmtest
使用命令grangertest
实现格兰杰测试。如果你有面板数据,你可能会对格兰杰检验的面板版本感兴趣。
plm
包实现了Dumistrecu/Hurlin(2012)的面板格兰杰检验。下面是两个例子。但是,对于面板格兰杰测试,你的数据太短了,因此我从帮助页面
?pgrangertest
中展示了另一个例子。