07.经济学模型-DSGE模型讨论之七 - 最简单的DSGE模型的Dynare模拟和MLE-Bayesian估计 下载本文

生命赐给我们,我们必须奉献生命,才能获得生命。

这个notes纯粹是扫盲用的。

我用了一个最简单的线性DSGE,只有两个方程。先是我用手算的方法找到saddle-path 的policy function,然后手算出impulse response function。这些我都用Dynare做了计算,程序和结果都写在note里面。

上面是我note的截图,这个DSGE模型实际上就是一个linear rational expecation model (LREM),但DSGE的线性化后的本质也就是个LRE。虽然这个note提供的模型非常简单,但是思路在于如何用Dynare来深入学习这个动态系统。有几个事情需要大家自己来做:

1. beta和rho的大小,大家从换很多次calibration,看能对IRF带来什么影响? 2. beta和rho都大于1的时候,你应该怎么修改模型,为了维持模型的稳定性? 3. 看修改shock的stardard deviation能对模型带了什么影响? 4. 如果你再加一个方程进去呢?什么样子的方程?

以上内容我都试验过了。这个东西没法帮大家试验,所以大家必须自己试着做。这样你可以学到很多关于动态系统的感性认识。

之后,我用最大似然估计对参数估计,然后我故意制造under-identification的问题,让大家看一下结果是什么样子。最后就是Bayesian estimation,我只估计了1个参数,用了2条平行马尔科夫链,做了超超短程模拟(只有500次,正常情况都是100000),为了省时间(我电脑只用50秒左右),所以我并没有让电脑跑很长的马尔科夫链和多个平行链条。所以结果非常差,但是这不是的目的。目的还是在于让从来没见过整个估计过程的同学看到一个全貌。所以我没有提及理论内容,或者是一带而过。

对于Bayesian estimation,有个地方要注意的就是shock的个数必须大于等observable的个数,这是启动Kalman filter模拟likelihood function的充分条件。Kalman filter是一个极其复杂的算法,计量经济学上面用来模拟likelihood function。以后我会有一个贴子专门来展开Kalman filter的内部结构。 notes下载 希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。

生命赐给我们,我们必须奉献生命,才能获得生命。

Simplest DSGE.pdf (257.99 KB)

关于模型具体推导和模拟的例子,请看第六个帖子 DSGE模型讨论之六——新古典增长模型(入门级DSGE)的推导和Dynare模擬 关于模型求解方法,比如Blanchard-Khan,Uhlig 方法,看第三个帖子 DSGE模型讨论之三——线形理性预期模型(Linear rational expectation model) 如果你连DSGE是什么都不知道,看 针对DSGE模型学习的建议性计划(原创)关于DSGE求解和模型参数估计的一些认识(原创)

>> dynare simplemodel

Configuring Dynare ... [mex] Generalized QZ.

[mex] Sylvester equation solution. [mex] Kronecker products.

[mex] Sparse kronecker products.

[mex] Local state space iteration (second order). [mex] Bytecode evaluation.

[mex] k-order perturbation solver. [mex] k-order solution simulation.

[mex] Quasi Monte-Carlo sequence (Sobol). [mex] Markov Switching SBVAR.

Starting Dynare (version 4.3.3).

Starting preprocessing of the model file ... Found 2 equation(s).

Evaluating expressions...done

Computing static model derivatives: - order 1

Computing dynamic model derivatives: - order 1

Processing outputs ...done Preprocessing completed.

Starting MATLAB/Octave computing.

STEADY-STATE RESULTS:

希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。

生命赐给我们,我们必须奉献生命,才能获得生命。

x 0 y 0

EIGENVALUES:

Modulus Real Imaginary

0.9 0.9 0 1.111 1.111 0

There are 1 eigenvalue(s) larger than 1 in modulus for 1 forward-looking variable(s)

The rank condition is verified.

Residuals of the static equations:

Equation number 1 : 0 Equation number 2 : 0

