stata语句中VAR模型的一系列检验和实现

需要学习这个语句,便自学了下。VAR模型在eview上可以实现,也可以在stata实现,下面是stata版本的,看父母投资(每月)对子女教育的成绩(一般来说,这个模型需要宏观上的年度数据、月度数据才能实现,但是这里只是举个例子便于理解。)

****时间上最好设置为2023m2、2023m1这种,不然无法完成时间序列的设置
encode year ,gen (t)
tsset t

*-1 检验滞后阶数
varsoc  edu
varsoc  invest

*-2 检验协整关系的个数
vecrank edu infro, lag(4)

*-3 建立VECM(向量误差修正模型)
vec edu infro, lag(4)

*-4 沃尔德检验
var edu infro, dfk small
varwle 

*-5 平稳性检验
varstable,graph

***6 格兰杰因果检验
vargranger

***7 脉冲响应
***这里会出现问题,将存储位置修改到其他位置就可以创新一个数据库了。
cd e:/

irf creat gi,set(mcr)
irf graph oirf,yline(0)


***8.方差分解
irf graph fevd,r(edu) noci
irf graph fevd,r(infro) noci


***9.预测未来值
help fcast
fcast compute f_,step(9)fcast graph infro consume
fcast compute m2_, step(8)


*预测
predict ce, ce
list t consume infro ce
twoway (line consume infro t,yaxis(1)) ///
(line ce t, yaxis(2)) ///
, yline(0,axis(2) lp(dash) lc(black*0.4))


***8.方差分解
irf graph fevd,r(edu) noci
irf graph fevd,r(infro) noci


***9.预测未来值
fcast compute f_,step(9)fcast graph infro consume
fcast compute m2_, step(8)


*预测
predict ce, ce
list t consume infro ce
twoway (line consume infro t,yaxis(1)) ///
(line ce t, yaxis(2)) ///
, yline(0,axis(2) lp(dash) lc(black*0.4))

***9.预测未来值
* 正交冲击反应
irf graph oirf, impulse(infro) response(edu)
irf graph oirf, impulse(infro) response(edu)
* 累积正交冲击反应
irf graph coirf, impulse(infro) response(edu)
irf graph coirf, impulse(infro) response(edu)



可以用个stata自带的语句先跑跑

cls
clear

use http://www.stata-press.com/data/r11/txhprice,clear
des
*-四个州房价的基本时序特征
tsset t
line austin dallas houston sa t
*--Part I-- Dallas v.s. Houston
*-------------------------------

* 二变量协整分析
line dallas houston t
* 若两地的房价差异过大,居民和相关资源会在两地迁移,从而使两地价格趋同,因此,可以认为达拉斯和休斯敦的房价存在协整关系
*-0 检验序列的平稳性
dfuller dallas
dfuller houston

. dfuller houston


*/

* 为什么是平稳呢?
*直觉解释:在完全竞争市场中,当前的房价包含了所有信息,因此,我们无法预测明日房价的走势
 
*-1 检验滞后阶数
varsoc dallas houston

*-2 检验协整关系的个数
vecrank dallas houston, lag(2)

*-3 建立VECM(向量误差修正模型)
vec dallas houston, lag(2)

*4.预测
predict ce, ce
list t dallas houston ce
twoway (line dallas houston t,yaxis(1)) ///
(line ce t, yaxis(2)) ///
, yline(0,axis(2) lp(dash) lc(black*0.4))
 
*-5 冲击反应分析(脉冲响应分析)
irf create vec2, set(vec02) step(24)


* 正交冲击反应
irf graph oirf, impulse(dallas) response(houston)
irf graph oirf, impulse(houston) response(dallas)
* 累积正交冲击反应
irf graph coirf, impulse(dallas) response(houston)
irf graph coirf, impulse(houston) response(dallas)


误差修正模型的结果为:
D_dallas=-0.3039L1.ce1-0.1647LD.dallas-0.0998LD.houston+0.0056
D_houston=0.5027L1.ce1-0.0620LD.dallas-0.33328LD.houston+0.0034
ce1=dallas-0.8676houston-1.689
分析:
在D_dallas 方程中,L._ce1 = -0.3039 表明:若Dallas 的房价过高,它会向着Houston 的房价下调;在[D_houston]方程中,L._ce1 =0.5027 表明:若Dallas 的房价过高,Houston 的房价会追随之。而要是在[D_houston]方程中,L._ce1 = -0.5027 则表明:若Houston 的房价过高,它会向着Dalla 的房价下调
 
长期均衡关系:P_dallas =-1.69 - 0.868*P_houston

这个例子是看公众号学习的,忘记出处了,下次看到了再附上链接。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值