keil调试查看变量(keil怎么看变量的值)
计量经济学服务中心专辑汇总!计量百科 ·资源·干货:
Stata |Python |Ma tlab |Eviews |R
Geoda |A rcGis |GeodaSpace |SPSS
一文读懂 |数据资源 |回归方法 |网络爬虫
门 限回归 |工具变量 | 内生性 |空间计量
因 果推断 |合成控制法 |倾向匹配得分 |断点回归 |双重差 分
面板数据 | 动态面板数据
计量经济学服务中心专辑汇总!计量百科 ·资源·干货:
Stata |Python |Ma tlab |Eviews |R
Geoda |A rcGis |GeodaSpace |SPSS
一文读懂 |数据资源 |回归方法 |网络爬虫
门 限回归 |工具变量 | 内生性 |空间计量
因 果推断 |合成控制法 |倾向匹配得分 |断点回归 |双重差 分
面板数据 | 动态面板数据
👉2023空间计量研讨班:空间计量及Geoda、Stata、ArcGis、Matlab应用
👉2023空间计量研讨班:空间计量及Geoda、Stata、ArcGis、Matlab应用
面板VAR模型代码
* --------------------------------------------------
*
* $$$$$ $$$$$$$$ $ $$$$$$$$ $
* $$ $$ $ $$ $ $$ $ $$ $ $$
* $$ $ $$ $$$ $$ $$$
* $$$ $$ $ $$ $$ $ $$
* $$$ $$ $ $$ $$ $ $$
展开全文
* $$$ $$ $$$$$ $$ $$$$$
* $ $$ $$ $ $$ $$ $ $$
* $$ $$ $$ $ $$ $$ $ $$
* $$$$$ $$$$ $$$ $$$$ $$$$ $$$ $$$$
*
* --------------------------------------------------
*
*
*
* ____________________________________________________
* ————————————————————————————————————————————————————
* 高级计量经济学--面板计量经济学
* _____________________________________________________
* —————————————————————————————————————————————————————
*
* 计量经济学服务中心&数量经济学
*
*
*
*
*-------------------------------------------------------------------------------
* 参考资料:
* 《初级计量经济学及Stata应用:Stata从入门到进阶》
* 《高级计量经济学及Stata应用:Stata回归分析与应用》
* 《量化社会科学方法》
* 《社会科学因果推断》
* 《面板数据计量分析方法》
* 《时间序列计量分析方法》
* 《高级计量经济学及Eviews应用》
* 《R、Python、Mtalab初高级教程》
* 《空间计量入门:空间计量在Geoda、GeodaSpace中的应用》
* 《零基础|轻松搞定空间计量:空间计量及GeoDa、Stata应用》
* 《空间计量第二部:空间计量及Matlab应用课程》
* 《空间计量第三部:空间计量及Stata应用课程》
* 《空间计量第四部:《空间计量及ArcGis应用课程》
* 《空间计量第五部:空间计量经济学》
* 《空间计量第六部:《空间计量及Python应用》
* 《空间计量第七部:《空间计量及R应用》
* 《空间计量第八部:《高级空间计量经济学》
*-------------------------------------------------------------------------------
* ==============================
* 面板VAR模型
* ==============================
** # 1、简介
* PVAR这个程序最初是由Inessa Love编写的。
* 它允许用户估计面板向量自回归和产生方差分解和脉冲响应函数。
* Love 's 的程序被Love and Ziccino (2006)等论文采用。
*
*
* 关于各种var模型,阅读如下资源:
* 1、Structural vector autoregression models
* 网址为:https://blog.stata.com/2016/09/20/structural-vector-autoregression-models/
*
* 2、Vector autoregressions in Stata
* 网址为:https://blog.stata.com/2016/08/09/vector-autoregressions-in-stata/
*
*
* 而pvar2完整的包包括三个文件.ado文件:helm.ado(用于执行Helmert转换),
* pvar2.ado(实际估计命令)和sgmm2.ado(用于pvar2的评估)。
* 该包还包括helm和pvar2的帮助文件。将这些文件复制到适当的Stata文件夹中。开始前请仔细阅读pvar2帮助文件。
*
* 在在使用pvar2之前,必须使用tsset或xtset。
*
** # 2、pvar2语法格式
* pvar2 [depvarlist] [ if] [ in] [weight] [, options]
* 语法选项为:
* gmm:使用gmm,必选项
*
* lag( #):指定VAR中的滞后期,默认是1,#必须是正整数。
*
* impulse [max IRF] [IRF x-axis intervals]:生成脉冲响应函数
*
* list_imp:生成一个带有脉冲响应函数的表(在脉冲之后使用)
*
* gr_imp:生成图形化脉冲响应
*
* decomp [maxnum] [interval]:生成一个包含方差分解的表(必须在impulse或monte命令后列出)
** # 3、案例应用:pvar2操作应用
** # 3.1、导入数据,然后修改变量名称,设定声明
webuse grunfeld, clear
rename company id
xtset id year
** # 3.2、拟合面板VAR
pvar2 kstock invest mvalue
*结果为:
*-----------------------------------result.begin--------------------------------
. pvar2 kstock invest mvalue
System-GMM started:
==================================================
Panel Vector Auto-Regression: System-GMM Results
==================================================
Group variable: company Number of groups = 10
Number of obs = 180 Number of equations= 3
Number of instruments used: 9
AIC = 37.84913 BIC = 38.54094 HQIC = 38.12963
------------------------------------------------------------------------------
| Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
h_kstock |
h_kstock |
L1. | 1.776256 .8756359 2.03 0.043 .060041 3.492471
|
h_invest |
L1. | -1.979485 2.22621 -0.89 0.374 -6.342776 2.383807
|
h_mvalue |
L1. | -.0715747 .1327148 -0.54 0.590 -.3316909 .1885416
-------------+----------------------------------------------------------------
h_invest |
h_kstock |
L1. | .1041885 .2965675 0.35 0.725 -.4770732 .6854502
|
h_invest |
L1. | .7496098 .7421829 1.01 0.312 -.7050419 2.204262
|
h_mvalue |
L1. | -.0533324 .0397851 -1.34 0.180 -.1313098 .024645
-------------+----------------------------------------------------------------
h_mvalue |
h_kstock |
L1. | .1966403 1.972992 0.10 0.921 -3.670353 4.063634
|
h_invest |
L1. | .0416641 4.385355 0.01 0.992 -8.553475 8.636803
|
h_mvalue |
L1. | .6614178 .335602 1.97 0.049 .0036499 1.319186
------------------------------------------------------------------------------
Instruments used: l1.kstock l1.invest l1.mvalue
Note: all equations use the same setof Instruments listed above
======================================
Hansen Test forover-identification
======================================
just identified - Hansen statistic is not calculated
System-GMM finished:
*-----------------------------------result.over--------------------------------
** # 3.3、拟合面板VAR,滞后2期的
pvar2 kstock invest mvalue,lag(2)
*结果为:
*-----------------------------------result.begin--------------------------------
. pvar2 kstock invest mvalue,lag(2)
System-GMM started:
==================================================
Panel Vector Auto-Regression: System-GMM Results
==================================================
Group variable: company Number of groups = 10
Number of obs = 170 Number of equations= 3
Number of instruments used: 18
AIC = 34.33666 BIC = 35.22206 HQIC = 34.69594
------------------------------------------------------------------------------
| Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
h_kstock |
h_kstock |
L1. | 1.732148 .1347226 12.86 0.000 1.468096 1.996199
|
h_invest |
L1. | .8096433 .1751534 4.62 0.000 .4663489 1.152938
|
h_mvalue |
L1. | -.0232559 .0174886 -1.33 0.184 -.0575331 .0110212
|
h_kstock |
L2. | -.7765044 .1057205 -7.34 0.000 -.9837128 -.569296
|
h_invest |
L2. | -.7358144 .1228004 -5.99 0.000 -.9764987 -.49513
|
h_mvalue |
L2. | .0068921 .0158799 0.43 0.664 -.024232 .0380161
-------------+----------------------------------------------------------------
h_invest |
h_kstock |
L1. | -.2993238 .2392185 -1.25 0.211 -.7681833 .1695358
|
h_invest |
L1. | 1.496062 .2725296 5.49 0.000 .9619141 2.030211
|
h_mvalue |
L1. | -.0815563 .0369626 -2.21 0.027 -.1540017 -.009111
|
h_kstock |
L2. | .23288 .1774415 1.31 0.189 -.1148991 .580659
|
h_invest |
L2. | -.2513994 .2300935 -1.09 0.275 -.7023744 .1995756
|
h_mvalue |
L2. | -.0238238 .0195361 -1.22 0.223 -.0621138 .0144662
-------------+----------------------------------------------------------------
h_mvalue |
h_kstock |
L1. | -1.736184 1.016007 -1.71 0.087 -3.727521 .255152
|
h_invest |
L1. | -.066045 1.300652 -0.05 0.960 -2.615276 2.483186
|
h_mvalue |
L1. | .2887134 .3195089 0.90 0.366 -.3375126 .9149394
|
h_kstock |
L2. | 2.390303 .737651 3.24 0.001 .9445338 3.836073
|
h_invest |
L2. | -.5708208 1.322601 -0.43 0.666 -3.163072 2.02143
|
h_mvalue |
L2. | -.0116131 .164753 -0.07 0.944 -.334523 .3112968
------------------------------------------------------------------------------
Instruments used: l1.kstock l1.invest l1.mvalue l2.kstock l2.invest l2.mvalue
Note: all equations use the same setof Instruments listed above
*-----------------------------------result.over--------------------------------
** # 3.4 面板VAR滞后阶数选择
**** 估计一个PVAR(5)模型并选择最优滞后阶数
pvar2 kstock invest mvalue, lag(5) soc
*结果为:
*-----------------------------------result.begin--------------------------------
. pvar2 kstock invest mvalue, lag(5) soc
===========================================
Selection Order Criteria forPanel VAR
===========================================
+------------------------------------+
|lag | AIC BIC HQIC |
|----+-------------------------------|
| 1 | 37.8491 38.5409 38.1296 |
| 2 | 34.3367 35.2221 34.6959 |
| 3 | 33.7112 34.8067 34.156 |
| 4 | 33.0443* 34.369* 33.5825* |
| 5 | 33.9323 35.5082 34.5727 |
+------------------------------------+
*-----------------------------------result.over--------------------------------
* 结果显示应该选择滞后4阶的
** # 3.5 面板VAR冲击响应函数IRF
* 用IRFs图进行系统gmm估计(冲击6期),蒙特卡罗模拟200次(默认值)得到误差边界:
pvar2 kstock invest mvalue, lag(2) irf(6)
*结果为:
*-----------------------------------result.begin--------------------------------
. pvar2 kstock invest mvalue, lag(2) irf(6)
System-GMM started:
==================================================
Panel Vector Auto-Regression: System-GMM Results
==================================================
Group variable: company Number of groups = 10
Number of obs = 170 Number of equations= 3
Number of instruments used: 18
AIC = 34.33666 BIC = 35.22206 HQIC = 34.69594
------------------------------------------------------------------------------
| Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
h_kstock |
h_kstock |
L1. | 1.732148 .1347226 12.86 0.000 1.468096 1.996199
|
h_invest |
L1. | .8096433 .1751534 4.62 0.000 .4663489 1.152938
|
h_mvalue |
L1. | -.0232559 .0174886 -1.33 0.184 -.0575331 .0110212
|
h_kstock |
L2. | -.7765044 .1057205 -7.34 0.000 -.9837128 -.569296
|
h_invest |
L2. | -.7358144 .1228004 -5.99 0.000 -.9764987 -.49513
|
h_mvalue |
L2. | .0068921 .0158799 0.43 0.664 -.024232 .0380161
-------------+----------------------------------------------------------------
h_invest |
h_kstock |
L1. | -.2993238 .2392185 -1.25 0.211 -.7681833 .1695358
|
h_invest |
L1. | 1.496062 .2725296 5.49 0.000 .9619141 2.030211
|
h_mvalue |
L1. | -.0815563 .0369626 -2.21 0.027 -.1540017 -.009111
|
h_kstock |
L2. | .23288 .1774415 1.31 0.189 -.1148991 .580659
|
h_invest |
L2. | -.2513994 .2300935 -1.09 0.275 -.7023744 .1995756
|
h_mvalue |
L2. | -.0238238 .0195361 -1.22 0.223 -.0621138 .0144662
-------------+----------------------------------------------------------------
h_mvalue |
h_kstock |
L1. | -1.736184 1.016007 -1.71 0.087 -3.727521 .255152
|
h_invest |
L1. | -.066045 1.300652 -0.05 0.960 -2.615276 2.483186
|
h_mvalue |
L1. | .2887134 .3195089 0.90 0.366 -.3375126 .9149394
|
h_kstock |
L2. | 2.390303 .737651 3.24 0.001 .9445338 3.836073
|
h_invest |
L2. | -.5708208 1.322601 -0.43 0.666 -3.163072 2.02143
|
h_mvalue |
L2. | -.0116131 .164753 -0.07 0.944 -.334523 .3112968
------------------------------------------------------------------------------
Instruments used: l1.kstock l1.invest l1.mvalue l2.kstock l2.invest l2.mvalue
Note: all equations use the same setof Instruments listed above
======================================
Hansen Test forover-identification
======================================
just identified - Hansen statistic is not calculated
System-GMM finished: 11:51:38
=======================================
Monte-Carlo Simulation forIRF bounds
=======================================
Starting Monte-Carlo loop: 11:51:38
Total repetitions requested: 200
.....................................................................................................................
> ...................................................................................
Finished Monte-Carlo loop: 11:51:39
Graphing the IRFs ......
(file gr1_1.gph not found)
file gr1_1.gph saved
(file gr1_2.gph not found)
file gr1_2.gph saved
(file gr1_3.gph not found)
file gr1_3.gph saved
(file gr2_1.gph not found)
file gr2_1.gph saved
(file gr2_2.gph not found)
file gr2_2.gph saved
(file gr2_3.gph not found)
file gr2_3.gph saved
(file gr3_1.gph not found)
file gr3_1.gph saved
(file gr3_2.gph not found)
file gr3_2.gph saved
(file gr3_3.gph not found)
file gr3_3.gph saved
.
end of do-file
*-----------------------------------result.over--------------------------------
* 图的结果为:
graph export"IRF.wmf"
shellout "IRF.wmf"
图的结果为:
** # 3.6 面板VAR方差分解
pvar2 kstock invest mvalue, irf(5) decomp(10) nograph
*结果为:
*-----------------------------------result.begin--------------------------------
/*
. pvar2 kstock invest mvalue, irf(5) decomp(10) nograph
System-GMM started: 11:55:39
==================================================
Panel Vector Auto-Regression: System-GMM Results
==================================================
Group variable: company Number of groups = 10
Number of obs = 180 Number of equations= 3
Number of instruments used: 9
AIC = 37.84913 BIC = 38.54094 HQIC = 38.12963
------------------------------------------------------------------------------
| Coefficient Std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
h_kstock |
h_kstock |
L1. | 1.776256 .8756359 2.03 0.043 .060041 3.492471
|
h_invest |
L1. | -1.979485 2.22621 -0.89 0.374 -6.342776 2.383807
|
h_mvalue |
L1. | -.0715747 .1327148 -0.54 0.590 -.3316909 .1885416
-------------+----------------------------------------------------------------
h_invest |
h_kstock |
L1. | .1041885 .2965675 0.35 0.725 -.4770732 .6854502
|
h_invest |
L1. | .7496098 .7421829 1.01 0.312 -.7050419 2.204262
|
h_mvalue |
L1. | -.0533324 .0397851 -1.34 0.180 -.1313098 .024645
-------------+----------------------------------------------------------------
h_mvalue |
h_kstock |
L1. | .1966403 1.972992 0.10 0.921 -3.670353 4.063634
|
h_invest |
L1. | .0416641 4.385355 0.01 0.992 -8.553475 8.636803
|
h_mvalue |
L1. | .6614178 .335602 1.97 0.049 .0036499 1.319186
------------------------------------------------------------------------------
Instruments used: l1.kstock l1.invest l1.mvalue
Note: all equations use the same setof Instruments listed above
======================================
Hansen Test forover-identification
======================================
just identified - Hansen statistic is not calculated
System-GMM finished: 11:55:39
*/
=======================================
Monte-Carlo Simulation forIRF bounds
=======================================
Starting Monte-Carlo loop: 11:55:39
Total repetitions requested: 200
.....................................................................................................................
> ...................................................................................
Finished Monte-Carlo loop: 11:55:40
===============================================
Forecast-error Variance Decompositions (FEVD)
===============================================
Variance decomposition: s = 1,2,3,4,5,6,7,8,9,10,
Variance-decompositions: percent of variation inthe row variable explained by column variable
D[30,4]
s kstock invest mvalue
kstock 1.000 1.000 0.000 0.000
invest 1.000 0.041 0.959 0.000
mvalue 1.000 0.077 0.279 0.644
kstock 2.000 0.903 0.094 0.003
invest 2.000 0.240 0.709 0.051
mvalue 2.000 0.059 0.286 0.654
kstock 3.000 0.807 0.191 0.002
invest 3.000 0.515 0.390 0.096
mvalue 3.000 0.062 0.277 0.661
kstock 4.000 0.739 0.260 0.001
invest 4.000 0.688 0.229 0.083
mvalue 4.000 0.123 0.252 0.625
kstock 5.000 0.693 0.306 0.001
invest 5.000 0.735 0.217 0.048
mvalue 5.000 0.276 0.231 0.493
kstock 6.000 0.662 0.335 0.003
invest 6.000 0.721 0.256 0.022
mvalue 6.000 0.457 0.244 0.299
kstock 7.000 0.642 0.353 0.005
invest 7.000 0.693 0.298 0.009
mvalue 7.000 0.571 0.281 0.148
kstock 8.000 0.628 0.364 0.007
invest 8.000 0.666 0.329 0.005
mvalue 8.000 0.615 0.316 0.069
kstock 9.000 0.620 0.371 0.009
invest 9.000 0.646 0.349 0.005
mvalue 9.000 0.625 0.341 0.034
kstock 10.000 0.615 0.375 0.011
invest 10.000 0.632 0.362 0.007
mvalue 10.000 0.623 0.357 0.020
.
end of do-file
.
*-----------------------------------result.over--------------------------------
** # 3.7 面板VAR格兰杰检验
pvar2 kstock invest mvalue, lag(3) granger
*结果为:
*-----------------------------------result.begin--------------------------------
=============================
Granger Causality tests
=============================
Granger causality Wald tests forPanel VAR
+------------------------------------------------------------------+
| Equation Excluded | chi2 df Prob > chi2 |
|--------------------------------------+---------------------------|
| h_kstock h_invest | 52.221 3 0.000 |
| h_kstock h_mvalue | 9.0752 3 0.028 |
| h_kstock ALL | 118.88 6 0.000 |
|--------------------------------------+---------------------------|
| h_invest h_kstock | 15.613 3 0.001 |
| h_invest h_mvalue | 12.366 3 0.006 |
| h_invest ALL | 18.998 6 0.004 |
|--------------------------------------+---------------------------|
| h_mvalue h_kstock | 15.08 3 0.002 |
| h_mvalue h_invest | 2.7232 3 0.436 |
| h_mvalue ALL | 25.034 6 0.000 |
+------------------------------------------------------------------+
.
end of do-file
.
*-----------------------------------result.over--------------------------------
1
** # 3.8 面板VAR模型pvar2命令保存结果
* PVAR2.ado保存了哪些结果呢?
*
* Pavr2在内存中保存了许多matrix, .dta文件和宏。
* 我们可以使用这些返回值来重绘IRFs图,恢复结果等等。
*
* pavr2之后,
*
* 输入 returnlist将列出存储在内存中的所有返回元素。
*
* 输入matrix dir将列出存储在内存中的所有矩阵。
*
* 输入macro dir将列出所有宏。
*
* 输入dir *.dta将列出pavr2在磁盘上保存的所有数据集。
*
* 输入dir gr*.gph将列出pavr2保存的所有图。
returnlist
dir *.dta
dir gr*.gph
1
PVAR这个程序最初是由Inessa Love编写的。它允许用户估计面板向量自回归和产生方差分解和脉冲响应函数。Love’s 的程序被Love and Ziccino (2006)等论文采用。
关于各种var模型,阅读如下资源:
1、Structural vector autoregression models,网址为:https://blog.stata.com/2016/09/20/structural-vector-autoregression-models/
2、Vector autoregressions in Stata,网址为:https://blog.stata.com/2016/08/09/vector-autoregressions-in-stata/
而pvar2完整的包包括三个文件.ado文件:helm.ado(用于执行Helmert转换),pvar2.ado(实际估计命令)和sgmm2.ado(用于pvar2的评估)。该包还包括helm和pvar2的帮助文件。将这些文件复制到适当的Stata文件夹中。开始前请仔细阅读pvar2帮助文件。
在在使用pvar2之前,必须使用tsset或xtset。
1
pvar2语法格式
语法选项为:
gmm:使用gmm,必选项
lag(#):指定VAR中的滞后期,默认是1,#必须是正整数。
impulse [max IRF] [IRF x-axis intervals]:生成脉冲响应函数
list_imp:生成一个带有脉冲响应函数的表(在脉冲之后使用)
gr_imp:生成图形化脉冲响应
decomp [maxnum] [interval]:生成一个包含方差分解的表(必须在impulse或monte命令后列出)
2
pvar2操作应用
1、导入数据,然后修改变量名称,设定声明
结果为:
2、Helmert transform the data to remove fixed effects
结果为:
3、拟合面板VAR与三个滞后;使用蒙特卡罗标准误差生成最多12个周期的脉冲响应函数(并在IRF图上标记偶数周期)
结果为: