File: map_regime.m

package info (click to toggle)
dynare 6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 67,632 kB
  • sloc: cpp: 79,090; ansic: 28,916; objc: 12,430; yacc: 4,528; pascal: 1,993; lex: 1,441; sh: 1,121; python: 634; makefile: 626; lisp: 163; xml: 18
file content (52 lines) | stat: -rw-r--r-- 2,062 bytes parent folder | download | duplicates (2)
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
function [regime, regime_start, error_flag]=map_regime(binding_indicator,debug_switch)
% function [regime, regime_start, error_flag]=map_regime(binding_indicator)
% Map regime indicator into information
%
% Inputs:
% - binding_indicator [integer]   [nperiods by 1] vector of regime indices
% - debug_switch      [boolean]   indicator for printing warnings
%
% Outputs:
% - regime          [integer]   [1 by n_transitions] vector of regime number indices
% - regime_start    [integer]   [1 by n_transitions] vectors with period numbers in which regime starts
% - error_flag      [boolean]   1 if regime never leaves 1 or is still there at the end of nperiods
%                               0 otherwise

% Original authors: Luca Guerrieri and Matteo Iacoviello 
% Original file downloaded from:
% https://www.matteoiacoviello.com/research_files/occbin_20140630.zip
% Adapted for Dynare by Dynare Team.
%
% This code is in the public domain and may be used freely.
% However the authors would appreciate acknowledgement of the source by
% citation of any of the following papers:
%
% Luca Guerrieri and Matteo Iacoviello (2015): "OccBin: A toolkit for solving
% dynamic models with occasionally binding constraints easily"
% Journal of Monetary Economics 70, 22-38

error_flag=0;
if isempty(binding_indicator)
    binding_indicator = false;
end
% analyse violvec and isolate contiguous periods in the other regime.
regime(1) = binding_indicator(1);
regime_index = 1;
regime_start(1) = 1;
for i=2:length(binding_indicator)
    if binding_indicator(i)~=regime(regime_index)
        regime_index=regime_index+1;
        regime(regime_index) = binding_indicator(i);
        regime_start(regime_index)=i;
    end
end

if (regime(1) == 1 && length(regime_start)==1)
    disp_verbose('map_regime: Binding regime was never left. nperiods needs to be increased.',debug_switch);
    error_flag=1;
end

if (regime(end)==1)
    disp_verbose('map_regime: Constraint(s) are binding at the end of the sample. nperiods needs to be increased.',debug_switch);
    error_flag=1;
end