function fval = BBCDLmodelcomp_ramsey_c1y_c2y_endoss(variablesguess,instr1,instr2)


global M_ 

%% assign variables and parameter values 

num_variablesguess=size(variablesguess,1);
for idxxx=1:1:num_variablesguess
    define_string=[M_.endo_names_reduced(idxxx,:),'=',sprintf('%20.20g',variablesguess(idxxx))];
    evalc(define_string);
end

if isnan(M_.params(:,:))==0
    %read parameter values from M_.params and assign to parameters names.
    %this overwrites parameters coming from params.m if estimation is done.
    num_para=size(M_.params,1);
    for idxxx=1:1:num_para
        define_string=[M_.param_names(idxxx,:),'=',sprintf('%20.20g',M_.params(idxxx))];
        evalc(define_string);
    end
end
 
 
fval(1) = Util - ( omega_welf1*Util1+omega_welf2*Util2); 
 
fval(2) = Welf - ( Util + nbeta*Welf); 
 
fval(3) = Welf1 - ( Util1 + nbeta*Welf1); 
 
fval(4) = Welf2 - ( Util2+ nbeta*Welf2); 
 
fval(5) = instr1 - ( c1y); 
 
fval(6) = instr2 - ( c2y); 
 
fval(7) =  c1deltadlag - (c1deltad);  
fval(8) = c1deltadlag2 - (c1deltadlag);  
fval(9) = c1ngdplag - (c1ngdp);  
fval(10) = c1ngdplag2 - (c1ngdplag);  
fval(11) = c1pcorelag - (c1pcore);  
fval(12) = c1pcorelag2 - (c1pcorelag);  
fval(13) = c1rerlag - (c1rer);  
fval(14) = c1rerlag2 - (c1rerlag);  
fval(15) = c1rnlag - (c1rn);  
fval(16) = c1rnlag2 - (c1rnlag);  
fval(17) = c1rpcpdlag - (c1rpcpd);  
fval(18) = c1rpcpdlag2 - (c1rpcpdlag);  
fval(19) = c1ylag - (c1y);  
fval(20) = c1ylag2 - (c1ylag);  
fval(21) = c2deltadlag - (c2deltad);  
fval(22) = c2deltadlag2 - (c2deltadlag);  
fval(23) = c2ngdplag - (c2ngdp);  
fval(24) = c2ngdplag2 - (c2ngdplag);  
fval(25) = c2pcorelag - (c2pcore);  
fval(26) = c2pcorelag2 - (c2pcorelag);  
fval(27) = c2rerlag - (c2rer);  
fval(28) = c2rerlag2 - (c2rerlag);  
fval(29) = c2rnlag - (c2rn);  
fval(30) = c2rnlag2 - (c2rnlag);  
fval(31) = c2rpcpdlag - (c2rpcpd);  
fval(32) = c2rpcpdlag2 - (c2rpcpdlag);  
fval(33) = c2ylag - (c2y);  
fval(34) = c2ylag2 - (c2ylag);  
  
 
 
fval(35) = Welfcon1 - ( (exp(c1c))^(1-c1sigma)/(1-c1sigma) + c1beta*Welfcon1); 
 
 
 
fval(36) = 1/(1+(c1rn)) - ( c1beta*(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))/(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))/c1pid); 
 
fval(37) = exp(c1rpcpd)*(c1omegac*exp(c1c)/exp(c1cd))^(c1rhoc/(1+c1rhoc)) - ( 1); 
 
fval(38) = (exp(c1rer))/(exp(c2rpcpd))- ( (c1omegamc*exp(c1c)/exp(c1mc))^(c1rhoc/(1+c1rhoc))); 
 
fval(39) = exp(c1c) - ( ((c1omegac)^(c1rhoc/(1+c1rhoc))*exp(c1cd)^(1/(1+c1rhoc))+(c1omegamc)^(c1rhoc/(1+c1rhoc))*(exp(c1mc))^(1/(1+c1rhoc)))^(1+c1rhoc)); 
 
fval(40) = (exp(c1pstar))^(1+(1+c1nup)/(c1nup)*c1chi) - ( (exp(c1hp))/(exp(c1gp))); 
 
fval(41) = (exp(c1hp)) - ( (1+(c1nup))/(c1nup) ... 
*c1chi0*(exp(c1y)/exp(c1z))^(c1chi)/((exp(c1c))^(-c1sigma)/exp(c1rpcpd))*exp(c1y) ... 
+ c1xip*c1beta*(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))/(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))*((c1pistar)/(c1pid))^(-(1 ... 
+(c1nup))/(c1nup)*(1+c1chi))*(exp(c1hp))); 
 
fval(42) = (exp(c1gp)) - ( (1+c1taup*exp(c1taupvar))/(c1nup)*(exp(c1y))+c1xip*c1beta*(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))/(((exp(c1c))^(-c1sigma)/exp(c1rpcpd)))*((c1pistar)/(c1pid))^(1 ... 
-(1+(c1nup))/(c1nup))*(exp(c1gp))); 
 
fval(43) = (1-c1xip)*((exp(c1pstar)))^(-1/(c1nup))+c1xip*((c1pistar)/(c1pid))^(-1/(c1nup)) - ( 1); 
 
fval(44) = (exp(c1deltad)) - ( (1-c1xip)*((exp(c1pstar)))^(-(1+(c1nup))/(c1nup)*(1+c1chi)) ... 
+c1xip*((c1pistar)/(c1pid))^(-(1+(c1nup))/(c1nup)*(1+c1chi))*(exp(c1deltadlag))); 
 
