-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPrincipal.m
105 lines (74 loc) · 3.31 KB
/
Principal.m
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Main prg to run the FAIR asymmetric estimation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
tic
mkdir results
addpath(['lib']);
addpath(['results']);
%Initialization/Parametrization of routine
setup_NL;
%To find starting values (or, in our case, priors), match IRFs with those of VAR:
VAR_resp_match_NL;
setup.length_param_vector=length(setup.initial_parameter);
close all
pause(.1)
%% Set parameter restrictions
% Impose lower-bnd / upper-bnd on parameters
% logit - parameter has to be between 0 and 1
% log - parameter has to be non-negative
% logit_general - upper and lower bounds are set by hand
% Impose -5<b<25 and 4<c<5000 (for illustration)
setup.index_logit_general=[22:30 46:48 31:39 49:51];
setup.length_logit_general=length(setup.index_logit_general);
setup.logit_general_lb=[-5*ones(1,12) 4*ones(1,12)]';
setup.logit_general_ub=[25*ones(1,12) 5000*ones(1,12)]';
% % Alternative identification scheme: sign restriction to (set) identify shock
% % beta0_pi<0 and a_pi<0 for shock to third variable (monetary shock)
% % a_r>0 (and beta0_r>0, which is always imposed in setup_NL)
% % also impose -25<b<25 and 8<c<4000 (for illustration)
% setup.index_logit_general=[11 41 20 21 44 45 22:30 46:48 31:39 49:51];
% setup.length_logit_general=length(setup.index_logit_general);
% setup.logit_general_lb=[-10 -10 -10 -1e-9 -10 -1e-9 -25*ones(1,12) 8*ones(1,12)]';
% setup.logit_general_ub=[1e-9 1e-9 1e-9 10 1e-9 10 25*ones(1,12) 5000*ones(1,12)]';
%Verify that initial guess is inside the bounds:
if max(setup.initial_parameter(setup.index_logit_general)<=setup.logit_general_lb)==1 | max(setup.initial_parameter(setup.index_logit_general)>=setup.logit_general_ub)==1
'Initial Guess inside the bounds!!'
stop
end
%% Set prior parameters (and identifying restrictions imposed through priors)
% %scaling for adaptive MCMC (see handbook of MCMC, page 104) ADAPTED
% setup.scaling_adaptive=.03^2/setup.length_param_vector;
setup.index_gamma=[];
setup.index_normal=[];
%In our examples, we only use Normal priors
setup.index_normal=[1:setup.length_param_vector]';
setup.normal_prior_means=[setup.initial_parameter;];
setup.normal_prior_std=2*abs([setup.initial_parameter;]);
%contemporaneous matrix:
setup.normal_prior_std(setup.index_block{1})=10;
% a:
setup.normal_prior_std(setup.index_block{2})=10;
% b:
setup.normal_prior_std(setup.index_block{3})=10;
% c:
setup.normal_prior_std(setup.index_block{4})=20^2;
% Example of short-run pointwise restriction: tight prior at 0 for upper diagonal elements of last column of contemp impact matrix)
setup.normal_prior_std([10 11 40 41])=1e-3;
%scaling for adaptive MCMC (see handbook of MCMC, page 104) ADAPTED
setup.scaling_adaptive=.03^2/setup.length_param_vector;
%% Estimation
[ draws, acc_rate, log_posteriors, statedraws, add_matrices] = sampling_MH( setup );
%add_matrices store the estimated shocks
save results/test_NL
toc
% Get shock series
inds=setup.number_of_draws/setup.keep_draw;
indices_for_draws=unidrnd(inds,1000,1);
shocks=add_matrices(:,:,indices_for_draws);
median_shock=squeeze(prctile(shocks,50,3));
lower_shock=squeeze(prctile(shocks,5,3));
upper_shock=squeeze(prctile(shocks,95,3));
% Plot IRFs
plots_irfs