# What‘s wrong with my dynare code?

I’ve checked my codes for many times,but there’s still no steady state.
I introduce my model first.there are two families(c,d) and two firms(a,b).Family a holds deposits in commercial banks and buys bonds from government, and family b borrow loans from commercial banks.
Firms are intermediate good firms and firm a has better technology.
Both firms decide their own prices by calvo rule.But firm a can decide its price every time,Firm b decides its price in a probability 1-v.So the aggregate price is decided by price a and price b.And from this I can deduct the NKPC.

I wonder whether there are something wrong in my codes.somebody said that if model in codes is not linear,it is difficult to give a initial value.but some equations in my model is not easy to be lineared.
I hope somebody could help me.thks！

``````close all;

var ha;  //labour of firm a
var hb;  //labour of firm b
var hc;  //labour from family c
var hd;  //labour from family d
var ka;   //capital of firm a
var kb;   //capital of firm b
var wac;  //wage of family c working in firm a
var wad;  //wage of family d working in firm a
var wbc;  //wage of family c working in firm b
var wbd ; //wage of family d working in firm b
var wa;   //wage from firm a
var wb;   //wage form firm b
var wc;   //wage of family c
var wd;   //wage of family d
var r;   //real capital cost
var mca;  //marginal cost of firm a
var mcb;  //marginal cost of firm b
var dc;  //deposit of family c
var z;   //technique
var  ya;
var  yb;
var  y;
var  ia;
var  ib;
var  lb;
var  ld;
var  bi;
var  bc;
var  cc;
var  cd;
var  pi;

varexo e;

parameters
alpha,chi,omiga,lamda,gamma,thelta,omegaa,omegab,delta,phi1,phi2,gy,m,rhob,epsilong,miu1,miu2,beta,miu11,qc,kappa,para_pre,lota,taul,taula,taulb,rb,rhoz,id;
alpha=.7;chi=5;omiga=.5;lamda=.3;gamma=.65;thelta=.6;omegaa=.01;omegab=.01;delta=0.1;phi1=4;
phi2=.3; //Consumption habit formation
epsilong=0.2; //Calvo parameter
gy=1;m=.7;rhob=.25;
miu1=.15;miu2=.8;beta=0.9;miu11=.16;lota=.4;
rb=.04;kappa=.2;id=.03;para_pre=.025;taul=.025;taula=.35;taulb=.3;

//Shock persistence
rhoz=0.61;

model;
//Household
miu1*wc/(cc-phi2*cc(-1))-miu2/(1-hc)-beta*miu1*phi2*wc/(cc(+1)-phi2*cc)=0;
-miu1/(cc-phi2*cc(-1))+(1-miu1-miu2)/dc+beta*miu1*(((1+id)/((cc(+1)-phi2*cc)*pi(+1))+phi2/(cc(+1)-phi2*cc)))=0;
-miu1/(cd-phi2*cd(-1))+beta*miu1*((1+rb)/((cc(+1)-phi2*cc)*pi(+1))-phi2/(cc(+1)-phi2*cc))=0;
miu11*wd/(cd-phi2*cd(-1))-(1-miu11)/(1-hd)+beta*miu11*(-phi2)*wd/(cd(+1)-phi2*cd)=0;
miu11/(cd-phi2*cd(-1))=beta*miu11*(-phi2/(cd(+1)-phi2*cd)-(1+r(+1))/(pi(+1)*(cd(+1)-phi2*cd)));

// Capital law of motion
ka=(1-delta)*ka(-1)+(1-((phi1/2)*(ia/ia(-1)-gy)^2))*ia;
kb=(1-delta)*kb(-1)+(1-((phi1/2)*(ib/ib(-1)-gy)^2))*ib;