fval(45) = exp(c1y) - ( exp(c1cd)+exp(c1g)+1/c1relc2*(exp(c2mc))); 
 
fval(46) = exp(c1g) - ( c1sharegy*exp(c1y)*exp(c1shockgy)); 
 
fval(47) = c1dcore - ( exp(c1rpcpd)/exp(c1rpcpdlag)*c1pid); 
 
fval(48) = exp(c1ngdp)/exp(c1ngdplag) - ( c1pid*exp(c1y)/exp(c1ylag));  
 
fval(49) = c1dcore - ( exp(c1pcore)/exp(c1pcorelag)); 
 
 
 
fval(50) = 1/(1+(c2rn)) - ( c2beta*(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))/(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))/c2pid); 
 
fval(51) = (exp(c2rpcpd))*(c2omegac*(exp(c2c))/(exp(c2cd)))^(c2rhoc/(1+c2rhoc)) - ( 1); 
 
fval(52) = 1/(exp(c1rer))/(exp(c1rpcpd)) - ( (c2omegamc*(exp(c2c))/(exp(c2mc)))^(c2rhoc/(1+c2rhoc))); 
 
fval(53) = (exp(c2c)) - ( ((c2omegac)^(c2rhoc/(1+c2rhoc))*(exp(c2cd))^(1/(1+c2rhoc))+(c2omegamc)^(c2rhoc/(1+c2rhoc))*((exp(c2mc)))^(1/(1+c2rhoc)))^(1+c2rhoc)); 
 
fval(54) = (exp(c2pstar))^(1+(1+c2nup)/(c2nup)*c2chi) - ( (exp(c2hp))/(exp(c2gp))); 
 
fval(55) = (exp(c2hp)) - ( (1+(c2nup))/(c2nup) ... 
*c2chi0*(exp(c2y)/exp(c2z))^c2chi/((exp(c2c))^(-c2sigma)/exp(c2rpcpd))*exp(c2y) ... 
+ c2xip*c2beta*(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))/(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))*((c2pistar)/(c2pid))^(-(1 ... 
+(c2nup))/(c2nup)*(1+c2chi))*(exp(c2hp))); 
 
fval(56) = (exp(c2gp)) - ( (1+c2taup*exp(c2taupvar))/(c2nup)*(exp(c2y))+c2xip*c2beta*(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))/(((exp(c2c))^(-c2sigma)/exp(c2rpcpd)))*((c2pistar)/(c2pid))^(1 ... 
-(1+(c2nup))/(c2nup))*(exp(c2gp))); 
 
fval(57) = (1-c2xip)*((exp(c2pstar)))^(-1/(c2nup))+c2xip*((c2pistar)/(c2pid))^(-1/(c2nup)) - ( 1); 
 
fval(58) = (exp(c2deltad)) - ( (1-c2xip)*((exp(c2pstar)))^(-(1+(c2nup))/(c2nup)*(1+c2chi)) ... 
+c2xip*((c2pistar)/(c2pid))^(-(1+(c2nup))/(c2nup)*(1+c2chi))*(exp(c2deltadlag))); 
 
fval(59) = (exp(c2y)) - ( (exp(c2cd))+(exp(c2g))+(c1relc2*(exp(c1mc)))); 
 
fval(60) = (exp(c2g)) - ( c2sharegy*(exp(c2y))*(exp(c2shockgy))); 
 
fval(61) = c2dcore - ( exp(c2rpcpd)/exp(c2rpcpdlag)*c2pid); 
 
fval(62) = exp(c2ngdp)/exp(c2ngdplag) - ( c2pid*exp(c2y)/exp(c2ylag));  
 
fval(63) = c2dcore - ( exp(c2pcore)/exp(c2pcorelag)); 
 
 
fval(64) = c2lambdaqss/((exp(c2c))^(-c2sigma))*c2rpcpdss - ( c1rerss/(exp(c1rer))*c1lambdaqss/((exp(c1c))^(-c1sigma))*c1rpcpdss); 
 
fval(65) = exp(c1rer) - ( 1/exp(c2rer)); 
 
fval(66) = exp(c1rer)/exp(c1rerlag) - ( exp(c1dnxf)*c2dcore/c1dcore); 
 
fval(67) = exp(c2rer)/exp(c2rerlag) - ( exp(c2dnxf)*c1dcore/c2dcore); 
 
fval(68) = Util1 - ( (exp(c1c))^(1-c1sigma)/(1-c1sigma)-c1chi0*(exp(c1z))^(-c1chi)*(exp(c1y))^(1+c1chi)/(1+c1chi)*exp(c1deltad)); 
 
fval(69) = Util2 - ( (exp(c2c))^(1-c2sigma)/(1-c2sigma)-c2chi0*(exp(c2z))^(-c2chi)*(exp(c2y))^(1+c2chi)/(1+c2chi)*exp(c2deltad)); 
 
 
 
fval(70) = c1shockgy - ( c1rhogy*c1shockgy + c1sigmagy*0); 
 
fval(71) = c1z - ( c1rhoz*c1z + c1sigmaz*0); 
 
fval(72) = c1taupvar - ( c1rhotaupvar*c1taupvar+c1sigmataupvarerr*0); 
 
fval(73) = c2shockgy - ( c2rhogy*c2shockgy + c2sigmagy*0); 
 
fval(74) = c2z - ( c2rhoz*c2z + c2sigmaz*0); 
 
fval(75) = c2taupvar - ( c2rhotaupvar*c2taupvar+c2sigmataupvarerr*0); 
 