MODEL SUMMARY

Number of variables: 2 Number of stochastic shocks: 2 Number of state variables: 1 Number of jumpers: 1 Number of static variables: 0

MATRIX OF COVARIANCE OF EXOGENOUS SHOCKS

Variables e u e 0.010000 0.000000 u 0.000000 0.010000

POLICY AND TRANSITION FUNCTIONS

y x

希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。

生命赐给我们,我们必须奉献生命,才能获得生命。

x(-1) 4.736842 0.900000 e 5.263158 1.000000 u 1.000000 0

MOMENTS OF SIMULATED VARIABLES

VARIABLE MEAN STD. DEV. VARIANCE SKEWNESS KURTOSIS y -0.347966 1.279206 1.636369 -0.076629 0.045543 x -0.065640 0.242347 0.058732 -0.091698 0.036069

CORRELATION OF SIMULATED VARIABLES

VARIABLE y x y 1.0000 0.9970 x 0.9970 1.0000

AUTOCORRELATION OF SIMULATED VARIABLES

VARIABLE 1 2 3 4 5 y 0.9127 0.8244 0.7364 0.6581 0.5958 x 0.9163 0.8295 0.7426 0.6692 0.6119 Loading 900 observations from Simul_data.mat

Initial value of the log posterior (or likelihood): -14016.6527

Warning: Options LargeScale = 'off' and Algorithm = 'trust-region-reflective' conflict. Ignoring Algorithm and running active-set algorithm. To run trust-region-reflective, set LargeScale = 'on'. To run active-set without this warning, use Algorithm = 'active-set'. > In fmincon at 454

In dynare_estimation_1 at 228 In dynare_estimation at 70 In simplemodel at 129 In dynare at 120

Warning: Your current settings will run a different algorithm (interior-point) in a future release. > In fmincon at 458

In dynare_estimation_1 at 228 In dynare_estimation at 70 In simplemodel at 129 In dynare at 120

Max Line search Directional First-order Iter F-count f(x) constraint steplength derivative optimality Procedure 希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。

生命赐给我们,我们必须奉献生命,才能获得生命。

0 3 14016.7 -0.19 1 7 -1447.33 -0.095 0.5 -1.1e+05 5.09e+04 2 13 -1577.29 -0.08313 0.125 -2.88e+04 8.91e+03 3 17 -1579.48 -0.04156 0.5 -244 4.29e+03 4 22 -1587.63 -0.07759 0.25 -341 1.9e+03 5 29 -1588.01 -0.07479 0.0625 -293 56.2 6 32 -1588.68 -0.08274 1 -76.1 390 7 35 -1589.03 -0.08502 1 -48.8 980 8 38 -1589.17 -0.08623 1 -140 110 9 41 -1589.19 -0.08436 1 -11.3 17.6 10 44 -1589.19 -0.08348 1 -3.35 8.1 11 47 -1589.19 -0.08345 1 -0.72 0.0422

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current search direction is less than twice the selected value of the step size tolerance and constraints are satisfied to within the default value of the constraint tolerance.

No active inequalities.

POSTERIOR KERNEL OPTIMIZATION PROBLEM!

(minus) the hessian matrix at the \=> posterior variance of the estimated parameters are not positive. You should try to change the initial values of the parameters using the estimated_params_init block, or use another optimization routine. Warning: The results below are most likely wrong! > In dynare_estimation_1 at 480 In dynare_estimation at 70 In simplemodel at 129 In dynare at 120

MODE CHECK

Fval obtained by the minimization routine: -1589.188769

RESULTS FROM MAXIMUM LIKELIHOOD parameters

Estimate s.d. t-stat

beta 0.8935 0.0000 0.0000

希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。

生命赐给我们,我们必须奉献生命,才能获得生命。 rho 0.9065 0.0000 0.0000 Total computing time : 0h00m07s

希望是本无所谓有,无所谓无的。这正如地上的路;其实地上本没有路,走的人多了,也便成了路。