# Solving a very nonlinear problem

Dear Users,

I apologize if this question is redundant with what has been asked recently, but I am a new user of Dynare; although have been using Matlab for some time, the nonlinearity of my optimization problem has led me to using Dynare in hopes that it will solve it more easily.

I have been trying to follow the methodology on one of Tom Sargent’s et al. papers on practicing with Dynare: files.nyu.edu/ts43/public/research/AP_tom16.pdf. In particular, I am imitating the first example.

My code is very similar; I start with the number of periods, I write all the parameters and endogenous variables, and then I write the model with its FOCs. (I am happy to post it if viewers are curious; it is not too long.) However, it returns to me a very basic problem, namely “The expression to the left of the equals sign is not a valid
target for an assignment.” This is from where I write the FOCs with an equal sign.

At the end, I write the initial values, and then I have:
stoch_simul(dr_algo=0,periods=100); datasaver(‘simudata’,]);

If anyone notices something peculiar, I would be very indebted. Thank you for your time in reading this,

As always, please post the mod-file

Thank you for the reply jpfeifer – apologies for not following proper protocol in the initial post. Below is my .mod file, but I will first explain it.

It’s a model where households choose between consumption and hours worked, but the environment is determined based off of production choices over energy inputs. The social planner recognizes this can chooses the level of energy used in production optimally. The FOCs are labeled; the third is the only “not completely common” one - just the shadow price on energy. (I must actually make a correction to it, but the error isn’t what’s preventing the program from running.) The resource constraints are just production = consumption plus investment, the law of motion for the environment, and the law of motion for capital. Thank you again for your time!

%start

periods 100

var c, h, k, ed, S, y;

parameters beta, iota, sigma_c, sigma_s, chi_s, alpha_c, alpha_f,…
eta_h, eta_c, eta_d, sigma_h, sigma_e, theta, delta, zetak,…
zetae, g, gamma, xi, rho, nsigma_e, nsigma_h, nsigma_c,…
nsigma_s, tau_c, tau_x, tau_d, tau_h, tau_k;

%%
%PARAMETERS
beta=.992; %discount rate
iota=.64; %share parameter b/w consumption and nested labor-environment
sigma_c=5.32; %subst b/w consumption and nested labor-environment
sigma_s=1.33; %subst b/w leisure and environmental quality
chi_s=.95; %share of leisure versus environmental quality
alpha_c=.94; %share of general consumption good
alpha_f=.06; %share of family services consumption good
eta_h=.97; %share b/w Cobb Douglas capital-labor and nested CES energy
eta_c=.5; %share parameter for clean energy
eta_d=.5; %share parameter for dirty energy
sigma_h=.02; %subst b/w Cobb Douglas capital-labor and nested CES energy
sigma_e=.02; %subst b/w clean and dirty energy
theta=.33; %share on capital to labor
delta=.0253; %depreciation
zetak=.213; %marginal adjustment costs for capital
zetae=zetak; %convex energy extraction costs
g=.03; %balanced growth
gamma=.001; %pollution parameters, regeneration
xi=.8; rho=.8; %emissions and pollution intensity

%abbreviations
nsigma_e=(sigma_e-1)/sigma_e;
nsigma_h=(sigma_h-1)/sigma_h;
nsigma_c=(sigma_c-1)./sigma_c; %“net” sigma c
nsigma_s=(sigma_s-1)./sigma_s; %net sigma s

%taxes, dummies for now
tau_c=.2; %consumption tax
tau_x=.2; %investment tax
tau_d=.1; %carbon tax
tau_h=.3; %labor income tax
tau_k=.2; %capital income tax

model;

%FOC 1 - Intertemporal Euler equation
(c^(-1/sigma_c))((iota(c^nsigma_c)+(1-iota)(chi_s… %“PSI”
(S^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))^(nsigma_c/nsigma_s))…
^(1/nsigma_c))=beta
(c(1)^(-1/sigma_c))((iota(c(1)^nsigma_c)+…
(1-iota)(chi_s(S(1)^nsigma_s)+(1-chi_s)((1-h(1))^…
nsigma_s))^(nsigma_c/nsigma_s))^(1/nsigma_c))
(eta_h.theta.((h./k).^(1-theta))).(KH.^(-1./sigma_h)).
(eta_h.(KH.^(1./sigma_h))+(1-eta_h).(ed.^(1./sigma_h))));

