Skip to content

Commit

Permalink
Created a new 'examples' subdirectory with a (still small) example da…
Browse files Browse the repository at this point in the history
…tabase
  • Loading branch information
Sébastien Villemot committed Apr 30, 2010
1 parent 6ef638a commit 4a619f3
Show file tree
Hide file tree
Showing 9 changed files with 1,005 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ EXTRA_DIST = \
license.txt \
windows/dynare.nsi \
windows/mexopts.bat \
windows/README.txt
windows/README.txt \
examples

dist-hook:
rm -rf `find $(distdir)/matlab -name *~`
rm -rf `find $(distdir)/matlab $(distdir)/examples -name *~`
rm -f $(distdir)/matlab/dynare_m$(EXEEXT) $(distdir)/matlab/dynare_version.m
$(MKDIR_P) $(distdir)/mex/matlab $(distdir)/mex/octave
73 changes: 70 additions & 3 deletions doc/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3995,6 +3995,31 @@ plot_conditional_forecast(periods = 10) e u;

</chapter>

<chapter>
<title>Examples</title>
<para>Dynare comes with a database of example <filename class="extension">.mod</filename> files, which are designed to show a broad range of Dynare features, and are taken from academic papers for most of them. You should have these files in the <filename class="directory">examples</filename> subdirectory of your distribution.</para>
<para>Here is a short list of the examples included. For a more complete description, please refer to the comments inside the files themselves.</para>
<variablelist>
<varlistentry>
<term><filename>ramst.mod</filename></term>
<listitem><para>An elementary real business cycle (RBC) model, simulated in a deterministic setup.</para></listitem>
</varlistentry>
<varlistentry>
<term><filename>example1.mod</filename></term>
<term><filename>example2.mod</filename></term>
<listitem><para>Two examples of a small RBC model in a stochastic setup, presented in <xref linkend="collard_2001"/> (see the file <filename>guide.pdf</filename> which comes with Dynare).</para></listitem>
</varlistentry>
<varlistentry>
<term><filename>fs2000.mod</filename></term>
<listitem><para>A cash in advance model, estimated by <xref linkend="schorfheide_2000"/>.</para></listitem>
</varlistentry>
<varlistentry>
<term><filename>bkk.mod</filename></term>
<listitem><para>Multi-country RBC model with time to build, presented in <xref linkend="backus-kehoe-kydland_1992"/>.</para></listitem>
</varlistentry>
</variablelist>
</chapter>

<bibliography>

<biblioentry id="boucekkine_1995" xreflabel="Boucekkine (1995)">
Expand Down Expand Up @@ -4097,7 +4122,7 @@ plot_conditional_forecast(periods = 10) e u;
</biblioset>
</biblioentry>

<biblioentry>
<biblioentry id="fernandez-villaverde-rubio-ramirez_2004" xreflabel="Fernandez-Villaverde and Rubio-Ramirez (2004)">
<biblioset relation="article">
<authorgroup>
<author>
Expand Down Expand Up @@ -4222,7 +4247,7 @@ plot_conditional_forecast(periods = 10) e u;
</biblioset>
</biblioentry>

<biblioentry>
<biblioentry id="lubik-schorfheide_2007" xreflabel="Lubik and Schorfheide (2007)">
<biblioset relation="article">
<authorgroup>
<author>
Expand Down Expand Up @@ -4289,7 +4314,8 @@ plot_conditional_forecast(periods = 10) e u;
<biblioset relation="journal">
<title>Journal of Applied Econometrics</title>
<volumenum>15</volumenum>
<pagenums>645-70</pagenums>
<issuenum>6</issuenum>
<pagenums>645-670</pagenums>
</biblioset>
</biblioentry>

Expand Down Expand Up @@ -4337,5 +4363,46 @@ plot_conditional_forecast(periods = 10) e u;
</biblioset>
</biblioentry>

<biblioentry id="collard_2001" xreflabel="Collard (2001)">
<biblioset relation="article">
<authorgroup>
<author>
<surname>Collard</surname>
<firstname>Fabrice</firstname>
</author>
</authorgroup>
<pubdate>2001</pubdate>
<title>Stochastic simulations with Dynare: A practical guide</title>
</biblioset>
</biblioentry>

