全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
8925 11
2018-03-18
在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-; 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)


附件列表
Capture.PNG

原图尺寸 136.27 KB

Capture.PNG

二维码

扫码加我 拉你入群

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

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

全部回复
2018-3-18 11:55:46
很好的资料,学习了,感谢楼主分享!
二维码

扫码加我 拉你入群

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

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

2018-12-7 15:36:13
文章里的代码好像有点错误吧,我稍微修改了之后才能运行程序
二维码

扫码加我 拉你入群

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

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

2019-1-5 10:41:54
感谢楼主分享!
二维码

扫码加我 拉你入群

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

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

2019-1-5 11:14:04
tiesuoqiao 发表于 2018-3-18 00:08
在R中进行面板向量自回归(panel var)的程序。实际上还包括了对应于Stata中动态面板xtabond2的R程序


谢谢你的分享
二维码

扫码加我 拉你入群

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

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

2019-1-9 21:42:55
非常有用,正是需要的时候,真心感谢楼主分享,解决很多问题。
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群