Loop in dynare results in indeterminancy error, but no error when run from dynare file

Hello, I am trying to run a loop from loop.m file in basic.mod dynare file. I try in two approaches:
First–from loop.m I run

beta = 0.9;
for i = 1:4 
gamma = i*0.01;
save file_name
dynare basic noclearall  
end

Then in the basic.mod dynare file

load file_name;
set_param_value('beta',beta).

But this results in Error using print_info (line 45)
Blanchard Kahn conditions are not satisfied: indeterminacy.

However, if I define parameter values in .mod file and run a loop, the file runs in without any indeterminancy error. But the loop only runs in without changing the gamma parameter. Could you tell me where I am making a mistake? I have seen previous posts on loops resulting in indeterminancy error. In my case, there is no indeterminancy error when run from dynare.

Thanks.

I would need to see the full files.

Thank you for your reply. This is my loop.m file:

T=200;  % observations used in simulations
T2=100; % number of periods for IRFs

loeirf=zeros(T2,30);
iiiy =1;
iiice=2;
iiich=3;
iiire=4;
iiirh=5;
iiiloe=6;
iiiq=7;


BETAH   = 0.9925;   
BETAE   = 0.94;   
BETAB   = 0.945;   
TAUH    = 2;
NU      = 0.05;
JEI     = 0.075;
MN      = 1;
MH      = 0.9;
FILOEE  = 0.25;
FILOEB  = 0.25;
RHO_ABH = 0.8;
LOE_SS = 0.4937;
Y_SS = 0.3248;

for i = 2:4

GAMMAE    = (i-1)*0.09;
save parameterfile BETAH BETAE BETAB TAUH NU JEI MN MH GAMMAE FILOEE FILOEB RHO_ABH LOE_SS Y_SS

dynare fbctiny noclearall

load dynarerocks

loe    = zeros(T2,1);
prod   = zeros(T2,1);	
dep = zeros(T2,1);
housee = zeros(T2,1);
househ = zeros(T2,1);
rateh = zeros(T2,1);
randn('state',20080701);
shocks = zeros(T,1);
shocks(2) = 0.25;  
prod(1)= 0;

 
loestst = decision(1,iiiloe); 	
loe(1)  = loestst;

ratehstst = decision(1,iiirh);
rateh(1) = ratehstst;


for t = 2:T2	
prod(t)=RHO_ABH*prod(t-1)+shocks(t);
dep(t) =GAMMAE*loe(t) - shocks(t); 
househ(t) = JEI/(1-BETAH);
housee(t) = 1-househ(t);
rateh(t) = decision(1,iiirh)+decision(2,iiirh)*prod(t-1) ...	
           +decision(3,iiirh)*dep(t-1) + decision(4,iiirh)*housee(t-1)  ...
           +decision(5,iiirh)*househ(t-1) + decision(6,iiirh)*(loe(t-1)-loestst) ...
           +decision(7,iiirh)*(rateh(t-1)-ratehstst) + decision(8,iiirh)*shocks(t);...
loe(t) = decision(1,iiiloe)+decision(2,iiiloe)*prod(t-1) ...	
           +decision(3,iiiloe) *dep(t-1) + decision(4,iiiloe)*housee(t-1)  ...
           +decision(5,iiiloe)*househ(t-1) + decision(6,iiiloe)*(loe(t-1)-loestst) ...
           +decision(7,iiiloe)*(rateh(t-1)-ratehstst) + decision(8,iiiloe)*shocks(t);...
end

loeirf(:,i)=loe-loestst;
 

    if i==1
        plot(loeirf(1:20,1:i),'linewidth',2.2,'color',[0 0 0])
    else
        plot(loeirf(1:20,1:i-1))
        hold on
        plot(loeirf(1:20,i),'linewidth',2.2,'color',[0 0 0])
        hold off
    end
end

Here is my .mod file

var abh, acloeb, acloee, cb, ce, ch, d, he, hh, loe, nh, q, re, rh, wh, y;

varexo eps_bh;

parameters BETAH, BETAE, BETAB, TAUH, NU, JEI, MN, MH, GAMMAE, FILOEE, FILOEB, LOE_SS, RHO_ABH, Y_SS;


load parameterfile;
set_param_value('BETAH',BETAH)
set_param_value('BETAE',BETAE)
set_param_value('BETAB',BETAB)
set_param_value('TAUH',TAUH)
set_param_value('NU',NU)
set_param_value('JEI',JEI)
set_param_value('MN',MN)
set_param_value('MH',MH)
set_param_value('GAMMAE',GAMMAE)
set_param_value('FILOEE',FILOEE)
set_param_value('FILOEB',FILOEB)
set_param_value('RHO_ABH',RHO_ABH)
set_param_value('LOE_SS',LOE_SS)
set_param_value('Y_SS',Y_SS)
 

model;

//% Households
//1
ch+d+q*(hh-hh(-1))=rh(-1)*d(-1)+wh*nh+abh;
//2
1/ch=BETAH*rh*(1/(ch(+1)));
//3
wh/ch=(TAUH/(1-nh));
//4
q/ch=JEI/hh+BETAH*q(+1)/(ch(+1));



//% Banks
//5
cb+rh(-1)*d(-1)+loe=d+re*loe(-1)-abh;
//6
d=GAMMAE*(loe-abh);
//7
(1-GAMMAE+acloeb)*(cb(+1))=BETAB*(re(+1)-GAMMAE*rh)*(cb);



//% Entrepreneurs
//8
ce+q*(he-he(-1))+re*(loe(-1))+wh*nh=y+loe;
//9
y=((he(-1))^NU)*(nh^(1-NU));
//10
loe=MH*(q(+1)/(re(+1)))*he-MN*wh*nh;
//11
(q-(1-acloee)*((MH*q(+1))/(re(+1))))*(1/ce)=
BETAE*(q(+1)*(1-MH)+NU*(y(+1)/he))*(1/(ce(+1)));

//12
(1-NU)*y=wh*nh*(1+MN*(1-acloee-BETAE*re(+1)*ce/ce(+1)));
//13
he+hh=1;
//14
abh=RHO_ABH*abh(-1)+eps_bh;
//15
acloeb = FILOEB*((loe)-(loe(-1)))/LOE_SS ;
//16
acloee = FILOEE*((loe)-(loe(-1)))/LOE_SS;

end;


initval;

ch=0.5;
d=0.5;
wh=1;
nh=0.3436;
rh=1.0075;
re=1.0126;
he=0.2639;
hh=0.8; 
q=3;
loe=0.5;
y=0.5;
ce=0.01; 
cb=0.01; 
abh=0;
acloee=0;
acloeb=0;
 
end;


shocks;
var eps_bh; stderr 1;
end;

stoch_simul(order=1,nocorr,nomoments,IRF=0) y ce ch re rh loe q;

This .mod file runs perfectly when parameter values are specified in the mod file, but results in Blanchard Kahn indeterminancy when asked from “set_param_value”.

You are working with

We don’t provide support for that tool here.