%FOC 2 - Intratemporal Euler equation
(iota*(c^(-1/sigma_c)))/((1-iota)(1-chi_s)
(h^(-1/sigma_s)).… %note: psi’s cancel out
((chi_s
(1/((eta_h
(1-theta)((k/h)^theta))
(((k^theta)(h.^(1-theta)))^(-1/sigma_h))
(eta_h*(((k^theta)(h.^(1-theta)))^(1/sigma_h))+…
(1-eta_h)
(ed^(1/sigma_h)))));

%FOC 3 - Shadow price on energy
((1-iota)chi_s((chi_s*(S^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))))
((iota*(c^nsigma_c)+(1-iota)(chi_s… %“PSI”
(S^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))^(nsigma_c/nsigma_s))…
^(1/nsigma_c))=(1-eta_h)
(ed^(-1/sigma_h))((eta_h… %MP_energy
(((k^theta)(h^(1-theta)))^nsigma_h)+(1-eta_h)
(ed^nsigma_h))^(1/(sigma_h-1)));

%Resource constraint for production
y=(eta_h.(KH.^nsigma_h).^(1./nsigma_h)+…
(1-eta_h).
(ed.^nsigma_h).^(1./nsigma_h)); %production

%Capital law of motion
k(1)=(1-delta)*k + (y-c); %investment = y-c

%Environmental
S(1)=S*(1+gamma)-ed*(xi+rho);

end;

initval;
k=1;
c=1;
h=.3;
S=1;
ed=1;
y=1;
end;

stoch_simul(dr_algo=0,periods=100); datasaver(‘simudata’,]);
%finish

You cannot use … for breaking around lines. Dynare does this automatically. When the line is not terminated by a semicolon, the line is assumed to continue.

Thank you jpfeifer for your taking the time to look at this – that is an observation I did not make having skimmed the manual; I thought “//” for comments was an alternative to “%” and lines “…”!

I have one final question since the adjustments reveal another flaw in my initial coding. Is it possible to make abbreviations for terms, such as if I want to call (k^theta)*(h^(1-theta)) an aggregate, say, KH? Adding these abbreviations would make catching potential problems in the code much easier. My current problem is that I obtain the error “DYNARE: preprocessing failed”. I have read your comments to two prior posters about this error and it evidently must be a coding mistake. Nevertheless, my code is below in case you are curious. Again, your help is immensely appreciated and I hope to gain sufficient familiarity sooner or later to help others on the forum too!

var c, h, k, ed;

parameters beta, iota, sigma_c, sigma_s, chi_s, alpha_c, alpha_f,
eta_h, eta_c, eta_d, sigma_h, sigma_e, theta, delta, zetak,
zetae, g, gamma, xi, rho, nsigma_e, nsigma_h, nsigma_c,
nsigma_s, tau_c, tau_x, tau_d, tau_h, tau_k;

// PARAMETERS
beta=.992; // discount rate
iota=.64; // share parameter b/w consumption and nested labor-environment
sigma_c=5.32; // subst b/w consumption and nested labor-environment
sigma_s=1.33; // subst b/w leisure and environmental quality
chi_s=.95; // share of leisure versus environmental quality
alpha_c=.94; // share of general consumption good
alpha_f=.06; // share of family services consumption good
eta_h=.97; // share b/w Cobb Douglas capital-labor and nested CES energy
eta_c=.5; // share parameter for clean energy
eta_d=.5; // share parameter for dirty energy
sigma_h=.02; // subst b/w Cobb Douglas capital-labor and nested CES energy
sigma_e=.02; // subst b/w clean and dirty energy
theta=.33; // share on capital to labor
delta=.0253; // depreciation
zetak=.213; // marginal adjustment costs for capital
zetae=zetak; // convex energy extraction costs
g=.03; // balanced growth
gamma=.001; // pollution parameters, regeneration
xi=.8; rho=.8; // emissions and pollution intensity

// abbreviations
nsigma_e=(sigma_e-1)/sigma_e;
nsigma_h=(sigma_h-1)/sigma_h;
nsigma_c=(sigma_c-1)./sigma_c; // “net” sigma c
nsigma_s=(sigma_s-1)./sigma_s; // net sigma s

// taxes, dummies for now
tau_c=.2; // consumption tax
tau_x=.2; // investment tax
tau_d=.1; // carbon tax
tau_h=.3; // labor income tax
tau_k=.2; // capital income tax

model;
/* note: letting S=((ed*(xi+rho)+S(+1))/(1+gamma)) */

// FOC 1 - Intertemporal Euler equation
/* the following contains the the simplified PSI from the paper /
(c^(-1/sigma_c))
((iota*(c^nsigma_c)+(1-iota)(chi_s(((ed*(xi+rho)+S(+1))/(1+gamma))^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))^(nsigma_c/nsigma_s))^(1/nsigma_c))=beta(c(+1)^(-1/sigma_c))((iota(c(+1)^nsigma_c)+(1-iota)(chi_s(((ed(+1)(xi+rho)+S(+2))/(1+gamma))^nsigma_s)+(1-chi_s)((1-h(+1))^nsigma_s))^(nsigma_c/nsigma_s))^(1/nsigma_c))(1+(eta_htheta*((h/k)^(1-theta)))(((k^theta)(h^(1-theta)))^(-1/sigma_h))(eta_h(((k^theta)(h^(1-theta)))^(1/sigma_h))+(1-eta_h)(ed^(1/sigma_h))));

// FOC 2 - Intratemporal Euler equation
/* the following is MU_h = (1/MP_h) /
(iota
(c^(-1/sigma_c)))/((1-iota)(1-chi_s)(h^(-1/sigma_s))=(1/((eta_h*(1-theta)((k/h)^theta))(((k^theta)(h.^(1-theta)))^(-1/sigma_h))(eta_h*(((k^theta)(h.^(1-theta)))^(1/sigma_h))+(1-eta_h)(ed^(1/sigma_h)))));

// FOC 3 - Shadow price on energy
((1-iota)chi_s((chi_s*(((ed*(xi+rho)+S(+1))/(1+gamma))^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))))((iota*(c^nsigma_c)+(1-iota)(chi_s(((ed*(xi+rho)+S(+1))/(1+gamma))^nsigma_s)+(1-chi_s)((1-h)^nsigma_s))^(nsigma_c/nsigma_s))^(1/nsigma_c))=(1-eta_h)(ed^(-1/sigma_h))((eta_h(((k^theta)(h^(1-theta)))^nsigma_h)+(1-eta_h)(ed^nsigma_h))^(1/(sigma_h-1)));

// Capital law of motion
/* k’ = investment + y -c /
k(+1)=(1-delta)k + (eta_h(((k^theta)
(h^(1-theta)))^nsigma_h)^(1/nsigma_h)+(1-eta_h)*(ed^nsigma_h)^(1/nsigma_h)) - c;

end;

initval;
k=1;
c=1;
h=.3;
ed=1;
end;

`sigma_e` is the name of an internal Dynare variable. Please rename it. Also note that elementwise operations (like ./ )are not possible unless you use the verbatim-block.