<biblioentry id="backus-kehoe-kydland_1992" xreflabel="Backus, Kehoe and Kydland (1992)">
<biblioset relation="article">
<authorgroup>
<author>
<surname>Backus</surname>
<firstname>David K.</firstname>
</author>
<author>
<surname>Kehoe</surname>
<firstname>Patrick J.</firstname>
</author>
<author>
<surname>Kydland</surname>
<firstname>Finn E.</firstname>
</author>
</authorgroup>
<pubdate>1992</pubdate>
<title>International Real Business Cycles</title>
</biblioset>
<biblioset relation="journal">
<title>Journal of Political Economy</title>
<volumenum>100</volumenum>
<issuenum>4</issuenum>
<pagenums>745-775</pagenums>
</biblioset>

</biblioentry>

</bibliography>
</book>
173 changes: 173 additions & 0 deletions examples/bkk.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
* This file implements the multi-country RBC model with time to build,
* described in Backus, Kehoe and Kydland (1992): "International Real Business
* Cycles", Journal of Political Economy, 100(4), 745-775.
*
* The notation for the variable names are the same in this file than in the paper.
* However the timing convention is different: we had to taken into account the
* fact that in Dynare, if a variable is denoted at the current period, then
* this variable must be also decided at the current period.
* Concretely, here are the differences between the paper and the model file:
* - z_t in the model file is equal to z_{t+1} in the paper
* - k_t in the model file is equal to k_{t+J} in the paper
* - s_t in the model file is equal to s_{J,t}=s_{J-1,t+1}=...=s_{1,t+J-1} in the paper
*
* The macroprocessor is used in this file to create a loop over countries.
* Only two countries are used here (as in the paper), but it is easy to add
* new countries in the corresponding macro-variable and completing the
* calibration.
*
* The calibration is the same than in the paper. The results in terms of
* moments of variables are very close to that of the paper (but not equal
* since the authors a different solution method).
*
* This implementation was written by Sebastien Villemot. Please note that the
* following copyright notice only applies to this Dynare implementation of the
* model.
*/