// Intermediate Firms
log(ha)=log(lamda)+gamma*log(hc)+(1-gamma)*log(hd);
log(hb)=log(1-lamda)+thelta*log(hc)+(1-thelta)*log(hd);
log(wac)=log(1-alpha)+log(lamda)+log(gamma)+(1-alpha)*log(chi)+log(z)+alpha*log(ka)+(gamma-1-alpha*gamma)*log(hc)+(1-gamma)*(1-alpha)*log(hd);
log(wbc)=log(thelta)+log(1-omiga)+log(1-lamda)+log(z)+omiga*log(kb)+(thelta-1-thelta*omiga)*log(hc)+(1-thelta)*(1-omiga)*log(hd);
log(wbd)=log((1-omiga)*(1-thelta)*(1-lamda))+log(z)+omiga*log(ka)+(thelta*(1-omiga))*log(hc)+(omiga*thelta-omiga-thelta)*log(hd);
log(wa)=log(1-alpha)+log(ya)-log(ha);
log(wb)=log(1-omiga)+log(yb)-log(hb);
wc=wac+wbc;
log(mca)=log(wa)-log(1-alpha)-log(z)+alpha*(log(taul)+log(1-alpha)-log(wa)-log(alpha));
log(mcb)=log(wb)-log(1-omiga)-log(z)+omiga*(log(m)+log(r)+log(1-omiga)-log(wb)-log(omiga));
log(r)=log(omiga)+log(y)-log(kb);

//Final firm;
y^(1/(1+epsilong))=lamda*(ya^(1/(1+epsilong)))+(1-lamda)*(yb^(1/(1+epsilong)));

//first order of intermidiate firms
log(1-alpha)+log(taul)-log(alpha)-log(wa)=log(ha)-log(ka);
log(1-omiga)+log(m)+log(r)-log(omiga)-log(wb)=log(hb)-log(kb);

// Calvo Pricing NKPC
log(pi)=((beta^2)/epsilong)*log(pi(+2))-beta*(lamda*(1-rhob)+rhob*(1-epsilong))*log(pi(+1))/(epsilong*rhob)-lamda*(1-beta)*log(mca)/(epsilong*rhob)+lamda*beta*(1-beta)*log(mca(+1))/epsilong+((1+lamda+epsilong*rhob)*(1-beta*rhob)*log(mcb)/(epsilong*rhob));

//Goods market equilibrium
y=cc+cd+ia+ib;

//CD Production Function
log(ya)=log(z)+alpha*log(ka)+(1-alpha)*log(chi*ha);
log(yb)=log(z)+omiga*log(kb)+(1-omiga)*log(hb);

//commercial banks
lb+ld+bi=dc*(1-kappa);
r*lb+r*ld+rb*bi(-1)=(id+para_pre)*dc;

//government
taula*ya+taulb*yb+taul*ka+bi+bc=(1+rb)*bi(-1)+(1+rb)*bc(-1);

//Exogenous processes
log(z)=rhoz*log(z(-1))+e;
end;
initval;
ha=1;
hb=2;
hc=1.2;
hd=1.3;
ka=4;
kb=3;
wa=.05;
wb=.02;
wac=.01;
wbc=.01;
wbd=.01;
r=.01;
mca=.5;
mcb=.6;
dc=1.5;
z=1;
ya=1;
yb=1;
y=1;
cc=.25;
cd=.2;
pi=1;
e=0;
end;
check;
shocks;
var e;  stderr  0.1;
end;
check;
//model_diagnostics;
//identification;
stoch_simul;
``````

It is hard to tell. The problem often is that there is still a mistake somewhere in the model equations and steady state computations then fail, because the wrong equations do not have a steady state. Given the size of your model, it will be very hard to debug. I can only recommend trying to compute the steady state analytically.

THANKS.
I checked my equations and codeday1.mod (4.7 KB)
,and corrected some mistakes.I just imitated someone’s model so there should not be logistic problem.What’s more,does computing the steady state analytically mean log-linearation?

You are already doing an exp()-substitution. That is not a good idea if your model does not run yet. Your variables in the model are now defined in logs, but the initial values you provide are in levels. That does not work. Please first make sure the model runs in levels.

No, analytically computing the steady state is not equal to log-linearization. For the latter you usually need to do the former. But you can compute a steady state of the nonlinear system without having to approximate equations