楼主: tiesuoqiao
9076 11

[程序分享] 面板向量自回归和动态面板 R package panelvar [推广有奖]

  • 1关注
  • 8粉丝

已卖:78份资源

副教授

85%

还不是VIP/贵宾

-

威望
0
论坛币
487 个
通用积分
309.8531
学术水平
15 点
热心指数
12 点
信用等级
9 点
经验
54652 点
帖子
324
精华
0
在线时间
1589 小时
注册时间
2009-5-29
最后登录
2025-11-24

楼主
tiesuoqiao 发表于 2018-3-18 00:08:52 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
在R中进行面板向量自回归(panel var)的程序。实际上还包括了对应于Stata中动态面板xtabond2的R程序



SSRN-id2896087.pdf (207.73 KB)

panelvar_0.4.4.zip (4.79 MB, 需要: 10 个论坛币)

In this paper we extend two general methods of moment estimators to panel vector autoregression models (PVAR) with p lags of endogenous variables, predetermined and strictly exogenous variables. First, the first difference GMM estimator (Holtz-Eakin et al., 1988; Arellano and Bond, 1991) is extended to this general PVAR model. Second, we do the same for the system GMM estimator (Blundell and Bond, 1998). We implement these estimators in the R package panelvar. In addition to the GMM-estimators we contribute to the literature by providing specification tests (Hansen overidentification test, lag selection criterion and stability test of the PVAR polynomial) and classical structural analysis for PVAR models such as orthogonal and generalized impulse response functions, bootstrapped confidence intervals for impulse response analysis and forecast error variance decompositions. Finally, we implement the first difference and the forward orthogonal transformation to remove the fixed effects.

在Rstudio中安装package步骤:“Tools” ->  “Install packages” -> "Install from Package Archive File" 然后选择zip


Examples with Cigar Data

We apply our package to the Cigar data set which was used by Baltagi and Levin (1992), Baltagi, Griffin, and Xiong (2000) and Croissant and Millo (2008). The data set covers variables that are relevant for cigarette demand in 46 American states over the period 1963 to 1992. These variables include price, sales, population, population over 16 years, consumer price inflation and minimum price. Especially, the availability of price and quantity are a classical example for vector autoregression models.

library(panelvar)data(Cigar)ex1_cigar_data <- pvargmm(dependent_vars = c("log_sales", "log_price"),                          lags = 1,                          predet_vars = c("log_ndi"),                          exog_vars = c("cpi", "log_pop16"),                          transformation = "fod",                          data = Cigar,                          panel_identifier= c("state", "year"),                          steps = c("twostep"),                          system_instruments = TRUE,                          max_instr_dependent_vars = 10,                          max_instr_predet_vars = 10,                          min_instr_dependent_vars = 2L,                          min_instr_predet_vars = 1L,                          collapse = TRUE)summary(ex1_cigar_data)

Dynamic Panel VAR estimation, twostep GMM

Transformation: Forward orthogonal deviations
Group variable: state
Time variable: year
Number of observations = 1380
Number of groups = 46
Obs per group: min = 30
Obs per group: avg = 30
Obs per group: max = 30

fod_log_sales

fod_log_price

fod_lag1_log_sales0.8517***-0.0350**
(0.0231)(0.0136)
fod_lag1_log_price-0.0981***0.8512***
(0.0185)(0.0147)
fod_log_ndi0.1172***0.0561***
(0.0203)(0.0137)
fod_cpi-0.0011***0.0017***
(0.0003)(0.0002)
fod_log_pop16-0.00500.0000
(0.0041)(0.0020)
const0.1930***0.2080***

(0.0110)

(0.0058)

[size=0.8em]p < 0.001, p < 0.01, p < 0.05

Hansen test of overid. restrictions: chi2(56) = 39.69 Prob > chi2 = 0.951
(Robust, but weakened by many instruments.)



Next, we test the stability of the autoregressive process:

stab_ex1_cigar_data <- stability(ex1_cigar_data)print(stab_ex1_cigar_data)
## Eigenvalue stability condition:## ##   Eigenvalue   Modulus## 1  0.9100521 0.9100521## 2  0.7928343 0.7928343## ## All the eigenvalues lie inside the unit circle.## PVAR satisfies stability condition.plot(stab_ex1_cigar_data)


In vector autoregression models researchers are often interested in impuls response analysis. Recently, researcher prefer the generalized impuls response analysis (GIRF) introduced by Pesaran and Shin (1998) to orthogonal impuls response analysis (OIRF) as it is independent of the ordering of the endogenous variables. However, GIRF and OIRF are closely related. Lin (2006) states that when <span class="MathJax" id="MathJax-Element-7-Frame" tabindex="0" data-mathml="Σϵ" role="presentation" style="display: inline; line-height: normal; word-spacing: normal; word-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; position: relative;">ΣϵΣϵ is diagonal OIRF and GIRF are the same. The GIRF of the effect of an unit shock to the r-th equation is the same as that of an orthogonal impulse response but different for other shocks. Hence, the GIRF can easily computed by using OIRF with each variable as the leading one.

ex1_cigar_data_girf <-  girf(ex1_cigar_data, n.ahead = 12, ma_approx_steps= 12)ex1_cigar_data_oirf <-  oirf(ex1_cigar_data, n.ahead = 12)

plot(ex1_cigar_data_girf, ex1_cigar_data_bs)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:package 向量自回归 动态面板 Pack PAC

Capture.PNG (136.27 KB)

Capture.PNG

沙发
pkl(未真实交易用户) 在职认证  发表于 2018-3-18 11:55:46
很好的资料,学习了,感谢楼主分享!

藤椅
Maple24246(真实交易用户) 学生认证  发表于 2018-12-7 15:36:13
文章里的代码好像有点错误吧,我稍微修改了之后才能运行程序

板凳
楚天江南客(未真实交易用户) 学生认证  发表于 2019-1-5 10:41:54
感谢楼主分享!

报纸
lonestone(未真实交易用户) 在职认证  发表于 2019-1-5 11:14:04 来自手机
tiesuoqiao 发表于 2018-3-18 00:08
在R中进行面板向量自回归(panel var)的程序。实际上还包括了对应于Stata中动态面板xtabond2的R程序


谢谢你的分享

地板
kaji雪姬(未真实交易用户) 发表于 2019-1-9 21:42:55
非常有用,正是需要的时候,真心感谢楼主分享,解决很多问题。

7
屋檐滴语(未真实交易用户) 发表于 2019-6-10 21:54:55
https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2896087

8
yuyuhoney(未真实交易用户) 发表于 2019-11-9 23:16:27
我在用自己数据(9个变量,1936个观测值)做pvargmm总是显示内存不足,请问这个问题怎么解决

9
yuyuhoney(未真实交易用户) 发表于 2021-2-4 00:31:53
Maple24246 发表于 2018-12-7 15:36
文章里的代码好像有点错误吧,我稍微修改了之后才能运行程序
请问您是修改了哪里,我也是不能运行程序,不知道问题在哪

10
浅谈辄止(真实交易用户) 发表于 2021-7-2 10:38:58
yuyuhoney 发表于 2019-11-9 23:16
我在用自己数据(9个变量,1936个观测值)做pvargmm总是显示内存不足,请问这个问题怎么解决
同问,请问你解决了吗

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-24 08:35