Continue dynare loop even when B/K condition violated (or

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Continue dynare loop even when B/K condition violated (or

Postby leolee » Fri Mar 24, 2017 3:05 am

Dear prof. Pfeifer,

I'm trying to loop a mod file over a lot of parameter sets and see which set can be solved and which cannot.

The problem is when one of them is not solvable (e.g, since BK condition violated), it stops the entire loop.

From the thread below, I found the "noprint" option can partially solve my problem:
http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=5771

I also found those problematic cases doesn't have any IRFs or ghx, ghu etc.

My question is, when I find such cases (no IRF, ghx, ghu,..), can I just think that the problem is from violating BK condition? I tried some of them without "noprint" option, and they were actually violating BK condition. If not, is there any option for saving the error messages somewhere and continue the loop?

Best,
Leo
leolee
 
Posts: 30
Joined: Thu Mar 19, 2015 9:54 am

Re: Continue dynare loop even when B/K condition violated (o

Postby jpfeifer » Fri Mar 24, 2017 8:07 am

Please see http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891. If you call
Code: Select all
info = stoch_simul(var_list_);

the value in
Code: Select all
info

is the error code.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Continue dynare loop even when B/K condition violated (o

Postby leolee » Fri Mar 24, 2017 2:00 pm

jpfeifer wrote:Please see http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891. If you call
Code: Select all
info = stoch_simul(var_list_);

the value in
Code: Select all
info

is the error code.


jpfeifer wrote:Please see http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=4891. If you call
Code: Select all
info = stoch_simul(var_list_);

the value in
Code: Select all
info

is the error code.


Dear Professor Pfeifer,

Thank you again for your kind and quick answer. It is helping me a lot.
I encountered another problem when trying loop over parameters using
Code: Select all
info = stoch_simul(var_list_);

The following is how I conducted my dynare looping over parameters. When I run the following code, I got some error messages saying "Maxit has been reached" for some of parameter sets.

Code: Select all
eval('S02_parameter_set');
save param_set.mat param_set;

for cases=1:144
    load('param_set.mat');
    if cases==1
        param_for_dynare = param_set(cases,:)';
        save param_mat.mat param_for_dynare;
        dynare simul_final -DIRF=1 noclearall
    else
        param_for_dynare = param_set(cases,:)';
            set_param_value('DZBar',param_for_dynare(1));
            set_param_value('eta',param_for_dynare(2));
            set_param_value('theta',param_for_dynare(3));
            set_param_value('xi',param_for_dynare(4));       
            set_param_value('IES',param_for_dynare(5));      
            set_param_value('betatilde',param_for_dynare(6));
            set_param_value('delta',param_for_dynare(7));
            set_param_value('LMax',param_for_dynare(8));
            set_param_value('Frisch',param_for_dynare(9));      
            set_param_value('CRRA',param_for_dynare(10));      
            set_param_value('taylrho',param_for_dynare(11));   
            set_param_value('taylpi',param_for_dynare(12));
            set_param_value('tayly',param_for_dynare(13));
            set_param_value('piBar',param_for_dynare(14));      
            set_param_value('rhoa',param_for_dynare(15));
            set_param_value('rhog',param_for_dynare(16));
            set_param_value('rhoinflavg',param_for_dynare(17));
            set_param_value('rhoz',param_for_dynare(18));
            set_param_value('rhopistar',param_for_dynare(19));
            set_param_value('sigmaa',param_for_dynare(20));   
            set_param_value('sigmag',param_for_dynare(21));   
            set_param_value('sigmai',param_for_dynare(22));
            set_param_value('sigmaz',param_for_dynare(23));   
            set_param_value('sigmapistar',param_for_dynare(24));
            set_param_value('gssload',param_for_dynare(25));   
            set_param_value('zeta',param_for_dynare(26));   
            set_param_value('omegaG',param_for_dynare(27));   
            set_param_value('DoYss',param_for_dynare(28));   
            set_param_value('Gamma1',param_for_dynare(29));   
            set_param_value('Gamma2',param_for_dynare(30));   
            info = stoch_simul(var_list_);
            if info;
                str = ['Computation fails for Case ' num2str(cases)];
               disp(str);
            end;
    end
end


What I cannot understand is, however, when I run dynare in each loop rather than just using
Code: Select all
info = stoch_simul(var_list_);
command from the 2nd iteration and on, It doesn't give me any error message.

For example, case#144 gives "Maxit has been reached" from the code above. But, when I run
Code: Select all
param_for_dynare = param_set(144,:)';
save param_mat.mat param_for_dynare;
dynare simul_final -DIRF=1 noclearall

It doesn't give me any error message.

Could you help me how should I understand this problem?

Attached are my mod file (which is replicating and sort of modifying Rudebusch and Swanson 2012), and sets of parameters (m.file)

Best,
Leo
Attachments
simul_final.mod
(10.24 KiB) Downloaded 54 times
M02_parameter_set.m
(2.15 KiB) Downloaded 46 times
leolee
 
Posts: 30
Joined: Thu Mar 19, 2015 9:54 am

Re: Continue dynare loop even when B/K condition violated (o

Postby jpfeifer » Sat Mar 25, 2017 9:04 am

That happens, because you are not correctly handling parameter dependence. See http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=6727
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Continue dynare loop even when B/K condition violated (o

Postby leolee » Sun Mar 26, 2017 12:07 am

jpfeifer wrote:That happens, because you are not correctly handling parameter dependence. See http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=6727


Thank you very much. Now I understand!
leolee
 
Posts: 30
Joined: Thu Mar 19, 2015 9:54 am

Re: Continue dynare loop even when B/K condition violated (o

Postby leolee » Sun Mar 26, 2017 4:16 am

jpfeifer wrote:That happens, because you are not correctly handling parameter dependence. See http://www.dynare.org/phpBB3/viewtopic.php?f=1&t=6727


Dear Prof. Pfeifer,

Even though I changed my mod file such that all the dependent parameters become model-local variables, the problem still exist.
When I run the following code,
Code: Select all
eval('S02_parameter_set');
save param_set.mat param_set;

for cases=1:144
    load('param_set.mat');
    if cases==1
        param_for_dynare = param_set(cases,:)';
        save param_mat.mat param_for_dynare;
        dynare simul_test_steady -DIRF=1 noclearall
    else
        param_for_dynare = param_set(cases,:)';
            set_param_value('DZBar',param_for_dynare(1));
            set_param_value('eta',param_for_dynare(2));
            set_param_value('theta',param_for_dynare(3));
            set_param_value('xi',param_for_dynare(4));       
            set_param_value('IES',param_for_dynare(5));     
            set_param_value('betatilde',param_for_dynare(6));
            set_param_value('delta',param_for_dynare(7));
            set_param_value('LMax',param_for_dynare(8));
            set_param_value('Frisch',param_for_dynare(9));     
            set_param_value('CRRA',param_for_dynare(10));     
            set_param_value('taylrho',param_for_dynare(11));   
            set_param_value('taylpi',param_for_dynare(12));
            set_param_value('tayly',param_for_dynare(13));
            set_param_value('piBar',param_for_dynare(14));     
            set_param_value('rhoa',param_for_dynare(15));
            set_param_value('rhog',param_for_dynare(16));
            set_param_value('rhoinflavg',param_for_dynare(17));
            set_param_value('rhoz',param_for_dynare(18));
            set_param_value('rhopistar',param_for_dynare(19));
            set_param_value('sigmaa',param_for_dynare(20));   
            set_param_value('sigmag',param_for_dynare(21));   
            set_param_value('sigmai',param_for_dynare(22));
            set_param_value('sigmaz',param_for_dynare(23));   
            set_param_value('sigmapistar',param_for_dynare(24));
            set_param_value('gssload',param_for_dynare(25));   
            set_param_value('zeta',param_for_dynare(26));   
            set_param_value('omegaG',param_for_dynare(27));   
            set_param_value('DoYss',param_for_dynare(28));   
            set_param_value('Gamma1',param_for_dynare(29));   
            set_param_value('Gamma2',param_for_dynare(30));   
            info = stoch_simul(var_list_);
            if info;
                str = ['Computation fails for Case ' num2str(cases)];
               disp(str);
            end;
    end
end

case 1,2,3,4 were OK, but case 5 gives an error message.

Then I changed the parameters of my mode file same as case 5 and manually ran the mod file, and it didn't give any error message. After that,
Code: Select all
info = stoch_simul(var_list_)
also gives no error message.

Given that all the "dependent parameters" are moved to the model part (as #variables), I think the problem should be disappear.
Could you give me some advice?

Best,
Leo
Attachments
S02_parameter_set.m
(9.39 KiB) Downloaded 41 times
simul_test.mod
mod file with no model-local variables
(9.33 KiB) Downloaded 40 times
simul_test_steady.mod
dependent parameters are changed into model-local variables
(14.47 KiB) Downloaded 39 times
leolee
 
Posts: 30
Joined: Thu Mar 19, 2015 9:54 am

Re: Continue dynare loop even when B/K condition violated (o

Postby jpfeifer » Sun Mar 26, 2017 7:32 am

The problem is that you are not using a steady_state-file, but rather an initval block with starting values that differ for different parameter sets. You need to reset these initial values as well. I did that by copy and pasting the respective lines from the m-file created by Dynare.
Code: Select all
eval('S02_parameter_set');
save param_set.mat param_set;

for cases=1:144
    load('param_set.mat');
    if cases==1
        param_for_dynare = param_set(cases,:)';
        save param_mat.mat param_for_dynare;
        dynare simul_test_steady -DIRF=1 noclearall
    else
        param_for_dynare = param_set(cases,:)';
        set_param_value('DZBar',param_for_dynare(1));
        set_param_value('eta',param_for_dynare(2));
        set_param_value('theta',param_for_dynare(3));
        set_param_value('xi',param_for_dynare(4));
        set_param_value('IES',param_for_dynare(5));
        set_param_value('betatilde',param_for_dynare(6));
        set_param_value('delta',param_for_dynare(7));
        set_param_value('LMax',param_for_dynare(8));
        set_param_value('Frisch',param_for_dynare(9));
        set_param_value('CRRA',param_for_dynare(10));
        set_param_value('taylrho',param_for_dynare(11));
        set_param_value('taylpi',param_for_dynare(12));
        set_param_value('tayly',param_for_dynare(13));
        set_param_value('piBar',param_for_dynare(14));
        set_param_value('rhoa',param_for_dynare(15));
        set_param_value('rhog',param_for_dynare(16));
        set_param_value('rhoinflavg',param_for_dynare(17));
        set_param_value('rhoz',param_for_dynare(18));
        set_param_value('rhopistar',param_for_dynare(19));
        set_param_value('sigmaa',param_for_dynare(20));
        set_param_value('sigmag',param_for_dynare(21));
        set_param_value('sigmai',param_for_dynare(22));
        set_param_value('sigmaz',param_for_dynare(23));
        set_param_value('sigmapistar',param_for_dynare(24));
        set_param_value('gssload',param_for_dynare(25));
        set_param_value('zeta',param_for_dynare(26));
        set_param_value('omegaG',param_for_dynare(27));
        set_param_value('DoYss',param_for_dynare(28));
        set_param_value('Gamma1',param_for_dynare(29));
        set_param_value('Gamma2',param_for_dynare(30));
        oo_.steady_state( 1 ) = M_.params(7);
        oo_.steady_state( 2 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17-(M_.params(2)+M_.params(9)-1)*10*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3;
        oo_.steady_state( 3 ) = 1;
        oo_.steady_state( 4 ) = M_.params(9);
        oo_.steady_state( 5 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17;
        oo_.steady_state( 6 ) = log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25)))));
        oo_.steady_state( 7 ) = log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25)))));
        oo_.steady_state( 8 ) = M_.params(3)/3;
        oo_.steady_state( 9 ) = 1/(1+M_.params(4));
        oo_.steady_state( 10 ) = 1;
        oo_.steady_state( 11 ) = 1;
        oo_.steady_state( 12 ) = 1;
        oo_.steady_state( 14 ) = 1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18));
        oo_.steady_state( 15 ) = 1/(1-M_.params(18)*exp((-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))))));
        oo_.steady_state( 17 ) = ((10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17-(M_.params(2)+M_.params(9)-1)*10*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3)^(1-1/M_.params(25))/(1-1/M_.params(25))+10^((1-M_.params(6))/M_.params(6))*M_.params(6)*1/(1+M_.params(4))*(10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17-(M_.params(2)+M_.params(9)-1)*10*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3)^((-1)/M_.params(25))*(M_.params(3)-M_.params(3)/3)^((M_.params(3)-M_.params(3)/3)/M_.params(26))*(M_.params(3)-M_.params(3)/3)^(1-(M_.params(3)-M_.params(3)/3)/M_.params(26))/(1-(M_.params(3)-M_.params(3)/3)/M_.params(26)))/(1-M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(9)^(1-1/M_.params(25)));
        oo_.steady_state( 18 ) = 1;
        oo_.steady_state( 19 ) = M_.params(9)^(1-1/M_.params(25))*((10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17-(M_.params(2)+M_.params(9)-1)*10*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3)^(1-1/M_.params(25))/(1-1/M_.params(25))+10^((1-M_.params(6))/M_.params(6))*M_.params(6)*1/(1+M_.params(4))*(10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17-(M_.params(2)+M_.params(9)-1)*10*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3)^((-1)/M_.params(25))*(M_.params(3)-M_.params(3)/3)^((M_.params(3)-M_.params(3)/3)/M_.params(26))*(M_.params(3)-M_.params(3)/3)^(1-(M_.params(3)-M_.params(3)/3)/M_.params(26))/(1-(M_.params(3)-M_.params(3)/3)/M_.params(26)))/(1-M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(9)^(1-1/M_.params(25)));
        oo_.steady_state( 20 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(6)*1/(1+M_.params(4));
        oo_.steady_state( 21 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3;
        oo_.steady_state( 22 ) = log(M_.params(18)*1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))/(1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))-1))*400;
        oo_.steady_state( 23 ) = 400*log(M_.params(18)*1/(1-M_.params(18)*exp((-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))))))/(1/(1-M_.params(18)*exp((-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))))))-1));
        oo_.steady_state( 24 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(5));
        oo_.steady_state( 25 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(5));
        oo_.steady_state( 16 ) = 100*(log(M_.params(18)*1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))/(1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))-1))*400-400*log(M_.params(18)*1/(1-M_.params(18)*exp((-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))))))/(1/(1-M_.params(18)*exp((-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))))))-1)));
        oo_.steady_state( 27 ) = log(M_.params(18)*1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))/(1/(1-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(18))-1))*400-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25)))))*400;
        oo_.steady_state( 28 ) = M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)));
        oo_.steady_state( 29 ) = M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)));
        oo_.steady_state( 30 ) = M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(9)^((-1)/M_.params(25));
        oo_.steady_state( 31 ) = M_.params(9)^(1-1/M_.params(25))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))/M_.params(28);
        oo_.steady_state( 32 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)*(M_.params(9)^(-1)+M_.params(28)*M_.params(29)/M_.params(9)/(1-M_.params(29)))^(-1);
        oo_.steady_state( 33 ) = M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*M_.params(29)/(1-M_.params(29))/(M_.params(9)^(1-1/M_.params(25))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))/M_.params(28));
        oo_.steady_state( 34 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17+10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)*(M_.params(9)^(-1)+M_.params(28)*M_.params(29)/M_.params(9)/(1-M_.params(29)))^(-1)*(1-M_.params(29))^(-1);
        oo_.steady_state( 39 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30);
        oo_.steady_state( 36 ) = M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25))));
        oo_.steady_state( 35 ) = M_.params(28)*M_.params(9)^(1/M_.params(25))*(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))^(-1);
        oo_.steady_state( 37 ) = M_.params(28)*M_.params(9)^(1/M_.params(25))*(M_.params(1)/M_.params(9)^(-(1/M_.params(25))))^(-1)-1-log(M_.params(9)^(1/M_.params(25))/(M_.params(1)/M_.params(9)^(-(1/M_.params(25)))));
        oo_.steady_state( 38 ) = 0;
        oo_.steady_state( 40 ) = (10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17+10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)-M_.params(9)^(-(1/M_.params(25)))*M_.params(1)/M_.params(9)^(-(1/M_.params(25)))*10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)*(M_.params(9)^(-1)+M_.params(28)*M_.params(29)/M_.params(9)/(1-M_.params(29)))^(-1)*(1-M_.params(29))^(-1)-10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*0.17)/oo_.steady_state(21);
        oo_.steady_state( 41 ) = 10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3*M_.params(30)/(10^((1-M_.params(6))/M_.params(6))*M_.params(3)/3);
        info = stoch_simul(var_list_);
        if info;
            str = ['Computation fails for Case ' num2str(cases)];
            disp(str);
        end;
    end
end
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 5 guests