File: NKM.mod

package info (click to toggle)
dynare 7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 79,248 kB
  • sloc: cpp: 82,011; ansic: 28,583; objc: 12,573; yacc: 5,105; pascal: 2,374; lex: 1,502; python: 1,118; sh: 1,116; makefile: 605; lisp: 162; xml: 18
file content (143 lines) | stat: -rw-r--r-- 5,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
@#include "NKM_common.inc"

options_.TeX=1;

    // -----------------Occbin ----------------------------------------------//
    options_.occbin.smoother.debug=1;
    occbin_setup(likelihood_piecewise_kalman_filter);

    // use PKF
    estimation(
            datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
            mode_compute=0, nobs=120, first_obs=1,
            mh_replic=0, plot_priors=0, smoother,
            consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);

    // plot regimes
    occbin.plot_regimes(oo_.occbin.smoother.regime_history,M_,options_)

    // forecast starting from period 42, zero shocks (default)
    smoother2histval(period=42);
    [forecast, error_flag] = occbin.forecast(options_,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,8);
    // forecast with stochastic shocks
    options_.occbin.forecast.qmc=true;
    options_.occbin.forecast.replic=127;
    [forecast1, error_flag] = occbin.forecast(options_,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,8);

    figure('Name','OccBin: Forecasts')
    subplot(2,1,1)
    plot(1:8,forecast.piecewise.Mean.inom,'b-',1:8,forecast1.piecewise.Mean.inom,'r--')
    subplot(2,1,2)
    plot(1:8,forecast.piecewise.Mean.y,'b-',1:8,forecast1.piecewise.Mean.y,'r--')

    // GIRF given states in 42 and shocks in 43
    t0=42;
    options_.occbin.irf.exo_names=M_.exo_names;
    options_.occbin.irf.t0=t0;
    oo_.occbin.irfs = occbin.irf(M_,oo_,options_);

    var_list_ = {'c','n','y','pigap','inom','inomnot'};

    // if you want to scale ...
    // options_occbin_.plot_irf.endo_scaling_factor = vars_irf(:,3);
    options_.occbin.plot_irf.simulname = ['t0_' int2str(t0)];
    options_.irf=40;
    occbin.plot_irfs(M_,oo_.occbin.irfs,options_,var_list_);
    var_list_={};
    options_.occbin.plot_irf.simulname = ['t0_' int2str(t0) '_full'];
    occbin.plot_irfs(M_,oo_.occbin.irfs,options_,var_list_);
    oo0=oo_;
    // use smoother_redux
    estimation(
            datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
            mode_compute=0, nobs=120, first_obs=1,
            mh_replic=0, plot_priors=0, smoother, smoother_redux,
            consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);

    // check consistency of smoother_redux
    for k=1:M_.endo_nbr,
        mer(k)=max(abs(oo_.SmoothedVariables.(M_.endo_names{k})-oo0.SmoothedVariables.(M_.endo_names{k})));
    end
    if max(mer)>1.e-10
        error('smoother redux does not recover full smoother results!')
    else
        disp('smoother redux successfully recovers full smoother results!')
    end

    for k=1:M_.endo_nbr,
    mer(k)=max(abs(oo_.UpdatedVariables.(M_.endo_names{k})-oo0.UpdatedVariables.(M_.endo_names{k})));
    end
    if max(mer)>1.e-10
    error('smoother redux does not recover full updated variables results!')
    else
    disp('smoother redux successfully recovers full updated variables results!')
    end


    for k=1:M_.endo_nbr,
    mer(k)=max(abs(oo_.FilteredVariables.(M_.endo_names{k})-oo0.FilteredVariables.(M_.endo_names{k})));
    end
    if max(mer)>1.e-10
    error('smoother redux does not recover full filtered variables results!')
    else
    disp('smoother redux successfully recovers full filtered variables results!')
    end

    for k=1:M_.endo_nbr,
        mer(k)=max(max(max(abs(oo_.FilteredVariablesKStepAhead(:,k,:)-oo0.FilteredVariablesKStepAhead(:,k,:)))));
    end
    if max(mer)>1.e-10
    error('smoother redux does not recover full k-step ahead variables results!')
    else
    disp('smoother redux successfully recovers full k-step ahead variables results!')
    end

    //run PKF with MCMC
    options_.smoother_redux=false;
    estimation(
        datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
        mode_compute=0, nobs=120, first_obs=1,
        mh_replic=50, plot_priors=0, smoother,
        consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);

    // use inversion filter (note that IF provides smoother together with likelihood)
    occbin_setup(likelihood_inversion_filter,smoother_inversion_filter);

    estimation(
            datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
            mode_compute=0, nobs=120, first_obs=1,
            mh_replic=50, plot_priors=0, smoother,
            consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);

    // show initial condition effect of IF
    figure('Name','OccBin: Smoothed shocks')
    subplot(221)
    plot([oo0.SmoothedShocks.epsg oo_.SmoothedShocks.epsg]), title('epsg')
    subplot(222)
    plot([oo0.SmoothedShocks.epsi oo_.SmoothedShocks.epsi]), title('epsi')
    subplot(223)
    plot([oo0.SmoothedShocks.epss oo_.SmoothedShocks.epss]), title('epss')
    legend('PKF','IF')
    figure('Name','OccBin: Smoothed Variables')
    subplot(221)
    plot([oo0.SmoothedVariables.inom oo_.SmoothedVariables.inom]), title('inom')
    subplot(222)
    plot([oo0.SmoothedVariables.yg oo_.SmoothedVariables.yg]), title('yg')
    subplot(223)
    plot([oo0.SmoothedVariables.pi oo_.SmoothedVariables.pi]), title('pi')
    legend('PKF','IF')
    occbin_write_regimes(smoother);

    estimation(
            datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
            mode_compute=0, nobs=120, first_obs=1,
            mh_replic=50, plot_priors=0, smoother,
            consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);

write_latex_dynamic_model;
collect_latex_files;
[status, cmdout]=system(['pdflatex -halt-on-error -interaction=nonstopmode ' M_.fname '_TeX_binder.tex']);
if status
    cmdout
    error('TeX-File did not compile.')
end