/*
* Copyright (C) 2010 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/

@#define countries = [ "H", "F" ]
@#define J = 4

@#for co in countries
var C_@{co} L_@{co} N_@{co} A_@{co} K_@{co} Z_@{co} X_@{co} LAMBDA_@{co} S_@{co} NX_@{co} Y_@{co};

varexo E_@{co};

parameters beta_@{co} alpha_@{co} eta_@{co} mu_@{co} gamma_@{co} theta_@{co} nu_@{co} sigma_@{co} delta_@{co} phi_@{co} psi_@{co} rho_@{co}_@{co};
@#endfor

// Lagrange multiplier of aggregate constraint
var LGM;

parameters rho_@{countries[1]}_@{countries[2]} rho_@{countries[2]}_@{countries[1]};

model;
@#for co in countries

Y_@{co} = ((LAMBDA_@{co}*K_@{co}(-@{J})^theta_@{co}*N_@{co}^(1-theta_@{co}))^(-nu_@{co}) + sigma_@{co}*Z_@{co}(-1)^(-nu_@{co}))^(-1/nu_@{co});
K_@{co} = (1-delta_@{co})*K_@{co}(-1) + S_@{co};
X_@{co} =
@# for lag in (-J+1):0
+ phi_@{co}*S_@{co}(@{lag})
@# endfor
;

A_@{co} = (1-eta_@{co})*A_@{co}(-1) + N_@{co};
L_@{co} = 1 - alpha_@{co}*N_@{co} - (1-alpha_@{co})*eta_@{co}*A_@{co}(-1);

// Utility multiplied by gamma
# U_@{co} = (C_@{co}^mu_@{co}*L_@{co}^(1-mu_@{co}))^gamma_@{co};

// FOC with respect to consumption
psi_@{co}*mu_@{co}/C_@{co}*U_@{co} = LGM;

// FOC with respect to labor
// NOTE: this condition is only valid for alpha = 1
psi_@{co}*(1-mu_@{co})/L_@{co}*U_@{co}*(-alpha_@{co}) = - LGM * (1-theta_@{co})/N_@{co}*(LAMBDA_@{co}*K_@{co}(-@{J})^theta_@{co}*N_@{co}^(1-theta_@{co}))^(-nu_@{co})*Y_@{co}^(1+nu_@{co});

// FOC with respect to capital
@# for lag in 0:(J-1)
+beta_@{co}^@{lag}*LGM(+@{lag})*phi_@{co}
@# endfor
@# for lag in 1:J
-beta_@{co}^@{lag}*LGM(+@{lag})*phi_@{co}*(1-delta_@{co})
@# endfor
= beta_@{co}^@{J}*LGM(+@{J})*theta_@{co}/K_@{co}*(LAMBDA_@{co}(+@{J})*K_@{co}^theta_@{co}*N_@{co}(+@{J})^(1-theta_@{co}))^(-nu_@{co})*Y_@{co}(+@{J})^(1+nu_@{co});

// FOC with respect to stock of inventories
LGM=beta_@{co}*LGM(+1)*(1+sigma_@{co}*Z_@{co}^(-nu_@{co}-1)*Y_@{co}(+1)^(1+nu_@{co}));

// Shock process
@# if co == countries[1]
@# define alt_co = countries[2]
@# else
@# define alt_co = countries[1]
@# endif
(LAMBDA_@{co}-1) = rho_@{co}_@{co}*(LAMBDA_@{co}(-1)-1) + rho_@{co}_@{alt_co}*(LAMBDA_@{alt_co}(-1)-1) + E_@{co};


NX_@{co} = (Y_@{co} - (C_@{co} + X_@{co} + Z_@{co} - Z_@{co}(-1)))/Y_@{co};

@#endfor

// World ressource constraint
@#for co in countries
+C_@{co} + X_@{co} + Z_@{co} - Z_@{co}(-1)
@#endfor
=
@#for co in countries
+Y_@{co}
@#endfor
;

end;

@#for co in countries
beta_@{co} = 0.99;
mu_@{co} = 0.34;
gamma_@{co} = -1.0;
alpha_@{co} = 1;
eta_@{co} = 0.5; // Irrelevant when alpha=1
theta_@{co} = 0.36;
nu_@{co} = 3;
sigma_@{co} = 0.01;
delta_@{co} = 0.025;
phi_@{co} = 1/@{J};
psi_@{co} = 0.5;
@#endfor

rho_H_H = 0.906;
rho_F_F = 0.906;
rho_H_F = 0.088;
rho_F_H = 0.088;

initval;
@#for co in countries
LAMBDA_@{co} = 1;
NX_@{co} = 0;
Z_@{co} = 1;
A_@{co} = 1;
L_@{co} = 0.5;
N_@{co} = 0.5;
Y_@{co} = 1;
K_@{co} = 1;
C_@{co} = 1;
S_@{co} = 1;
X_@{co} = 1;

E_@{co} = 0;
@#endfor

LGM = 1;
end;

shocks;
var E_H; stderr 0.00852;
var E_F; stderr 0.00852;
corr E_H, E_F = 0.258;
end;

steady;
check;

stoch_simul(order=1, hp_filter=1600, nograph);
68 changes: 68 additions & 0 deletions examples/example1.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Example 1 from F. Collard (2001): "Stochastic simulations with DYNARE:
* A practical guide" (see "guide.pdf" in the documentation directory).
*/

/*
* Copyright (C) 2001-2010 Dynare Team
*
* This file is part of Dynare.
*
* Dynare is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Dynare is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/


var y, c, k, a, h, b;
varexo e, u;

parameters beta, rho, alpha, delta, theta, psi, tau;

alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;

phi = 0.1;

model;
c*theta*h^(1+psi)=(1-alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
k = exp(b)*(y-c)+(1-delta)*k(-1);
a = rho*a(-1)+tau*b(-1) + e;
b = tau*a(-1)+rho*b(-1) + u;
end;

initval;
y = 1.08068253095672;
c = 0.80359242014163;
h = 0.29175631001732;
k = 11.08360443260358;
a = 0;
b = 0;
e = 0;
u = 0;
end;

shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;

stoch_simul;
Loading

0 comments on commit 4a619f3

Please sign in to comment.