@#define

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.

@#define

Postby marlenemaya » Tue May 09, 2017 9:17 am

Hi, I'm running a simple new keynesian model both under exchange rates and under monetary union. Then I want to plot results of my IRF in the same graph. My code doesn't work. Which is the problem? thank you
Code: Select all
//IN THIS CASE IS CONSIDERED THE CASE WITH SYMMETRY IN PRICE ADJUSTMENT
close all
//QUESTIONE e E variabili che non riesco ad identificare
///////////////////////////////////////////////////////////////////////////
//DEFINITION OF VARIABLES

//@#define monetary_union=0
var p,ss,y,y_f,pp,pp_f,s,mu,mu_f;
varexo eps_mu,eps_muf;
parameters  sigma,zeta, n, sigmas,epsilon,bbeta,theta,theta_f,eta,rho_mu,rho_muf,kappa,kappa_f,ggamma,lambda,lambda_f,yb,yb_f,sb, monetary_union;


theta=0.75;
sigma=1;
zeta=0.67;
n=0.5;
epsilon=7.66;
bbeta=0.99;
theta_f=0.75;
eta=2;
lambda=0.75;
lambda_f=0.75;
rho_mu=0.9;
rho_muf=0.9;
kappa=((1-theta*bbeta)*(1-theta))/(theta*(1+epsilon*zeta));
kappa_f=((1-theta_f*bbeta)*(1-theta_f))/(theta_f*(1+epsilon*zeta));
ggamma=(lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2;
sigmas=((sigma*eta-1)/sigma)*(2-lambda-lambda_f)*ggamma;
//omega=(((lambda+lambda_f)*(2-lambda-lambda_f)*(sigma*eta-1)*(sigma+zeta))/omega)*kappa;
sb=0;
yb=((lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2)/sigma;
yb_f=((lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2)/sigma;
//monetary_union=0;

///////////////////////////////////////////////////////////////////////////
//SPECIFICATION OF THE MODEL



model(linear);
pp=bbeta*pp(+1)+(sigma+zeta)*kappa*(y-yb)-lambda*(2-lambda-lambda_f)*(sigma*eta-1)*kappa*(s-sb)+kappa*mu;
pp_f=bbeta*pp_f(+1)+(sigma+zeta)*kappa_f*(y_f-yb_f)+lambda_f*(2-lambda-lambda_f)*(sigma*eta-1)*kappa_f*(s-sb)+kappa_f*mu_f;//AGGREGATE SUPPLY
ggamma*s=sigma*(y-y_f);
@#ifdef monetary_union
0=(n*(y-yb)+(1-n)*(y_f-yb_f))+epsilon*(n*pp+(1-n)*pp_f);
s-s(-1)=pp_f-pp;
@#else
0=(y-yb)+epsilon*pp;
0=(y_f-yb_f)+epsilon*pp_f;
@#endif
mu=rho_mu*mu(-1)+eps_mu;
mu_f=rho_muf*mu_f(-1)+eps_muf;
p=pp-pp_f;
ss=s-sb;
end;



initval;
mu=0;
mu_f=0;
y=yb;
y_f=yb_f;
pp_f=0;
pp=0;
s=0;
ss=0;
p=0;
end;

//planner_objective(bbeta*(((sigma+zeta)/2)*(n*(y-yb)^2+(1-n)*(y_f-yb_f)^2)-((n*sigmas)/2)*(s-sb)^2+(epsilon/2)*((n/kappa)*pp^2+((1-n)/kappa_f)*pp_f)));
//ramsey_policy(planner_discount=0.99,order=1);
//steady;
//check;






shocks;
var eps_mu=0.1;
var eps_muf=0.1;
end;

stoch_simul(order=1,nodisplay,irf=51);


g=ss_eps_mu;
f=p_eps_mu;


@#define monetary_union=0
steady;
check;
stoch_simul(nodisplay,irf=51);

t=0:50
subplot(2,1,1)
plot(t,ss_eps_mu)
hold on
plot(t,g)
hold all
subplot(2,1,2)
plot(t,p_eps_mu)
hold on
plot(t,f)
hold off
marlenemaya
 
Posts: 19
Joined: Mon Nov 21, 2016 3:56 pm

Re: @#define

Postby jpfeifer » Wed May 10, 2017 1:19 pm

Write the mod-file to take the monetary_union macro flag as an input that is either 0 or 1:
Code: Select all
var p,ss,y,y_f,pp,pp_f,s,mu,mu_f;
varexo eps_mu,eps_muf;
parameters  sigma,zeta, n, sigmas,epsilon,bbeta,theta,theta_f,eta,rho_mu,rho_muf,kappa,kappa_f,ggamma,lambda,lambda_f,yb,yb_f,sb, monetary_union;


theta=0.75;
sigma=1;
zeta=0.67;
n=0.5;
epsilon=7.66;
bbeta=0.99;
theta_f=0.75;
eta=2;
lambda=0.75;
lambda_f=0.75;
rho_mu=0.9;
rho_muf=0.9;
kappa=((1-theta*bbeta)*(1-theta))/(theta*(1+epsilon*zeta));
kappa_f=((1-theta_f*bbeta)*(1-theta_f))/(theta_f*(1+epsilon*zeta));
ggamma=(lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2;
sigmas=((sigma*eta-1)/sigma)*(2-lambda-lambda_f)*ggamma;
//omega=(((lambda+lambda_f)*(2-lambda-lambda_f)*(sigma*eta-1)*(sigma+zeta))/omega)*kappa;
sb=0;
yb=((lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2)/sigma;
yb_f=((lambda+lambda_f)*(2-lambda-lambda_f)*sigma*eta+(1-lambda-lambda_f)^2)/sigma;
//monetary_union=0;

///////////////////////////////////////////////////////////////////////////
//SPECIFICATION OF THE MODEL

model(linear);
pp=bbeta*pp(+1)+(sigma+zeta)*kappa*(y-yb)-lambda*(2-lambda-lambda_f)*(sigma*eta-1)*kappa*(s-sb)+kappa*mu;
pp_f=bbeta*pp_f(+1)+(sigma+zeta)*kappa_f*(y_f-yb_f)+lambda_f*(2-lambda-lambda_f)*(sigma*eta-1)*kappa_f*(s-sb)+kappa_f*mu_f;//AGGREGATE SUPPLY
ggamma*s=sigma*(y-y_f);
@#if monetary_union==0
0=(n*(y-yb)+(1-n)*(y_f-yb_f))+epsilon*(n*pp+(1-n)*pp_f);
s-s(-1)=pp_f-pp;
@#else
0=(y-yb)+epsilon*pp;
0=(y_f-yb_f)+epsilon*pp_f;
@#endif
mu=rho_mu*mu(-1)+eps_mu;
mu_f=rho_muf*mu_f(-1)+eps_muf;
p=pp-pp_f;
ss=s-sb;
end;



initval;
mu=0;
mu_f=0;
y=yb;
y_f=yb_f;
pp_f=0;
pp=0;
s=0;
ss=0;
p=0;
end;


shocks;
var eps_mu=0.1;
var eps_muf=0.1;
end;

stoch_simul(order=1,nodisplay,irf=51);


The run the following script in Matlab:
Code: Select all
%run file with monetary union flag set to 1
dynare NK -Dmonetary_union=0
%store IRFs
g=ss_eps_mu;
f=p_eps_mu;

%run file with monetary union flag set to 0
dynare NK -Dmonetary_union=1 noclearall

%do plot
t=0:50;
subplot(2,1,1)
plot(t,ss_eps_mu)
hold on
plot(t,g)
hold all
subplot(2,1,2)
plot(t,p_eps_mu)
hold on
plot(t,f)
hold off
------------
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: @#define

Postby zhanghuifd » Sat May 20, 2017 12:23 am

Dear friends,
I met the similar problem as the first post.
I code a model as below(simple):
Code: Select all
var ; 
varexo ;
parameters;
@#define high = 1
@#define negative_e3 = 1

%====calib======
@#if high == 1
e1      = 14;
e2      = 8;
@#if negative_e3 == 1
e3      = -6;
@# else
e3      = 6;
@# endif
@# else
e1      = 4;
e2      = 3;
@#if negative_e3 == 1
e3      = -1;
@# else
e3      = 1;
@# endif
@# endif
...
model;
end;
initval;
end;
shocks;
end;
stoch_simul(order = 1,irf = 0);

Then I saved it named pub.mod and ran in matlab as below:
Code: Select all
dynare pub -Dnegative_e3 =0 noclearall

but e3 still returns the same value: -6. When I run dynare pub -Dhigh =0 , it also returns original values for e1, e2.
What's wrong with it? Thanks!
zhanghuifd
 
Posts: 36
Joined: Tue Mar 21, 2017 8:14 am

Re: @#define

Postby jpfeifer » Sat May 20, 2017 7:02 am

You must not have
Code: Select all
@#define high = 1
@#define negative_e3 = 1

in your mod-file. These two statements will override anything you pass on the command line via e.g.
Code: Select all
-Dnegative_e3
------------
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: @#define

Postby zhanghuifd » Sat May 20, 2017 2:54 pm

Thanks for your advice!
But if I want to use two macro flag at the same time, how should I code it?
i.e. high = 1 and negative_e3 =1 .
Sorry, I find little information on it.
Thanks a lot!!!
zhanghuifd
 
Posts: 36
Joined: Tue Mar 21, 2017 8:14 am

Re: @#define

Postby jpfeifer » Sun May 21, 2017 8:07 am

That would be
Code: Select all
dynare pub -Dnegative_e3=1  -Dhigh=1 noclearall
------------
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: @#define

Postby zhanghuifd » Sun May 21, 2017 9:40 am

Hi, so much thanks for your help!
zhanghuifd
 
Posts: 36
Joined: Tue Mar 21, 2017 8:14 am


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 8 guests