\item The \textbf{Dynare macro language} adds a programmatic element to Dynare
\begin{itemize}
\item Introduces conditionals, loops, and other simple programmatic directives
\item Used to speed model development
\item Used to speed up model development
\item Useful in various situations
\begin{itemize}
\item Multi-country models
...
...
@@ -132,6 +133,7 @@
\item loop statements: \verb+@#for/@#endfor+
\end{itemize}
\item Most directives fit on one line. If needed however, two backslashes (i.e. \verb+\\+) at the end of a line indicate that the directive is continued on the next line.
\item Directives are not terminated with a semicolon
\end{itemize}
\end{frame}
...
...
@@ -139,13 +141,13 @@
\frametitle{Values}
\begin{itemize}
\item The macro processor can handle values of 5 different types:
\begin{itemize}
\begin{enumerate}
\item boolean
\item real
\item string
\item tuple
\item array
\end{itemize}
\end{enumerate}
\item Values of the types listed above can be cast to other types
\item Macro-expressions are constructed using literals of the 5 basic types
\item Macro-expressions are constructed using literals (i.e.\ fixed values) of the 5 basic types
described above, macro-variables, standard operators, function calls and comprehensions.
\item Macro-expressions can be used in two places:
\begin{itemize}
\item inside macro directives; no special markup is required
\item in the body of the \texttt{.mod} file, between an at sign and curly braces (like \verb+@{expr}+); the macro processor will substitute the expression with its value
\item in the body of the \texttt{.mod} file, between an ``at''-sign and curly braces (like \verb+@{expr}+); the macro processor will substitute the expression with its value
\end{itemize}
\end{itemize}
\end{frame}
...
...
@@ -223,7 +225,7 @@
\begin{frame}[fragile=singleslide]
\frametitle{Macro-expressions (5/8): Tuple}
Tuples are enclosed by parenthesis and elements separated by commas (like
Tuples are enclosed by parentheses and elements are separated by commas (like
\texttt{(a,b,c)} or \texttt{(1,2.2,c)}).
\begin{block}{Operators on tuples}
\begin{itemize}
...
...
@@ -256,7 +258,7 @@
\frametitle{Macro-expressions (6/8): Array (2/2)}
Arrays can be seen as representing a set of elements (assuming no element
appears twice in the array). Several set operations can thus be performed on
arrays: union, intersection, difference, cartesian product and power.
arrays: union, intersection, difference, Cartesian product and power.
\begin{block}{Set operations on arrays}
\begin{itemize}
\item set union: \texttt{|}
...
...
@@ -266,7 +268,7 @@
\item Cartesian power of an array: \texttt{\^}
\end{itemize}
\end{block}
For example, if \texttt{A} and \texttt{B} are arrays, then the following
For example: if \texttt{A} and \texttt{B} are arrays, then the following
set operations are valid: \texttt{A|B}, \texttt{A\&B}, \texttt{A-B},
\texttt{A*B}, \texttt{A\^{}3}.
\end{frame}
...
...
@@ -329,7 +331,7 @@
\frametitle{Macro-expressions (8/8): Functions}
\begin{itemize}
\item Can take any number of arguments
\item Dynamic binding: is evaluated when invoked, not when defined
\item Dynamic binding: is evaluated when invoked during the macroprocessing stage, not when defined
\item Can be included in expressions; valid operators depend on return type
\end{itemize}
...
...
@@ -352,7 +354,7 @@ Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
The value of a macro-variable can be defined with the \verb+@#define+
directive.
The macro processor has its own list of variables which are different from model variables and MATLAB/Octave variables
The macro processor has its own list of variables, which are different from model variables and MATLAB/Octave variables
@@ -368,7 +370,7 @@ Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
@#define t = ("US" in w) // Equals true
\end{verbatim}
\end{block}
NB: You can define macro variables on the dynare command line by using the \texttt{-D} option
NB: You can define macro variables on the Dynare command line by using the \texttt{-D} option
\end{frame}
\begin{frame}[fragile=singleslide]
...
...
@@ -427,7 +429,7 @@ end;
\item Files to include are searched for in the current directory. Other directories can
be added with the
\verb+@#includepath+ directive, the \texttt{-I} command line option, or the
\texttt{[paths]} section in config file.
\texttt{[paths]} section in config files.
\end{itemize}
\end{frame}
...
...
@@ -539,6 +541,7 @@ This loop will iterate over only 4 triplets: \texttt{(3,4,5)},
\begin{frame}[fragile=singleslide]
\frametitle{Conditional directives (2/3)}
\begin{block}{Syntax 3}
\scriptsize
\verb+@#if +\textit{bool\_or\_real\_expr1}\\
\verb++\textit{body included if expr1 is true (or != 0)}\\
\verb+@#elseif +\textit{bool\_or\_real\_expr2}\\
...
...
@@ -588,26 +591,27 @@ end;
\end{columns}
\bigskip
There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
(\textit{i.e.} it tests whether a variable is \emph{not} defined). NB: There is
\begin{itemize}
\item There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
(\textit{i.e.} it tests whether a variable is \emph{not} defined).
\item NB: There is
\emph{no}\verb+@#elseifdef+ or \verb+@#elseifndef+ directive; use
\verb+elseif defined(variable_name)+ to achieve the desired objective.
\end{itemize}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Echo and error directives}
\frametitle{Echo directives}
\begin{itemize}
\item The echo directive will simply display a message on standard output
\item The error directive will display the message and make Dynare stop (only makes sense inside a conditional directive)
\item The echomacrovars directive will display all of the macro variables (or
those specified) and their values, optionally saving them
those specified) and their values
\item The \texttt{save} option allows saving this information to \texttt{options\_.macrovars\_line\_x}, where \texttt{x} denotes the line number where the statement was encountered
@@ -617,6 +621,23 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\begin{block}{Examples}
\begin{verbatim}
@#echo "Information message."
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile=singleslide]
\frametitle{Error directive}
\begin{itemize}
\item The error directive will display the message and make Dynare stop (only makes sense inside a conditional directive)
\end{itemize}
\begin{block}{Syntax}
\verb+@#error +\textit{string\_expr}\\
\end{block}
\begin{block}{Example}
\begin{verbatim}
@#error "Error message!"
\end{verbatim}
\end{block}
...
...
@@ -626,8 +647,8 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\frametitle{Macro-related command line options}
\begin{itemize}
\item\texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file-macroexp.mod}.
\item\texttt{nolinemacro}: In the output of \texttt{savemacro}, don't print line numbers where the macro directives were placed.
\item\texttt{noemptylinemacro}: Remove empty lines in the output of \texttt{savemacro}.
\itemNB: \texttt{savemacro=filename} allows a user-defined file name
\item\texttt{linemacro}: In the output of \texttt{savemacro}, print line numbers where the macro directives were placed.
\item\texttt{onlymacro}: Stops processing after the macro processing step.
\end{itemize}
\end{frame}
...
...
@@ -640,13 +661,13 @@ There is also \verb+@#ifndef+, which is the opposite of \verb+@#ifdef+
\item The \verb+@#include+ directive can be used to split \texttt{.mod} files into several modular components
\item Example setup:
\begin{description}
\item[\texttt{modeldesc.mod}:] contains variable declarations, model equations and shocks declarations
\item[\texttt{simulate.mod}:] includes \texttt{modeldesc.mod}, calibrates parameters and runs stochastic simulations
\item[\texttt{estim.mod}:] includes \texttt{modeldesc.mod}, declares priors on parameters and runs bayesian estimation
\item[\texttt{modeldesc.mod}:] contains variable declarations, model equations, and shock declarations
\item[\texttt{simulate.mod}:] includes \texttt{modeldesc.mod}, calibrates parameters, and runs stochastic simulations
\item[\texttt{estim.mod}:] includes \texttt{modeldesc.mod}, declares priors on parameters, and runs Bayesian estimation
\end{description}
\item Dynare can be called on \texttt{simulate.mod} and \texttt{estim.mod}
\item But it makes no sense to run it on \texttt{modeldesc.mod}
\item Advantage: no need to manually copy/paste the whole model (at the beginning) or changes to the model (during development)
\item Advantage: no need to manually copy/paste the whole model (during initial development) or port model changes (during development)
\end{itemize}
\end{frame}
...
...
@@ -725,18 +746,18 @@ end;
\begin{frame}
\frametitle{Endogeneizing parameters (1/4)}
\begin{itemize}
\item When calibrating the model it may be useful to consider a parameter as an endogenous (and vice-versa)
\item When calibrating the model, it may be useful to pin down parameters by targeting endogenous objects
\item Example:
\begin{gather*}
y = \left(\alpha^{\frac{1}{\xi}}\ell^{1-\frac{1}{\xi}} + (1-\alpha)^{\frac{1}{\xi}}k^{1-\frac{1}{\xi}}\right)^{\frac{\xi}{\xi - 1}}\\
\item In the model, $\alpha$ is a (share) parameter, and $lab\_rat$ is an endogenous variable
\item In the model, $\alpha$ is a (share) parameter, and $lab\_rat_t$ is an endogenous variable
\item We observe that:
\begin{itemize}
\itemcalibrating$\alpha$ is not straigthforward!
\itemon the contrary, we have real world data for $lab\_rat$
\item it is clear that these two variables are economically linked
\itemsetting a value for$\alpha$ is not straightforward!
\itembut we have real world data for $lab\_rat_t$
\item it is clear that these two objects are economically linked
\end{itemize}
\end{itemize}
\end{frame}
...
...
@@ -744,13 +765,13 @@ end;
\begin{frame}[fragile=singleslide]
\frametitle{Endogeneizing parameters (2/4)}
\begin{itemize}
\item Therefore, when computing the steady state:
\item Therefore, when computing the steady state by solving the static model:
\begin{itemize}
\item we make $\alpha$ an endogenous variable and $lab\_rat$ a parameter
\item we impose an economically relevant value for $lab\_rat$
\item we make $\alpha$ a variable and the steady state value $lab\_rat$ of the dynamic variable $lab\_rat_t$ a parameter
\item we impose an economically sensible value for $lab\_rat$
\item the solution algorithm deduces the implied value for $\alpha$
\end{itemize}
\item We call this method ``variable flipping''
\item We call this method ``variable flipping'', because it treats $\alpha$ as a variable and $lab\_rat$ as a parameter for the purpose of the static model