From 306f9f62eebd5e66f96ed356cf3a1575b7d8a3f3 Mon Sep 17 00:00:00 2001 From: "Documenter.jl" Date: Thu, 28 Mar 2024 16:50:06 +0000 Subject: [PATCH] build based on 98d0992 --- dev/.documenter-siteinfo.json | 2 +- dev/index.html | 2 +- dev/installation-and-configuration/index.html | 4 ++-- dev/macroprocessor/index.html | 4 ++-- .../deterministic-simulations/index.html | 6 +++--- dev/model-file/estimation/index.html | 10 +++++----- dev/model-file/filtersmoother/index.html | 4 ++-- dev/model-file/forecasting/index.html | 4 ++-- dev/model-file/local-approxiation/index.html | 6 +++--- dev/model-file/model-declaration/index.html | 4 ++-- dev/model-file/reporting/index.html | 2 ++ dev/model-file/shocks/index.html | 6 +++--- dev/model-file/steady-state/index.html | 6 +++--- dev/model-file/syntax-elements/index.html | 4 ++-- .../variable-declarations/index.html | 4 ++-- dev/objects.inv | Bin 1836 -> 1904 bytes dev/running-dynare/index.html | 4 ++-- dev/search_index.js | 2 +- 18 files changed, 38 insertions(+), 36 deletions(-) create mode 100644 dev/model-file/reporting/index.html diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index a795ebc..c34642d 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.9.4","generation_timestamp":"2024-03-25T13:58:28","documenter_version":"1.3.0"}} \ No newline at end of file +{"documenter":{"julia_version":"1.9.4","generation_timestamp":"2024-03-28T16:50:03","documenter_version":"1.3.0"}} \ No newline at end of file diff --git a/dev/index.html b/dev/index.html index 4a9c727..ebba2fd 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Home · Dynare.jl

The Dynare Julia Reference Manual

Introduction

DynareJulia is a rewriting of Dynare (https://www.dynare.org) that was initially written in Gauss in 1994 and rewritten in Matlab around 2000.

Dynare provides several algorithms to work with Dynamic Stochastic General Equilibrium (DSGE) models often used in macroeconomics. Among other features, it helps

  • solving such models,
  • simulating them,
  • estimating the parameters,
  • making forecasts.

The user of the package writes a text file, usually with an .mod extension, that contains the equations of the model and the computation tasks. Then, DynareJulia compiles the model and runs the computations.

DynareJulia honors a subset of commands valid in DynareMatlab. Tell us if one of your favorite command or option is missing.

For many computing tasks, DynareJulia provides also Julia functions that can be used in the *.mod file or issued interactively after having run the *.mod file. These Julia functions use keyword arguments for the options and you need only to enter them if you want to change the default value. The keyword arguments without a default value are required arguments. In the sections of this documentation, the Dynare Commands are presented first, then the Julia functions.

Dynare has benefited from many contributions over the years. Here is a list of the contributors:

The Dynare Team

Currently the development team of Dynare is composed of:

  • Stéphane Adjemian (Le Mans Université, Gains)
  • Michel Juillard (Banque de France)
  • Sumudu Kankanamge (Toulouse School of Economics and CEPREMAP)
  • Frédéric Karamé (Le Mans Université, Gains and CEPREMAP)
  • Junior Maih (Norges Bank)
  • Willi Mutschler (University of Tübingen)
  • Johannes Pfeifer (Universität der Bundeswehr München)
  • Marco Ratto (European Commission, Joint Research Centre - JRC)
  • Normann Rion (CY Cergy Paris Université and CEPREMAP)
  • Sébastien Villemot (CEPREMAP)

The following people contribute or have contributed to DynareJulia

  • Satyanarayana Bade
  • Petre Caraiani
  • Lilith Hafner
  • Michel Juillard
  • Félix Ordoñez
  • Louis Ponet
  • Rohit Singh Rathaur
  • Dawie van Lill

The following people used to be members of the Dynare team:

  • Houtan Bastani
  • Abdeljabar Benzougar
  • Alejandro Buesa
  • Fabrice Collard
  • Assia Ezzeroug
  • Dóra Kocsis
  • Stéphane Lhuissier
  • Ferhat Mihoubi
  • George Perendia

Copyright © 1996-2023, Dynare Team.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license can be found at https://www.gnu.org/licenses/fdl.txt.

+Home · Dynare.jl

The Dynare Julia Reference Manual

Introduction

DynareJulia is a rewriting of Dynare (https://www.dynare.org) that was initially written in Gauss in 1994 and rewritten in Matlab around 2000.

Dynare provides several algorithms to work with Dynamic Stochastic General Equilibrium (DSGE) models often used in macroeconomics. Among other features, it helps

  • solving such models,
  • simulating them,
  • estimating the parameters,
  • making forecasts.

The user of the package writes a text file, usually with an .mod extension, that contains the equations of the model and the computation tasks. Then, DynareJulia compiles the model and runs the computations.

DynareJulia honors a subset of commands valid in DynareMatlab. Tell us if one of your favorite command or option is missing.

For many computing tasks, DynareJulia provides also Julia functions that can be used in the *.mod file or issued interactively after having run the *.mod file. These Julia functions use keyword arguments for the options and you need only to enter them if you want to change the default value. The keyword arguments without a default value are required arguments. In the sections of this documentation, the Dynare Commands are presented first, then the Julia functions.

Dynare has benefited from many contributions over the years. Here is a list of the contributors:

The Dynare Team

Currently the development team of Dynare is composed of:

  • Stéphane Adjemian (Le Mans Université, Gains)
  • Michel Juillard (Banque de France)
  • Sumudu Kankanamge (Toulouse School of Economics and CEPREMAP)
  • Frédéric Karamé (Le Mans Université, Gains and CEPREMAP)
  • Junior Maih (Norges Bank)
  • Willi Mutschler (University of Tübingen)
  • Johannes Pfeifer (Universität der Bundeswehr München)
  • Marco Ratto (European Commission, Joint Research Centre - JRC)
  • Normann Rion (CY Cergy Paris Université and CEPREMAP)
  • Sébastien Villemot (CEPREMAP)

The following people contribute or have contributed to DynareJulia

  • Satyanarayana Bade
  • Petre Caraiani
  • Lilith Hafner
  • Michel Juillard
  • Félix Ordoñez
  • Louis Ponet
  • Rohit Singh Rathaur
  • Dawie van Lill

The following people used to be members of the Dynare team:

  • Houtan Bastani
  • Abdeljabar Benzougar
  • Alejandro Buesa
  • Fabrice Collard
  • Assia Ezzeroug
  • Dóra Kocsis
  • Stéphane Lhuissier
  • Ferhat Mihoubi
  • George Perendia

Copyright © 1996-2023, Dynare Team.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license can be found at https://www.gnu.org/licenses/fdl.txt.

diff --git a/dev/installation-and-configuration/index.html b/dev/installation-and-configuration/index.html index 3497ad2..cc1e7c3 100644 --- a/dev/installation-and-configuration/index.html +++ b/dev/installation-and-configuration/index.html @@ -1,3 +1,3 @@ -Installation and Configuration · Dynare.jl

Installation and configuration

Software requirements

Dynare is available for all plateforms supported by the current stable version of Julia (https://julialang.org/downloads/#supported_platforms). It should also work with older versions of Julia starting with version 1.6.3

Installation of Dynare

In Julia, install the Dynare.jl package:

using Pkg
-pkg"add Dynare"

Using Dynare

In order to start using Dynare in Julia, type

using Dynare

Optional extensions

Pardiso

If you want the solution of very large perfect foresight models and reduce the memory consumption, use the Pardiso package (https://github.com/JuliaSparse/Pardiso.jl) and type

using MKL, Pardiso

PATHSolver

If youw want to solve perfect foresight models with occasionally binding constraints use the PATHSolver package (https://github.com/chkwon/PATHSolver.jl) and type

using PATHSolver
+Installation and Configuration · Dynare.jl

Installation and configuration

Software requirements

Dynare is available for all plateforms supported by the current stable version of Julia (https://julialang.org/downloads/#supported_platforms). It should also work with older versions of Julia starting with version 1.6.3

Installation of Dynare

In Julia, install the Dynare.jl package:

using Pkg
+pkg"add Dynare"

Using Dynare

In order to start using Dynare in Julia, type

using Dynare

Optional extensions

Pardiso

If you want the solution of very large perfect foresight models and reduce the memory consumption, use the Pardiso package (https://github.com/JuliaSparse/Pardiso.jl) and type

using MKL, Pardiso

PATHSolver

If youw want to solve perfect foresight models with occasionally binding constraints use the PATHSolver package (https://github.com/chkwon/PATHSolver.jl) and type

using PATHSolver
diff --git a/dev/macroprocessor/index.html b/dev/macroprocessor/index.html index bb76100..60b5a62 100644 --- a/dev/macroprocessor/index.html +++ b/dev/macroprocessor/index.html @@ -1,5 +1,5 @@ -Macroprocessing language · Dynare.jl

Macro processing language

It is possible to use "macro" commands in the .mod file for performing tasks such as: including modular source files, replicating blocks of equations through loops, conditionally executing some code, writing indexed sums or products inside equations...

The Dynare macro-language provides a new set of macro-commands which can be used in .mod files. It features:

  • File inclusion
  • Loops (for structure)
  • Conditional inclusion (if/then/else structures)
  • Expression substitution

This macro-language is totally independent of the basic Dynare language, and is processed by a separate component of the Dynare pre-processor. The macro processor transforms a .mod file with macros into a .mod file without macros (doing expansions/inclusions), and then feeds it to the Dynare parser. The key point to understand is that the macro processor only does text substitution (like the C preprocessor or the PHP language). Note that it is possible to see the output of the macro processor by using the savemacro option of the dynare command (see dyn-invoc).

The macro processor is invoked by placing macro directives in the .mod file. Directives begin with an at-sign followed by a pound sign (@#). They produce no output, but give instructions to the macro processor. In most cases, directives occupy exactly one line of text. If needed, two backslashes (\\) at the end of the line indicate that the directive is continued on the next line. Macro directives following // are not interpreted by the macro processor. For historical reasons, directives in commented blocks, ie surrounded by /* and */, are interpreted by the macro processor. The user should not rely on this behavior. The main directives are:

  • @#includepath, paths to search for files that are to be included,
  • @#include, for file inclusion,
  • @#define, for defining a macro processor variable,
  • @#if, @#ifdef, @#ifndef, @#elseif, @#else, @#endif for conditional statements,
  • @#for, @#endfor for constructing loops.

The macro processor maintains its own list of variables (distinct from model variables and Julia variables). These macro-variables are assigned using the @#define directive and can be of the following basic types: boolean, real, string, tuple, function, and array (of any of the previous types).

Macro expressions

Macro-expressions can be used in two places:

  • Inside macro directives, directly;
  • In the body of the .mod file, between an at-sign and curly braces: the macro processor will substitute the expression with its value

It is possible to construct macro-expressions that can be assigned to macro-variables or used within a macro-directive. The expressions are constructed using literals of the basic types (boolean, real, string, tuple, array), comprehensions, macro-variables, macro-functions, and standard operators.

Note

Elsewhere in the manual, MACRO_EXPRESSION designates an expression constructed as explained in this section.

Boolean

The following operators can be used on booleans:

  • Comparison operators: ==, !=
  • Logical operators: &&, ||, !

Real

The following operators can be used on reals:

  • Arithmetic operators: +, -, *, /, ^

  • Comparison operators: <, >, <=, >=, ==, !=

  • Logical operators: &&, ||, !

  • Ranges with an increment of 1: REAL1:REAL2 (for example, 1:4 is equivalent to real array [1, 2, 3, 4]).

    4.6 Previously, putting brackets around the arguments to the colon operator (e.g. [1:4]) had no effect. Now, [1:4] will create an array containing an array (i.e. [ [1, 2, 3, 4] ]).

  • Ranges with user-defined increment: REAL1:REAL2:REAL3 (for example, 6:-2.1:-1 is equivalent to real array [6, 3.9, 1.8, -0.3]).

  • Functions: max, min, mod, exp, log, log10, sin, cos, tan, asin, acos, atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma, round, normpdf, normcdf. NB ln can be used instead of log

String

String literals have to be enclosed by double quotes (like "name").

The following operators can be used on strings:

  • Comparison operators: <, >, <=, >=, ==, !=
  • Concatenation of two strings: +
  • Extraction of substrings: if s is a string, then s[3] is a string containing only the third character of s, and s[4:6] contains the characters from 4th to 6th
  • Function: length

Tuple

Tuples are enclosed by parenthesis and elements separated by commas (like (a,b,c) or (1,2,3)).

The following operators can be used on tuples:

  • Comparison operators: ==, !=
  • Functions: empty, length

Array

Arrays are enclosed by brackets, and their elements are separated by commas (like [1,[2,3],4] or ["US", "FR"]).

The following operators can be used on arrays:

  • Comparison operators: ==, !=
  • Dereferencing: if v is an array, then v[2] is its 2nd element
  • Concatenation of two arrays: +
  • Set union of two arrays: |
  • Set intersection of two arrays: &
  • Difference -: returns the first operand from which the elements of the second operand have been removed.
  • Cartesian product of two arrays: *
  • Cartesian product of one array N times: ^N
  • Extraction of sub-arrays: e.g. v[4:6]
  • Testing membership of an array: in operator (for example: "b" in ["a", "b", "c"] returns 1)
  • Functions: empty, sum, length

Comprehension

Comprehension syntax is a shorthand way to make arrays from other arrays. There are three different ways the comprehension syntax can be employed: [filtering], [mapping], and [filtering and mapping].

Filtering

Filtering allows one to choose those elements from an array for which a certain condition hold.

Example

Create a new array, choosing the even numbers from the array 1:5:

     [ i in 1:5 when mod(i,2) == 0 ]

would result in:

   [2, 4]

Mapping

Mapping allows you to apply a transformation to every element of an array.

Example

Create a new array, squaring all elements of the array 1:5:

   [ i^2 for i in 1:5 ]

would result in:

    [1, 4, 9, 16, 25]

Filtering and Mapping

Combining the two preceding ideas would allow one to apply a transformation to every selected element of an array.

Example

Create a new array, squaring all even elements of the array 1:5:

   [ i^2 for i in 1:5 when mod(i,2) == 0]

would result in:

    [4, 16]

Further Examples :

   [ (j, i+1) for (i,j) in (1:2)^2 ]
+Macroprocessing language · Dynare.jl

Macro processing language

It is possible to use "macro" commands in the .mod file for performing tasks such as: including modular source files, replicating blocks of equations through loops, conditionally executing some code, writing indexed sums or products inside equations...

The Dynare macro-language provides a new set of macro-commands which can be used in .mod files. It features:

  • File inclusion
  • Loops (for structure)
  • Conditional inclusion (if/then/else structures)
  • Expression substitution

This macro-language is totally independent of the basic Dynare language, and is processed by a separate component of the Dynare pre-processor. The macro processor transforms a .mod file with macros into a .mod file without macros (doing expansions/inclusions), and then feeds it to the Dynare parser. The key point to understand is that the macro processor only does text substitution (like the C preprocessor or the PHP language). Note that it is possible to see the output of the macro processor by using the savemacro option of the dynare command (see dyn-invoc).

The macro processor is invoked by placing macro directives in the .mod file. Directives begin with an at-sign followed by a pound sign (@#). They produce no output, but give instructions to the macro processor. In most cases, directives occupy exactly one line of text. If needed, two backslashes (\\) at the end of the line indicate that the directive is continued on the next line. Macro directives following // are not interpreted by the macro processor. For historical reasons, directives in commented blocks, ie surrounded by /* and */, are interpreted by the macro processor. The user should not rely on this behavior. The main directives are:

  • @#includepath, paths to search for files that are to be included,
  • @#include, for file inclusion,
  • @#define, for defining a macro processor variable,
  • @#if, @#ifdef, @#ifndef, @#elseif, @#else, @#endif for conditional statements,
  • @#for, @#endfor for constructing loops.

The macro processor maintains its own list of variables (distinct from model variables and Julia variables). These macro-variables are assigned using the @#define directive and can be of the following basic types: boolean, real, string, tuple, function, and array (of any of the previous types).

Macro expressions

Macro-expressions can be used in two places:

  • Inside macro directives, directly;
  • In the body of the .mod file, between an at-sign and curly braces: the macro processor will substitute the expression with its value

It is possible to construct macro-expressions that can be assigned to macro-variables or used within a macro-directive. The expressions are constructed using literals of the basic types (boolean, real, string, tuple, array), comprehensions, macro-variables, macro-functions, and standard operators.

Note

Elsewhere in the manual, MACRO_EXPRESSION designates an expression constructed as explained in this section.

Boolean

The following operators can be used on booleans:

  • Comparison operators: ==, !=
  • Logical operators: &&, ||, !

Real

The following operators can be used on reals:

  • Arithmetic operators: +, -, *, /, ^

  • Comparison operators: <, >, <=, >=, ==, !=

  • Logical operators: &&, ||, !

  • Ranges with an increment of 1: REAL1:REAL2 (for example, 1:4 is equivalent to real array [1, 2, 3, 4]).

    4.6 Previously, putting brackets around the arguments to the colon operator (e.g. [1:4]) had no effect. Now, [1:4] will create an array containing an array (i.e. [ [1, 2, 3, 4] ]).

  • Ranges with user-defined increment: REAL1:REAL2:REAL3 (for example, 6:-2.1:-1 is equivalent to real array [6, 3.9, 1.8, -0.3]).

  • Functions: max, min, mod, exp, log, log10, sin, cos, tan, asin, acos, atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma, round, normpdf, normcdf. NB ln can be used instead of log

String

String literals have to be enclosed by double quotes (like "name").

The following operators can be used on strings:

  • Comparison operators: <, >, <=, >=, ==, !=
  • Concatenation of two strings: +
  • Extraction of substrings: if s is a string, then s[3] is a string containing only the third character of s, and s[4:6] contains the characters from 4th to 6th
  • Function: length

Tuple

Tuples are enclosed by parenthesis and elements separated by commas (like (a,b,c) or (1,2,3)).

The following operators can be used on tuples:

  • Comparison operators: ==, !=
  • Functions: empty, length

Array

Arrays are enclosed by brackets, and their elements are separated by commas (like [1,[2,3],4] or ["US", "FR"]).

The following operators can be used on arrays:

  • Comparison operators: ==, !=
  • Dereferencing: if v is an array, then v[2] is its 2nd element
  • Concatenation of two arrays: +
  • Set union of two arrays: |
  • Set intersection of two arrays: &
  • Difference -: returns the first operand from which the elements of the second operand have been removed.
  • Cartesian product of two arrays: *
  • Cartesian product of one array N times: ^N
  • Extraction of sub-arrays: e.g. v[4:6]
  • Testing membership of an array: in operator (for example: "b" in ["a", "b", "c"] returns 1)
  • Functions: empty, sum, length

Comprehension

Comprehension syntax is a shorthand way to make arrays from other arrays. There are three different ways the comprehension syntax can be employed: [filtering], [mapping], and [filtering and mapping].

Filtering

Filtering allows one to choose those elements from an array for which a certain condition hold.

Example

Create a new array, choosing the even numbers from the array 1:5:

     [ i in 1:5 when mod(i,2) == 0 ]

would result in:

   [2, 4]

Mapping

Mapping allows you to apply a transformation to every element of an array.

Example

Create a new array, squaring all elements of the array 1:5:

   [ i^2 for i in 1:5 ]

would result in:

    [1, 4, 9, 16, 25]

Filtering and Mapping

Combining the two preceding ideas would allow one to apply a transformation to every selected element of an array.

Example

Create a new array, squaring all even elements of the array 1:5:

   [ i^2 for i in 1:5 when mod(i,2) == 0]

would result in:

    [4, 16]

Further Examples :

   [ (j, i+1) for (i,j) in (1:2)^2 ]
    [ (j, i+1) for (i,j) in (1:2)*(1:2) when i < j ]

would result in:

     [(1, 2), (2, 2), (1, 3), (2, 3)]
      [(2, 2)]

Function

Functions can be defined in the macro processor using the @#define directive (see below). A function is evaluated at the time it is invoked, not at define time. Functions can be included in expressions and the operators that can be combined with them depend on their return type.

Checking variable type

Given a variable name or literal, you can check the type it evaluates to using the following functions: isboolean, isreal, isstring, istuple, and isarray.

Examples

CodeOutput
isboolean(0)false
isboolean(true)true
isreal("str")false

Casting between types

Variables and literals of one type can be cast into another type. Some type changes are straightforward (e.g. changing a [real]{.title-ref} to a [string]{.title-ref}) whereas others have certain requirements (e.g. to cast an [array]{.title-ref} to a [real]{.title-ref} it must be a one element array containing a type that can be cast to [real]{.title-ref}).

Examples

CodeOutput
(bool) -1.1true
(bool) 0false
(real) "2.2"2.2
(tuple) [3.3](3.3)
(array) 4.4[4.4]
(real) [5.5]5.5
(real) [6.6, 7.7]error
(real) "8.8 in a string"error

Casts can be used in expressions:

Examples

CodeOutput
(bool) 0 && truefalse
(real) "1" + 23
(string) (3 + 4)"7"
(array) 5 + (array) 6[5, 6]

Macro directives

Macro Directive: @#includepath "PATH"

Macro Directive @#includepath MACRO_EXPRESSION

This directive adds the path contained in PATH to the list of those to search when looking for a .mod file specified by @#include. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that these paths are added after any paths passed using -I <-I\<\<path\>\>>{.interpreted-text role="opt"}.

Example

     @#includepath "/path/to/folder/containing/modfiles"
      @#includepath folders_containing_mod_files

Macro Directive: @#include "FILENAME"

Macro Directive: @#include MACRO_EXPRESSION

This directive simply includes the content of another file in its place; it is exactly equivalent to a copy/paste of the content of the included file. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that it is possible to nest includes (i.e. to include a file from an included file). The file will be searched for in the current directory. If it is not found, the file will be searched for in the folders provided by -I <-I\<\<path\>\>>{.interpreted-text role="opt"} and @#includepath.

Example

     @#include "modelcomponent.mod"
@@ -145,4 +145,4 @@
      % Anything contained in this block will be passed
      % directly to the <modfile>.m file, including comments
      var = 1;
-     end;

Misc commands

Command: `saveparamsandsteadystate (FILENAME);

For all parameters, endogenous and exogenous variables, stores their value in a text file, using a simple name/value associative table.

  • for parameters, the value is taken from the last parameter initialization.
  • for exogenous, the value is taken from the last initval block.
  • for endogenous, the value is taken from the last steady state computation (or, if no steady state has been computed, from the last initval block).

Note that no variable type is stored in the file, so that the values can be reloaded with load_params_and_steady_state in a setup where the variable types are different.

The typical usage of this function is to compute the steady-state of a model by calibrating the steady-state value of some endogenous variables (which implies that some parameters must be endogeneized during the steady-state computation).

You would then write a first .mod file which computes the steady state and saves the result of the computation at the end of the file, using save_params_and_steady_state.

In a second file designed to perform the actual simulations, you would use load_params_and_steady_state just after your variable declarations, in order to load the steady state previously computed (including the parameters which had been endogeneized during the steady state computation).

The need for two separate .mod files arises from the fact that the variable declarations differ between the files for steady state calibration and for simulation (the set of endogenous and parameters differ between the two); this leads to different var and parameters statements.

Also note that you can take advantage of the @#include directive to share the model equations between the two files (see macro-proc-lang).

  • load_params_and_steady_state (FILENAME);

For all parameters, endogenous and exogenous variables, loads their value from a file created with save_params_and_steady_state.

  • for parameters, their value will be initialized as if they had been calibrated in the .mod file.
  • for endogenous and exogenous variables, their value will be initialized as they would have been from an initval block .

This function is used in conjunction with save_params_and_steady_state; see the documentation of that function for more information.

+ end;

Misc commands

Command: `saveparamsandsteadystate (FILENAME);

For all parameters, endogenous and exogenous variables, stores their value in a text file, using a simple name/value associative table.

  • for parameters, the value is taken from the last parameter initialization.
  • for exogenous, the value is taken from the last initval block.
  • for endogenous, the value is taken from the last steady state computation (or, if no steady state has been computed, from the last initval block).

Note that no variable type is stored in the file, so that the values can be reloaded with load_params_and_steady_state in a setup where the variable types are different.

The typical usage of this function is to compute the steady-state of a model by calibrating the steady-state value of some endogenous variables (which implies that some parameters must be endogeneized during the steady-state computation).

You would then write a first .mod file which computes the steady state and saves the result of the computation at the end of the file, using save_params_and_steady_state.

In a second file designed to perform the actual simulations, you would use load_params_and_steady_state just after your variable declarations, in order to load the steady state previously computed (including the parameters which had been endogeneized during the steady state computation).

The need for two separate .mod files arises from the fact that the variable declarations differ between the files for steady state calibration and for simulation (the set of endogenous and parameters differ between the two); this leads to different var and parameters statements.

Also note that you can take advantage of the @#include directive to share the model equations between the two files (see macro-proc-lang).

  • load_params_and_steady_state (FILENAME);

For all parameters, endogenous and exogenous variables, loads their value from a file created with save_params_and_steady_state.

  • for parameters, their value will be initialized as if they had been calibrated in the .mod file.
  • for endogenous and exogenous variables, their value will be initialized as they would have been from an initval block .

This function is used in conjunction with save_params_and_steady_state; see the documentation of that function for more information.

diff --git a/dev/model-file/deterministic-simulations/index.html b/dev/model-file/deterministic-simulations/index.html index 6538e62..939f963 100644 --- a/dev/model-file/deterministic-simulations/index.html +++ b/dev/model-file/deterministic-simulations/index.html @@ -1,5 +1,5 @@ -Deterministic simulations · Dynare.jl

When the framework is deterministic, Dynare can be used for models with the assumption of perfect foresight. The system is supposed to be in a given state before a period 1 (often a steady state) when the news of a contemporaneous or of a future shock is learned by the agents in the model. The purpose of the simulation is to describe the reaction in anticipation of, then in reaction to the shock, until the system returns to equilibrium. This return to equilibrium is only an asymptotic phenomenon, which one must approximate by an horizon of simulation far enough in the future. Another exercise for which Dynare is well suited is to study the transition path to a new equilibrium following a permanent shock. For deterministic simulations, the numerical problem consists of solving a nonlinear system of simultaneous equations in n endogenous variables in T periods. Dynare uses a Newton-type method to solve the simultaneous equation system. Because the resulting Jacobian is in the order of n by T and hence will be very large for long simulations with many variables, Dynare makes use of the sparse matrix code .

Dynare commands

perfect_foresight_setup

Command: perfect\_foresight\_setup;

Command: perfect\_foresight\_setup (OPTIONS...);

Prepares a perfect foresight simulation, by extracting the information in the initval, endval and shocks blocks and converting them into simulation paths for exogenous and endogenous variables.

This command must always be called before running the simulation with perfect\_foresight\_solver.

Options
  • periods = INTEGER

Number of periods of the simulation.

  • datafile = FILENAME

Used to specify path for all endogenous and exogenous variables. Strictly equivalent to initval_file.

Output

The paths for the exogenous variables are stored into context.results.model_resultst[1].simulations.

The initial and terminal conditions for the endogenous variables and the initial guess for the path of endogenous variables are stored into context.results.model_results[1].simulations.

perfect_foresight_solver

Command: perfect\_foresight\_solver ;

Command: perfect\_foresight\_solver (OPTIONS...);

Computes the perfect foresight (or deterministic) simulation of the model.

Note that perfect\_foresight\_setup must be called before this command, in order to setup the environment for the simulation.

Options
  • maxit = INTEGER

Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.

  • tolf = DOUBLE

Convergence criterion for termination based on the function value. Iteration will cease when it proves impossible to improve the function value by more than tolf. Default: 1e-5

  • tolx = DOUBLE

Convergence criterion for termination based on the change in the function argument. Iteration will cease when the solver attempts to take a step that is smaller than tolx. Default: 1e-5

  • noprint

Don't print anything. Useful for loops.

  • print

Print results (opposite of noprint).

  • lmmcp

Solves mixed complementarity problems (the term refers to the LMMCP solver (Kanzow and Petra, 2004), that is used by DynareMatlab. DynareJulia uses the PATHSovler package)

  • endogenous_terminal_period

The number of periods is not constant across Newton iterations when solving the perfect foresight model. The size of the nonlinear system of equations is reduced by removing the portion of the paths (and associated equations) for which the solution has already been identified (up to the tolerance parameter). This strategy can be interpreted as a mix of the shooting and relaxation approaches. Note that round off errors are more important with this mixed strategy (user should check the reported value of the maximum absolute error). Only available with option stack_solve_algo==0.

Remark

Be careful when employing auxiliary variables in the context of perfect
+Deterministic simulations · Dynare.jl

When the framework is deterministic, Dynare can be used for models with the assumption of perfect foresight. The system is supposed to be in a given state before a period 1 (often a steady state) when the news of a contemporaneous or of a future shock is learned by the agents in the model. The purpose of the simulation is to describe the reaction in anticipation of, then in reaction to the shock, until the system returns to equilibrium. This return to equilibrium is only an asymptotic phenomenon, which one must approximate by an horizon of simulation far enough in the future. Another exercise for which Dynare is well suited is to study the transition path to a new equilibrium following a permanent shock. For deterministic simulations, the numerical problem consists of solving a nonlinear system of simultaneous equations in n endogenous variables in T periods. Dynare uses a Newton-type method to solve the simultaneous equation system. Because the resulting Jacobian is in the order of n by T and hence will be very large for long simulations with many variables, Dynare makes use of the sparse matrix code .

Dynare commands

perfect_foresight_setup

Command: perfect\_foresight\_setup;

Command: perfect\_foresight\_setup (OPTIONS...);

Prepares a perfect foresight simulation, by extracting the information in the initval, endval and shocks blocks and converting them into simulation paths for exogenous and endogenous variables.

This command must always be called before running the simulation with perfect\_foresight\_solver.

Options
  • periods = INTEGER

Number of periods of the simulation.

  • datafile = FILENAME

Used to specify path for all endogenous and exogenous variables. Strictly equivalent to initval_file.

Output

The paths for the exogenous variables are stored into context.results.model_resultst[1].simulations.

The initial and terminal conditions for the endogenous variables and the initial guess for the path of endogenous variables are stored into context.results.model_results[1].simulations.

perfect_foresight_solver

Command: perfect\_foresight\_solver ;

Command: perfect\_foresight\_solver (OPTIONS...);

Computes the perfect foresight (or deterministic) simulation of the model.

Note that perfect\_foresight\_setup must be called before this command, in order to setup the environment for the simulation.

Options
  • maxit = INTEGER

Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.

  • tolf = DOUBLE

Convergence criterion for termination based on the function value. Iteration will cease when it proves impossible to improve the function value by more than tolf. Default: 1e-5

  • tolx = DOUBLE

Convergence criterion for termination based on the change in the function argument. Iteration will cease when the solver attempts to take a step that is smaller than tolx. Default: 1e-5

  • noprint

Don't print anything. Useful for loops.

  • print

Print results (opposite of noprint).

  • lmmcp

Solves mixed complementarity problems (the term refers to the LMMCP solver (Kanzow and Petra, 2004), that is used by DynareMatlab. DynareJulia uses the PATHSovler package)

  • endogenous_terminal_period

The number of periods is not constant across Newton iterations when solving the perfect foresight model. The size of the nonlinear system of equations is reduced by removing the portion of the paths (and associated equations) for which the solution has already been identified (up to the tolerance parameter). This strategy can be interpreted as a mix of the shooting and relaxation approaches. Note that round off errors are more important with this mixed strategy (user should check the reported value of the maximum absolute error). Only available with option stack_solve_algo==0.

Remark

Be careful when employing auxiliary variables in the context of perfect
 foresight computations. The same model may work for stochastic
 simulations, but fail for perfect foresight simulations. The issue
 arises when an equation suddenly only contains variables dated `t+1` (or
@@ -8,9 +8,9 @@
 Jacobian singular.
Example

Consider the following specification of an Euler equation with log utility:

Lambda = beta*C(-1)/C;
 Lambda(+1)*R(+1)= 1;

Clearly, the derivative of the second equation with respect to all endogenous variables at time t is zero, causing perfect_foresight_solver to generally fail. This is due to the use of the Lagrange multiplier Lambda as an auxiliary variable. Instead, employing the identical

beta*C/C(+1)*R(+1)= 1;

will work.

Julia function

Dynare.perfect_foresight!Function
perfect_foresight!(; periods, context = context, display = true,
                    linear_solve_algo=ilu, maxit = 50, mcp = false,
-                   tolf = 1e-5, tolx = 1e-5)

Keyword arguments

  • periods::Int: number of periods in the simulation [required]
  • context::Context=context: context in which the simulation is computed
  • display::Bool=true: whether to display the results
  • linear_solve_algo::LinearSolveAlgo=ilu: algorithm used for the solution of the linear problem. Either ilu or pardiso. ilu is the sparse linear solver used by default in Julia. To use the Pardiso solver, write using Pardiso before running Dynare.
  • maxit::Int=50 maximum number of iterations
  • mcp::Bool=falseL whether to solve a mixed complementarity problem with occasionally binding constraints
  • tolf::Float64=1e-5: tolerance for the norm of residualts
  • tolx::Float64=1e-5: tolerance for the norm of the change in the result
source
Output

The simulated endogenous variables are available in context.results.model_results[1].simulations. This is a vector of AxisArrayTable, one for each simulations stored in context. Each AxisArrayTable contains the trajectories for endogenous and exogenous variables

Solving mixed complementarity problems

requires a particular model setup as the goal is to get rid of any min/max operators and complementary slackness conditions that might introduce a singularity into the Jacobian. This is done by attaching an equation tag (see model-decl) with the mcp keyword to affected equations. The format of the mcp tag is

[mcp = 'VARIABBLENAME OP CONSTANT']

where VARIABLENAME is an endogenous variable and OP is either > or <. For complicated occasionally binding constraints, it may be necessary to declare a new endogenous variable.

This tag states that the equation to which the tag is attached has to hold unless the expression within the tag is binding. For instance, a ZLB on the nominal interest rate would be specified as follows in the model block:

    model;
+                   tolf = 1e-5, tolx = 1e-5)

Keyword arguments

  • periods::Int: number of periods in the simulation [required]
  • context::Context=context: context in which the simulation is computed
  • display::Bool=true: whether to display the results
  • linear_solve_algo::LinearSolveAlgo=ilu: algorithm used for the solution of the linear problem. Either ilu or pardiso. ilu is the sparse linear solver used by default in Julia. To use the Pardiso solver, write using Pardiso before running Dynare.
  • maxit::Int=50 maximum number of iterations
  • mcp::Bool=falseL whether to solve a mixed complementarity problem with occasionally binding constraints
  • tolf::Float64=1e-5: tolerance for the norm of residualts
  • tolx::Float64=1e-5: tolerance for the norm of the change in the result
source
Output

The simulated endogenous variables are available in context.results.model_results[1].simulations. This is a vector of AxisArrayTable, one for each simulations stored in context. Each AxisArrayTable contains the trajectories for endogenous and exogenous variables

Solving mixed complementarity problems

requires a particular model setup as the goal is to get rid of any min/max operators and complementary slackness conditions that might introduce a singularity into the Jacobian. This is done by attaching an equation tag (see model-decl) with the mcp keyword to affected equations. The format of the mcp tag is

[mcp = 'VARIABBLENAME OP CONSTANT']

where VARIABLENAME is an endogenous variable and OP is either > or <. For complicated occasionally binding constraints, it may be necessary to declare a new endogenous variable.

This tag states that the equation to which the tag is attached has to hold unless the expression within the tag is binding. For instance, a ZLB on the nominal interest rate would be specified as follows in the model block:

    model;
        ...
        [mcp = 'r > -1.94478']
        r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;
        ...
-    end;

where r is the nominal interest rate in deviation from the steady state. This construct implies that the Taylor rule is operative, unless the implied interest rate r<=-1.94478, in which case the r is fixed at -1.94478. This is equavalant to

\[(r_t > -1.94478)\;\; \bot\;\; r_t = \rho r_{t-1} + (1-\rho) (g_\pi Infl_t+g_y YGap_t) + e_t\]

By restricting the value of r coming out of this equation, the mcp tag also avoids using max(r,-1.94478) for other occurrences of r in the rest of the model. It is important to keep in mind that, because the mcp tag effectively replaces a complementary slackness condition, it cannot be simply attached to any equation.

Note that in the current implementation, the content of the mcp equation tag is not parsed by the preprocessor. The inequalities must therefore be as simple as possible: an endogenous variable, followed by a relational operator, followed by a number (not a variable, parameter or expression).

+ end;

where r is the nominal interest rate in deviation from the steady state. This construct implies that the Taylor rule is operative, unless the implied interest rate r<=-1.94478, in which case the r is fixed at -1.94478. This is equavalant to

\[(r_t > -1.94478)\;\; \bot\;\; r_t = \rho r_{t-1} + (1-\rho) (g_\pi Infl_t+g_y YGap_t) + e_t\]

By restricting the value of r coming out of this equation, the mcp tag also avoids using max(r,-1.94478) for other occurrences of r in the rest of the model. It is important to keep in mind that, because the mcp tag effectively replaces a complementary slackness condition, it cannot be simply attached to any equation.

Note that in the current implementation, the content of the mcp equation tag is not parsed by the preprocessor. The inequalities must therefore be as simple as possible: an endogenous variable, followed by a relational operator, followed by a number (not a variable, parameter or expression).

diff --git a/dev/model-file/estimation/index.html b/dev/model-file/estimation/index.html index ea5fa7c..5f88ea6 100644 --- a/dev/model-file/estimation/index.html +++ b/dev/model-file/estimation/index.html @@ -1,5 +1,5 @@ -Estimation · Dynare.jl

Provided that you have observations on some endogenous variables, it is possible to use Dynare to estimate some or all parameters. Bayesian techniques (as in Fernández-Villaverde and Rubio-Ramírez (2004), Rabanal and Rubio-Ramirez (2003), Schorfheide (2000) or Smets and Wouters (2003)) are available. Using Bayesian methods, it is possible to estimate DSGE models.

Note that in order to avoid stochastic singularity, you must have at least as many shocks or measurement errors in your model as you have observed variables.

Before using the estimation commands described below, you need to define some elements of the state space representation of the model. At the minimum, you need to declare the observed variables with var_obs and, possibly, deterministic trends with observation_trends (see the previous section: State space, filtering and smoothing)

Dynare commands

estimated_params

Block: estimated_params ;

Block: estimated_params (overwrite) ;

This block lists all parameters to be estimated and specifies bounds and priors as necessary.

Each line corresponds to an estimated parameter.

In a maximum likelihood or a method of moments estimation, each line follows this syntax:

    stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME
+Estimation · Dynare.jl

Provided that you have observations on some endogenous variables, it is possible to use Dynare to estimate some or all parameters. Bayesian techniques (as in Fernández-Villaverde and Rubio-Ramírez (2004), Rabanal and Rubio-Ramirez (2003), Schorfheide (2000) or Smets and Wouters (2003)) are available. Using Bayesian methods, it is possible to estimate DSGE models.

Note that in order to avoid stochastic singularity, you must have at least as many shocks or measurement errors in your model as you have observed variables.

Before using the estimation commands described below, you need to define some elements of the state space representation of the model. At the minimum, you need to declare the observed variables with var_obs and, possibly, deterministic trends with observation_trends (see the previous section: State space, filtering and smoothing)

Dynare commands

estimated_params

Block: estimated_params ;

Block: estimated_params (overwrite) ;

This block lists all parameters to be estimated and specifies bounds and priors as necessary.

Each line corresponds to an estimated parameter.

In a maximum likelihood or a method of moments estimation, each line follows this syntax:

    stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME
     , INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND ];

In a Bayesian MCMC or a penalized method of moments estimation, each line follows this syntax:

    stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME | DSGE_PRIOR_WEIGHT
     [, INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND]], PRIOR_SHAPE,
     PRIOR_MEAN, PRIOR_STANDARD_ERROR [, PRIOR_3RD_PARAMETER [,
@@ -12,7 +12,7 @@
 
      estimated_params;
      bet, normal_pdf, 1, 0.05;
-     end;

It is possible to have several estimated_params blocks. By default, subsequent blocks are concatenated with the previous ones; this can be useful when building models in a modular fashion (see also estimated_params_remove for that use case). However, if an estimated_params block has the overwrite option, its contents becomes the new list of estimated parameters, cancelling previous blocks; this can be useful when doing several estimations in a single .mod file.

estimated_params_init

Block: estimated_params_init ;

Block: estimated_params_init (OPTIONS...);

This block declares numerical initial values for the optimizer when these ones are different from the prior mean. It should be specified after the estimated_params block as otherwise the specified starting values are overwritten by the latter.

Each line has the following syntax:

    stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME, INITIAL_VALUE;

estimation

Command: estimation [VARIABLE_NAME...];

Command: estimation (OPTIONS...)[VARIABLE_NAME...];

This command runs Bayesian estimation.

Options
  • datafile = FILENAME

The datafile must be in CSV format

    estimation(datafile='../fsdat_simul.csv',...);
  • nobs = INTEGER

The number of observations following first_obs to be used. Default: all observations in the file after first_obs.

  • first_obs = INTEGER

The number of the first observation to be used. In case of estimating a DSGE-VAR, first_obs needs to be larger than the number of lags. Default: 1.

  • plot_priors = INTEGER: Control the plotting of priors, 0, no prior plot, 1, pPrior density for each estimated parameter is plotted. It is important to check that the actual shape of prior densities matches what you have in mind. Ill-chosen values for the prior standard density can result in absurd prior densities (default valueL 1).

  • mh_replic = INTEGER

Number of replications for each chain of the Metropolis-Hastings algorithm. The number of draws should be sufficient to achieve convergence of the MCMC and to meaningfully compute posterior objects. Default: 20000.

  • mh_nblocks = INTEGER

Number of parallel chains for Metropolis-Hastings algorithm. Default: 2.

  • mh_jscale = DOUBLE

The scale parameter of the jumping distribution's covariance matrix. The default value is rarely satisfactory. This option must be tuned to obtain, ideally, an acceptance ratio of 25%-33%. Basically, the idea is to increase the variance of the jumping distribution if the acceptance ratio is too high, and decrease the same variance if the acceptance ratio is too low. In some situations it may help to consider parameter-specific values for this scale parameter. This can be done in the estimated_params block. Default: 0.2.

Julia functions

Dynare.mode_compute!Function
 mode_compute!(; 
+     end;

It is possible to have several estimated_params blocks. By default, subsequent blocks are concatenated with the previous ones; this can be useful when building models in a modular fashion (see also estimated_params_remove for that use case). However, if an estimated_params block has the overwrite option, its contents becomes the new list of estimated parameters, cancelling previous blocks; this can be useful when doing several estimations in a single .mod file.

estimated_params_init

Block: estimated_params_init ;

Block: estimated_params_init (OPTIONS...);

This block declares numerical initial values for the optimizer when these ones are different from the prior mean. It should be specified after the estimated_params block as otherwise the specified starting values are overwritten by the latter.

Each line has the following syntax:

    stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME, INITIAL_VALUE;

estimation

Command: estimation [VARIABLE_NAME...];

Command: estimation (OPTIONS...)[VARIABLE_NAME...];

This command runs Bayesian estimation.

Options
  • datafile = FILENAME

The datafile must be in CSV format

    estimation(datafile='../fsdat_simul.csv',...);
  • nobs = INTEGER

The number of observations following first_obs to be used. Default: all observations in the file after first_obs.

  • first_obs = INTEGER

The number of the first observation to be used. In case of estimating a DSGE-VAR, first_obs needs to be larger than the number of lags. Default: 1.

  • plot_priors = INTEGER: Control the plotting of priors, 0, no prior plot, 1, pPrior density for each estimated parameter is plotted. It is important to check that the actual shape of prior densities matches what you have in mind. Ill-chosen values for the prior standard density can result in absurd prior densities (default valueL 1).

  • mh_replic = INTEGER

Number of replications for each chain of the Metropolis-Hastings algorithm. The number of draws should be sufficient to achieve convergence of the MCMC and to meaningfully compute posterior objects. Default: 20000.

  • mh_nblocks = INTEGER

Number of parallel chains for Metropolis-Hastings algorithm. Default: 2.

  • mh_jscale = DOUBLE

The scale parameter of the jumping distribution's covariance matrix. The default value is rarely satisfactory. This option must be tuned to obtain, ideally, an acceptance ratio of 25%-33%. Basically, the idea is to increase the variance of the jumping distribution if the acceptance ratio is too high, and decrease the same variance if the acceptance ratio is too low. In some situations it may help to consider parameter-specific values for this scale parameter. This can be done in the estimated_params block. Default: 0.2.

Julia functions

Dynare.mode_compute!Function
 mode_compute!(; 
              context=context,
              data = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),
              datafile = "",
@@ -26,10 +26,10 @@
              nobs::Int = 0,
              order::Int = 1,
              presample::Int = 0,
-             transformed_parameters = true)

computes the posterior mode.

Keyword arguments

  • context::Context=context: context of the computation
  • data::AxisArrayTable: AxisArrayTable containing observed variables
  • datafile::String: data filename (can't be used as the same time asdataset`)
  • first_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)
  • initial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)
  • last_obs::PeriodsSinceEpoch: last period (default: last period of the dataset)
  • nobs::Int = 0: number of observations (default: entire dataset)
  • transformed_parameters = true: whether to transform estimated parameter so as they take their value on R

Either data or datafile must be specified.

source
Dynare.plot_priorsFunction
plot_priors(; context::Context = context, n_points::Int = 100)

plots prior density

Keyword arguments

  • context::Context = context: context in which to take the date to be ploted
  • n_points::Int = 100: number of points used for a curve
source
Dynare.plot_prior_posteriorFunction
plot_prior_posterior(chains; context::Context=context)

plots priors posterios and mode if computed on the same plots

Keyword arguments

  • context::Context=context: context used to get the estimation results

Output

  • the plots are saved in ./<modfilename>/Graphs/PriorPosterior_<x>.png
source
Dynare.prior!Function
 prior!(s::Symbol; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)
+             transformed_parameters = true)

computes the posterior mode.

Keyword arguments

  • context::Context=context: context of the computation
  • data::AxisArrayTable: AxisArrayTable containing observed variables
  • datafile::String: data filename (can't be used as the same time asdataset`)
  • first_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)
  • initial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)
  • last_obs::PeriodsSinceEpoch: last period (default: last period of the dataset)
  • nobs::Int = 0: number of observations (default: entire dataset)
  • transformed_parameters = true: whether to transform estimated parameter so as they take their value on R

Either data or datafile must be specified.

source
Dynare.plot_priorsFunction
plot_priors(; context::Context = context, n_points::Int = 100)

plots prior density

Keyword arguments

  • context::Context = context: context in which to take the date to be ploted
  • n_points::Int = 100: number of points used for a curve
source
Dynare.plot_prior_posteriorFunction
plot_prior_posterior(chains; context::Context=context)

plots priors posterios and mode if computed on the same plots

Keyword arguments

  • context::Context=context: context used to get the estimation results

Output

  • the plots are saved in ./<modfilename>/Graphs/PriorPosterior_<x>.png
source
Dynare.prior!Function
 prior!(s::Symbol; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)
  prior!(s::stdev; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)
  prior!(s::variance; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)
- prior!(s::corr; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)

generates a prior for a symbol of a parameter, the standard deviation (stdev) or the variance (variance) of an exogenous variable or an endogenous variable (measurement error) or the correlation (corr) between 2 endogenous or exogenous variables

Keywor arguments

  • shape <: Distributions: the shape of the prior distribution (Beta, InvertedGamma, InvertedGamma1, Gamma, Normal, Uniform, Weibull) [required]
  • context::Context=context: context in which the prior is declared
  • domain::Vector{<:Real}=Float64[]: domain for a uniform distribution
  • initialvalue::Union{Real,Missing}=missing: initialvalue for mode finding or MCMC iterations
  • mean::Union{Real,Missing}=missing: mean of the prior distribution
  • stdev::Union{Real,Missing}=missing: stdev of the prior distribution
  • variance::Union{Real,Missing}=missing: variance of the prior distribution
source
Dynare.rwmh_compute!Function
rwmh_compute!(;context::Context=context,
+ prior!(s::corr; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)

generates a prior for a symbol of a parameter, the standard deviation (stdev) or the variance (variance) of an exogenous variable or an endogenous variable (measurement error) or the correlation (corr) between 2 endogenous or exogenous variables

Keywor arguments

  • shape <: Distributions: the shape of the prior distribution (Beta, InvertedGamma, InvertedGamma1, Gamma, Normal, Uniform, Weibull) [required]
  • context::Context=context: context in which the prior is declared
  • domain::Vector{<:Real}=Float64[]: domain for a uniform distribution
  • initialvalue::Union{Real,Missing}=missing: initialvalue for mode finding or MCMC iterations
  • mean::Union{Real,Missing}=missing: mean of the prior distribution
  • stdev::Union{Real,Missing}=missing: stdev of the prior distribution
  • variance::Union{Real,Missing}=missing: variance of the prior distribution
source
Dynare.rwmh_compute!Function
rwmh_compute!(;context::Context=context,
          back_transformation::Bool = true,
          datafile::String = "",
          data::AxisArrayTable = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),
@@ -51,4 +51,4 @@
          plot_chain::Bool = true,
          plot_posterior_density::Bool = false, 
          presample::Int = 0,
-         transformed_parameters::Bool = true

)

runs random walk Monte Carlo simulations of the posterior

Keyword arguments

  • context::Context=context: context of the computation
  • covariance::AbstractMatrix{Float64}:
  • data::AxisArrayTable: AxisArrayTable containing observed variables
  • datafile::String: data filename
  • first_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)
  • initial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)
  • last_obs::PeriodsSinceEpoch: last period (default: last dataseet in the dataset)
  • mcmc_chains::Int number of MCMC chains (default: 1)
  • mcmc_jscale::Float64: scale factor of proposal
  • mcmc_replic::Int: = 0,
  • nobs::Int = 0: number of observations (default: entire dataset)
  • plot_chain::Bool: whether to display standard MCMC chain output (default:true)
  • plot_posterior_density::Bool: wether to display plots with prior and posterior densities (default: false)
  • transformed_covariance::Matrix{Float64}: covariance of transformed parameters (default: empty)
  • transformed_parameters = true: whether to transform estimated parameter so as they take their value on R

Either data or datafile must be specified.

source
+ transformed_parameters::Bool = true

)

runs random walk Monte Carlo simulations of the posterior

Keyword arguments

  • context::Context=context: context of the computation
  • covariance::AbstractMatrix{Float64}:
  • data::AxisArrayTable: AxisArrayTable containing observed variables
  • datafile::String: data filename
  • first_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)
  • initial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)
  • last_obs::PeriodsSinceEpoch: last period (default: last dataseet in the dataset)
  • mcmc_chains::Int number of MCMC chains (default: 1)
  • mcmc_jscale::Float64: scale factor of proposal
  • mcmc_replic::Int: = 0,
  • nobs::Int = 0: number of observations (default: entire dataset)
  • plot_chain::Bool: whether to display standard MCMC chain output (default:true)
  • plot_posterior_density::Bool: wether to display plots with prior and posterior densities (default: false)
  • transformed_covariance::Matrix{Float64}: covariance of transformed parameters (default: empty)
  • transformed_parameters = true: whether to transform estimated parameter so as they take their value on R

Either data or datafile must be specified.

source
diff --git a/dev/model-file/filtersmoother/index.html b/dev/model-file/filtersmoother/index.html index 7017a7b..e01ecf1 100644 --- a/dev/model-file/filtersmoother/index.html +++ b/dev/model-file/filtersmoother/index.html @@ -1,5 +1,5 @@ -State space, filtering and smoothing · Dynare.jl

From a statistical point of view, DSGE models are unobserved components models: only a few variables are observed. Filtering or smoothing provide estimate of the unobserved variables given the observations.

The model is put in state space form

\[\begin{align*} +State space, filtering and smoothing · Dynare.jl

From a statistical point of view, DSGE models are unobserved components models: only a few variables are observed. Filtering or smoothing provide estimate of the unobserved variables given the observations.

The model is put in state space form

\[\begin{align*} y^o_t &= M s_t + N\epsilon_t\\ s_t &= Ts_{t-1} + R\eta_t \end{align*}\]

where $y^o_t$ represents observed variable at period t. The coefficient matrices of the transition equation, T and R are provided by the solution of the linear(-isze) rational expectation model. $\epsilon_t$ are possible measurement errors and $\eta_t$ the structural shocks. Most often matrix M is a selection matrix.

Filtering provides estimates conditional only on past observations:

\[\mathbb{E}(y^{no}_t|Y^o_{t-1})\]

where $y^{no}_t$ are unobserved variables at period t and $Y^o_{t-1}$ represent the set observations until period t-1 included.

Smoothing provides estimates of unobserved variables conditional on the entire sample of observations:

\[\mathbb{E}(y^{no}_t|Y^o_T)\]

where $Y^o_T$ represents the all observations in the sample.

Dynare command

varobs

Observed variables are declared with the varobs command

Command: varobs VARIABLE_NAME...;

This command lists the name of observed endogenous variables for the estimation procedure. These variables must be available in the data file (see estimation_cmd <estim-comm>).

Alternatively, this command is also used in conjunction with the partial_information option of stoch_simul, for declaring the set of observed variables when solving the model under partial information.

Only one instance of varobs is allowed in a model file. If one needs to declare observed variables in a loop, the macro processor can be used as shown in the second example below.

Example
     varobs C y rr;

It is possible to declare a deterministic linear trend that is removed for the computations and added back in the results

Block: observation_trends ;

This block specifies linear trends for observed variables as functions of model parameters. In case the loglinear option is used, this corresponds to a linear trend in the logged observables, i.e. an exponential trend in the level of the observables.

Each line inside of the block should be of the form:

    VARIABLE_NAME(EXPRESSION);

In most cases, variables shouldn't be centered when observation_trends is used.

Example
     observation_trends;
@@ -11,4 +11,4 @@
                  first_obs::PeriodSinceEpoch = Undated(typemin(Int)),
                  last_obs::PeriodSinceEpoch = Undated(typemin(Int)),
                  nobs::Int = 0
-               )

Compute the smoothed values of the variables for an estimated model

#Keyword arguments

  • periods::Integer: number of forecasted periods [required]
  • datafile::String: file with the observations for the smoother
  • data::AxisArrayTable: AxisArrayTable containing observed variables (can't be used at the same time as datafile)
  • first_obs::PeriodSinceEpoch: first period used by smoother (default: first observation in the dataset)
  • last_obs::PeriodSinceEpoch: last period used by smoother (default: last observation in the dataset)
  • nobs::Int: number of observations (default: entire dataset)
source
+ )

Compute the smoothed values of the variables for an estimated model

#Keyword arguments

source diff --git a/dev/model-file/forecasting/index.html b/dev/model-file/forecasting/index.html index 6c8201b..c5db5f8 100644 --- a/dev/model-file/forecasting/index.html +++ b/dev/model-file/forecasting/index.html @@ -1,9 +1,9 @@ -Forecasting · Dynare.jl

Julia functions

Dynare.forecasting!Function
forecasting!(; periods::Integer,
+Forecasting · Dynare.jl

Julia functions

Dynare.forecasting!Function
forecasting!(; periods::Integer,
                forecast_mode::ForecastModes,
                context::Context=context,
                datafile::String="",
                first_obs::PeriodsSinceEpoch=Undated(typemin(Int)),
                first_period::PeriodsSinceEpoch=Undated(0),
                last_obs::PeriodsSinceEpoch=Undated(typemin(Int)),
-               order::Integer=1)

computes an unconditional forecast of the variables of the model

Keyword arguments

  • periods::Integer: number of forecasted periods [required]
  • forecast_mode::ForecastModes: one of histval or calibsmoother [required]
  • datafile::String: file with the observations for the smoother
  • first_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file)
  • first_period::PeriodsSinceEpoch: initial_period for the forecast (default when histval: Undated(0), default when calibsmoother: last period of the smoother)
  • last_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)
  • order::Integer: order of local approximation
source
Dynare.recursive_forecasting!Function

function recursiveforecasting!(; Np::Integer, firstperiod::PeriodsSinceEpoch, lastperiod::PeriodsSinceEpoch, context::Context=context, datafile::String="", firstobs::PeriodsSinceEpoch=Undated(1), last_obs::PeriodsSinceEpoch=Undated(0), order::Integer=1) computes an unconditional recursive forecast for one variable by adding one period to the sample used for the smoother before forecasting over Np periods.

Keyword arguments

  • Np::Integer: number of forecasted periods [required]
  • first_period::PeriodsSinceEpoch: initial period of first forecast [required]
  • last_period::PeriodsSinceEpoch: initial period of last forecast [required]
  • datafile::String: file with the observations for the smoother
  • first_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file)
  • last_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)
  • order::Integer: order of local approximation
source
+ order::Integer=1)

computes an unconditional forecast of the variables of the model

Keyword arguments

  • periods::Integer: number of forecasted periods [required]
  • forecast_mode::ForecastModes: one of histval or calibsmoother [required]
  • datafile::String: file with the observations for the smoother
  • first_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file)
  • first_period::PeriodsSinceEpoch: initial_period for the forecast (default when histval: Undated(0), default when calibsmoother: last period of the smoother)
  • last_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)
  • order::Integer: order of local approximation
source
Dynare.recursive_forecasting!Function

function recursiveforecasting!(; Np::Integer, firstperiod::PeriodsSinceEpoch, lastperiod::PeriodsSinceEpoch, context::Context=context, datafile::String="", firstobs::PeriodsSinceEpoch=Undated(1), last_obs::PeriodsSinceEpoch=Undated(0), order::Integer=1) computes an unconditional recursive forecast for one variable by adding one period to the sample used for the smoother before forecasting over Np periods.

Keyword arguments

  • Np::Integer: number of forecasted periods [required]
  • first_period::PeriodsSinceEpoch: initial period of first forecast [required]
  • last_period::PeriodsSinceEpoch: initial period of last forecast [required]
  • datafile::String: file with the observations for the smoother
  • first_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file)
  • last_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)
  • order::Integer: order of local approximation
source
diff --git a/dev/model-file/local-approxiation/index.html b/dev/model-file/local-approxiation/index.html index dc53268..81544b8 100644 --- a/dev/model-file/local-approxiation/index.html +++ b/dev/model-file/local-approxiation/index.html @@ -1,5 +1,5 @@ -Local approximation · Dynare.jl

In a stochastic context, Dynare computes one or several simulations corresponding to a random draw of the shocks.

The main algorithm for solving stochastic models relies on a Taylor approximation, up to second order, of the solution function (see Judd (1996), Collard and Juillard (2001a, 2001b), and Schmitt-Grohé and Uríbe (2004)). The details of the Dynare implementation of the first order solution are given in Villemot (2011). Such a solution is computed using the stoch_simul command.

Dynare commands

stoch_simul

Command: `stoch_simul;

Command: `stoch_simul (OPTIONS...);

Solves a stochastic (i.e. rational expectations) model, using perturbation techniques.

More precisely, stoch_simul computes a Taylor approximation of the model around the deterministic steady state and solves of the the decision and transition functions for the approximated model. Using this, it computes impulse response functions and various descriptive statistics (moments, variance decomposition, correlation and autocorrelation coefficients). For correlated shocks, the variance decomposition is computed as in the VAR literature through a Cholesky decomposition of the covariance matrix of the exogenous variables. When the shocks are correlated, the variance decomposition depends upon the order of the variables in the varexo command.

The IRFs are computed as the difference between the trajectory of a variable following a shock at the beginning of period 1 and its steady state value. More details on the computation of IRFs can be found at https://archives.dynare.org/DynareWiki/IrFs.

Variance decomposition, correlation, autocorrelation are only displayed for variables with strictly positive variance. Impulse response functions are only plotted for variables with response larger than $10^{-10}$.

Variance decomposition is computed relative to the sum of the contribution of each shock. Normally, this is of course equal to aggregate variance, but if a model generates very large variances, it may happen that, due to numerical error, the two differ by a significant amount. Dynare issues a warning if the maximum relative difference between the sum of the contribution of each shock and aggregate variance is larger than 0.01%.

The covariance matrix of the shocks is specified with the shocks command (see shocks-exo).

Options
  • ar = INTEGER

Order of autocorrelation coefficients to compute. Default: 5

  • irf = INTEGER

Number of periods on which to compute the IRFs. Setting irf=0 suppresses the plotting of IRFs. Default: 40.

  • nonstationary: declares the model as nonstationary.

  • noprint: don't print the results

  • order = INTEGER

Order of Taylor approximation. Note that for third order and above, the k_order_solver option is implied and only empirical moments are available (you must provide a value for periods option). Default: 2

  • periods = INTEGER

If different from zero, empirical moments will be computed instead of theoretical moments. The value of the option specifies the number of periods to use in the simulations. Values of the initval block, possibly recomputed by steady, will be used as starting point for the simulation. The simulated endogenous variables are made available to the user in Julia variable context.results.model_results[1].simulation. Default: 0.

  • dr = OPTION

Determines the method used to compute the decision rule. Possible values for OPTION are:

default

Uses the default method to compute the decision rule based on the generalized Schur decomposition (see Villemot (2011) for more information).

cycle_reduction

Uses the cycle reduction algorithm to solve the polynomial equation for retrieving the coefficients associated to the endogenous variables in the decision rule. This method is faster than the default one for large scale models.

Default value is default.

Output

The derivatives of the approximated solution function are availabe in the vector of matrices context.results.model_results[1].solution_derivatives. The first element contains the matrix of first order derivatives. The second element, the matrix of second order derivatives.

The matrix of first order derivatives is a $n x (n_s + n_x + 1)$ matrix where n is the number of endogenous variables, $n_s$, the number of state variables (variables appearing in the model with a lag), and $n_x$, the number of exogenous variables. An element of this matrix is

\[\begin{align*} +Local approximation · Dynare.jl

In a stochastic context, Dynare computes one or several simulations corresponding to a random draw of the shocks.

The main algorithm for solving stochastic models relies on a Taylor approximation, up to second order, of the solution function (see Judd (1996), Collard and Juillard (2001a, 2001b), and Schmitt-Grohé and Uríbe (2004)). The details of the Dynare implementation of the first order solution are given in Villemot (2011). Such a solution is computed using the stoch_simul command.

Dynare commands

stoch_simul

Command: `stoch_simul;

Command: `stoch_simul (OPTIONS...);

Solves a stochastic (i.e. rational expectations) model, using perturbation techniques.

More precisely, stoch_simul computes a Taylor approximation of the model around the deterministic steady state and solves of the the decision and transition functions for the approximated model. Using this, it computes impulse response functions and various descriptive statistics (moments, variance decomposition, correlation and autocorrelation coefficients). For correlated shocks, the variance decomposition is computed as in the VAR literature through a Cholesky decomposition of the covariance matrix of the exogenous variables. When the shocks are correlated, the variance decomposition depends upon the order of the variables in the varexo command.

The IRFs are computed as the difference between the trajectory of a variable following a shock at the beginning of period 1 and its steady state value. More details on the computation of IRFs can be found at https://archives.dynare.org/DynareWiki/IrFs.

Variance decomposition, correlation, autocorrelation are only displayed for variables with strictly positive variance. Impulse response functions are only plotted for variables with response larger than $10^{-10}$.

Variance decomposition is computed relative to the sum of the contribution of each shock. Normally, this is of course equal to aggregate variance, but if a model generates very large variances, it may happen that, due to numerical error, the two differ by a significant amount. Dynare issues a warning if the maximum relative difference between the sum of the contribution of each shock and aggregate variance is larger than 0.01%.

The covariance matrix of the shocks is specified with the shocks command (see shocks-exo).

Options
  • ar = INTEGER

Order of autocorrelation coefficients to compute. Default: 5

  • irf = INTEGER

Number of periods on which to compute the IRFs. Setting irf=0 suppresses the plotting of IRFs. Default: 40.

  • nonstationary: declares the model as nonstationary.

  • noprint: don't print the results

  • order = INTEGER

Order of Taylor approximation. Note that for third order and above, the k_order_solver option is implied and only empirical moments are available (you must provide a value for periods option). Default: 2

  • periods = INTEGER

If different from zero, empirical moments will be computed instead of theoretical moments. The value of the option specifies the number of periods to use in the simulations. Values of the initval block, possibly recomputed by steady, will be used as starting point for the simulation. The simulated endogenous variables are made available to the user in Julia variable context.results.model_results[1].simulation. Default: 0.

  • dr = OPTION

Determines the method used to compute the decision rule. Possible values for OPTION are:

default

Uses the default method to compute the decision rule based on the generalized Schur decomposition (see Villemot (2011) for more information).

cycle_reduction

Uses the cycle reduction algorithm to solve the polynomial equation for retrieving the coefficients associated to the endogenous variables in the decision rule. This method is faster than the default one for large scale models.

Default value is default.

Output

The derivatives of the approximated solution function are availabe in the vector of matrices context.results.model_results[1].solution_derivatives. The first element contains the matrix of first order derivatives. The second element, the matrix of second order derivatives.

The matrix of first order derivatives is a $n x (n_s + n_x + 1)$ matrix where n is the number of endogenous variables, $n_s$, the number of state variables (variables appearing in the model with a lag), and $n_x$, the number of exogenous variables. An element of this matrix is

\[\begin{align*} X_{i,j} &= \frac{\partial g_i}{\partial y_j},\;\;j=1,\ldots,n_s\\ X_{i,n_s+j} &= \frac{\partial g_i}{\partial x_j},\;\;j=1,\ldots,n_x\\ X_{i,n_s+n_k+1} &= \frac{\partial g_i}{\partial \sigma} = 0 @@ -12,6 +12,6 @@ dr_algo::String = "GS", irf::Int = 40, LRE_options = LinearRationalExpectationsOptions(), nar::Int = 5, nonstationary::Bool = false, - order::Int = 1, periods::Int = 0 )

computes a local approximation of a model contained in context

Keyword arguments

  • context::Context=context: context in which the simulation is computed
  • display::Bool=true: whether to display the results
  • dr_algo::String: solution algorithm, either "GS" for generalized Schur decomposition (default) or "CR" for cyclic reduction
  • irf::Int = 40: number of periods for IRFs. Use 0 for no IRF computation
  • LRE_options::LinearRationalExpectationsOptions = LinearRationalExpectationsOptions(): options passed to the LinearRationalExpectation package
  • nar::Int = 5: numnber of periods for autocorrelations. Use 0 for no autocorrelation computation
  • nonstationary::Bool = false: to specify a nonstationary model
  • periods::Int = 0: number of periods for an optional Monte Carlo simulation of the model
source

First-order approximation

The approximation has the stylized form:

\[y_t = y^s + A \phi(y_{t-1}) + B u_t\]

where $y^s$ is the steady state value of $y$ and $\phi(y_{t-1})=y_{t-1}-y^s$. Matrices of coefficients $A$ and $B$ are computed by Dynare.

Second-order approximation

The approximation has the form:

\[y_t = y^s + 0.5 \Delta^2 + A \phi(y_{t-1}) + B u_t + 0.5 C + order::Int = 1, periods::Int = 0 )

computes a local approximation of a model contained in context

Keyword arguments

  • context::Context=context: context in which the simulation is computed
  • display::Bool=true: whether to display the results
  • dr_algo::String: solution algorithm, either "GS" for generalized Schur decomposition (default) or "CR" for cyclic reduction
  • irf::Int = 40: number of periods for IRFs. Use 0 for no IRF computation
  • LRE_options::LinearRationalExpectationsOptions = LinearRationalExpectationsOptions(): options passed to the LinearRationalExpectation package
  • nar::Int = 5: numnber of periods for autocorrelations. Use 0 for no autocorrelation computation
  • nonstationary::Bool = false: to specify a nonstationary model
  • periods::Int = 0: number of periods for an optional Monte Carlo simulation of the model
source

First-order approximation

The approximation has the stylized form:

\[y_t = y^s + A \phi(y_{t-1}) + B u_t\]

where $y^s$ is the steady state value of $y$ and $\phi(y_{t-1})=y_{t-1}-y^s$. Matrices of coefficients $A$ and $B$ are computed by Dynare.

Second-order approximation

The approximation has the form:

\[y_t = y^s + 0.5 \Delta^2 + A \phi(y_{t-1}) + B u_t + 0.5 C (\phi(y_{t-1})\otimes \phi(y_{t-1})) + 0.5 D (u_t \otimes u_t) + E -(\phi(y_{t-1}) \otimes u_t)\]

where $y^s$ is the steady state value of $y$, $\phi(y_{t-1})=y_{t-1}-y^s$, and $\Delta^2$ is the shift effect of the variance of future shocks. Matrices of coefficients $A$, $B$, $C$, $D$ and $E$ are computed by Dynare.

+(\phi(y_{t-1}) \otimes u_t)\]

where $y^s$ is the steady state value of $y$, $\phi(y_{t-1})=y_{t-1}-y^s$, and $\Delta^2$ is the shift effect of the variance of future shocks. Matrices of coefficients $A$, $B$, $C$, $D$ and $E$ are computed by Dynare.

diff --git a/dev/model-file/model-declaration/index.html b/dev/model-file/model-declaration/index.html index 10926cb..a9df0ea 100644 --- a/dev/model-file/model-declaration/index.html +++ b/dev/model-file/model-declaration/index.html @@ -1,5 +1,5 @@ -Model declaration · Dynare.jl

Model declaration

The model is declared inside a model block:

Block: model ;

Block: model (OPTIONS...);

The equations of the model are written in a block delimited by model and end keywords.

There must be as many equations as there are endogenous variables in the model, except when computing the unconstrained optimal policy with ramsey_model, ramsey_policy or discretionary_policy.

The syntax of equations must follow the conventions for MODEL_EXPRESSION as described in expr. Each equation must be terminated by a semicolon (';'). A normal equation looks like:

MODEL_EXPRESSION = MODEL_EXPRESSION;

When the equations are written in homogenous form, it is possible to omit the '=0' part and write only the left hand side of the equation. A homogenous equation looks like:

MODEL_EXPRESSION;

Inside the model block, Dynare allows the creation of model-local variables, which constitute a simple way to share a common expression between several equations. The syntax consists of a pound sign (#) followed by the name of the new model local variable (which must not be declared as in var-decl, but may have been declared by model_local_variable), an equal sign, and the expression for which this new variable will stand. Later on, every time this variable appears in the model, Dynare will substitute it by the expression assigned to the variable. Note that the scope of this variable is restricted to the model block; it cannot be used outside. To assign a LaTeX name to the model local variable, use the declaration syntax outlined by model_local_variable. A model local variable declaration looks like:

#VARIABLE_NAME = MODEL_EXPRESSION;

It is possible to tag equations written in the model block. A tag can serve different purposes by allowing the user to attach arbitrary informations to each equation and to recover them at runtime. For instance, it is possible to name the equations with a name-tag, using a syntax like:

model;
+Model declaration · Dynare.jl

Model declaration

The model is declared inside a model block:

Block: model ;

Block: model (OPTIONS...);

The equations of the model are written in a block delimited by model and end keywords.

There must be as many equations as there are endogenous variables in the model, except when computing the unconstrained optimal policy with ramsey_model, ramsey_policy or discretionary_policy.

The syntax of equations must follow the conventions for MODEL_EXPRESSION as described in expr. Each equation must be terminated by a semicolon (';'). A normal equation looks like:

MODEL_EXPRESSION = MODEL_EXPRESSION;

When the equations are written in homogenous form, it is possible to omit the '=0' part and write only the left hand side of the equation. A homogenous equation looks like:

MODEL_EXPRESSION;

Inside the model block, Dynare allows the creation of model-local variables, which constitute a simple way to share a common expression between several equations. The syntax consists of a pound sign (#) followed by the name of the new model local variable (which must not be declared as in var-decl, but may have been declared by model_local_variable), an equal sign, and the expression for which this new variable will stand. Later on, every time this variable appears in the model, Dynare will substitute it by the expression assigned to the variable. Note that the scope of this variable is restricted to the model block; it cannot be used outside. To assign a LaTeX name to the model local variable, use the declaration syntax outlined by model_local_variable. A model local variable declaration looks like:

#VARIABLE_NAME = MODEL_EXPRESSION;

It is possible to tag equations written in the model block. A tag can serve different purposes by allowing the user to attach arbitrary informations to each equation and to recover them at runtime. For instance, it is possible to name the equations with a name-tag, using a syntax like:

model;
 
 [name = 'Budget constraint'];
 c + k = k^theta*A;
@@ -47,4 +47,4 @@
 
 model_replace('dummy');
   c^(-gam) = (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
-end;

In the above example, the dummy equation is replaced by a proper Euler equation.

Auxiliary variables

The model which is solved internally by Dynare is not exactly the model declared by the user. In some cases, Dynare will introduce auxiliary endogenous variables–-along with corresponding auxiliary equations–-which will appear in the final output.

The main transformation concerns leads and lags. Dynare will perform a transformation of the model so that there is only one lead and one lag on endogenous variables and no leads/lags on exogenous variables.

This transformation is achieved by the creation of auxiliary variables and corresponding equations. For example, if x(+2) exists in the model, Dynare will create one auxiliary variable AUX_ENDO_LEAD = x(+1), and replace x(+2) by AUX_ENDO_LEAD(+1).

A similar transformation is done for lags greater than 2 on endogenous (auxiliary variables will have a name beginning with AUX_ENDO_LAG), and for exogenous with leads and lags (auxiliary variables will have a name beginning with AUX_EXO_LEAD or AUX_EXO_LAG respectively).

Another transformation is done for the EXPECTATION operator. For each occurrence of this operator, Dynare creates an auxiliary variable defined by a new equation, and replaces the expectation operator by a reference to the new auxiliary variable. For example, the expression EXPECTATION(-1)(x(+1)) is replaced by AUX_EXPECT_LAG_1(-1), and the new auxiliary variable is declared as AUX_EXPECT_LAG_1 = x(+2).

Auxiliary variables are also introduced by the preprocessor for the ramsey_model and ramsey_policy commands. In this case, they are used to represent the Lagrange multipliers when first order conditions of the Ramsey problem are computed. The new variables take the form MULT_i, where i represents the constraint with which the multiplier is associated (counted from the order of declaration in the model block).

Auxiliary variables are also introduced by the differentiate_forward_vars option of the model block. The new variables take the form AUX_DIFF_FWRD_i, and are equal to x-x(-1) for some endogenous variable x.

Finally, auxiliary variables will arise in the context of employing the diff-operator.

Once created, all auxiliary variables are included in the set of endogenous variables. The output of decision rules (see below) is such that auxiliary variable names are replaced by the original variables they refer to.

The number of endogenous variables before the creation of auxiliary variables is stored in context.models[1].orig_endo_nbr, and the number of endogenous variables after the creation of auxiliary variables is stored in context.models[1].endogenous_nbr.

+end;

In the above example, the dummy equation is replaced by a proper Euler equation.

Auxiliary variables

The model which is solved internally by Dynare is not exactly the model declared by the user. In some cases, Dynare will introduce auxiliary endogenous variables–-along with corresponding auxiliary equations–-which will appear in the final output.

The main transformation concerns leads and lags. Dynare will perform a transformation of the model so that there is only one lead and one lag on endogenous variables and no leads/lags on exogenous variables.

This transformation is achieved by the creation of auxiliary variables and corresponding equations. For example, if x(+2) exists in the model, Dynare will create one auxiliary variable AUX_ENDO_LEAD = x(+1), and replace x(+2) by AUX_ENDO_LEAD(+1).

A similar transformation is done for lags greater than 2 on endogenous (auxiliary variables will have a name beginning with AUX_ENDO_LAG), and for exogenous with leads and lags (auxiliary variables will have a name beginning with AUX_EXO_LEAD or AUX_EXO_LAG respectively).

Another transformation is done for the EXPECTATION operator. For each occurrence of this operator, Dynare creates an auxiliary variable defined by a new equation, and replaces the expectation operator by a reference to the new auxiliary variable. For example, the expression EXPECTATION(-1)(x(+1)) is replaced by AUX_EXPECT_LAG_1(-1), and the new auxiliary variable is declared as AUX_EXPECT_LAG_1 = x(+2).

Auxiliary variables are also introduced by the preprocessor for the ramsey_model and ramsey_policy commands. In this case, they are used to represent the Lagrange multipliers when first order conditions of the Ramsey problem are computed. The new variables take the form MULT_i, where i represents the constraint with which the multiplier is associated (counted from the order of declaration in the model block).

Auxiliary variables are also introduced by the differentiate_forward_vars option of the model block. The new variables take the form AUX_DIFF_FWRD_i, and are equal to x-x(-1) for some endogenous variable x.

Finally, auxiliary variables will arise in the context of employing the diff-operator.

Once created, all auxiliary variables are included in the set of endogenous variables. The output of decision rules (see below) is such that auxiliary variable names are replaced by the original variables they refer to.

The number of endogenous variables before the creation of auxiliary variables is stored in context.models[1].orig_endo_nbr, and the number of endogenous variables after the creation of auxiliary variables is stored in context.models[1].endogenous_nbr.

diff --git a/dev/model-file/reporting/index.html b/dev/model-file/reporting/index.html new file mode 100644 index 0000000..cd1e938 --- /dev/null +++ b/dev/model-file/reporting/index.html @@ -0,0 +1,2 @@ + +Reporting · Dynare.jl

Dynare can generate PDF reports using \LaTeX

  • A report is made of
    • a title
    • a subtitle (optional)
    • pages
  • A page is made of sections
  • A section can be
    • a text paragraph
    • a listing of the model
    • a table
    • a graphic

Julia functions

Dynare.ReportType

Report(title::String; subtitle::String = "")

initialize empty report

Keyword arguments

  • title::String: Report title [required]
  • subtitle::String: Report subtitle
source
Dynare.add_page!Function

add_page!(report::Report, page::Page)

adds a page to a report

Keyword arguments

  • report::Report: report
  • page::Page: page to be added
source
Dynare.add_graph!Function

add_graph!(page::Page, graph::Graph)

adds a graph to a page

Keyword arguments

  • page::Page: page
  • graph::Graph: graph to be added
source
Dynare.add_model!Function

add_model!(page::Page; context::Context = context, lastline::Int = 0, format = 1) adds the lines of a *.mod file to pages

Keyword arguments

  • page::Page: page [required]
  • context::Context: context corresponding to the *.mod file (default: context)
  • lastline::Int: last line to be printed
  • format::Int: how to display parameter values 1: value is written after the parameter name 2: value is written below the parameter name
source
Dynare.add_paragraph!Function

add_paragraph!(page::Page, paragraph::String)

adds a graph to a page

Keyword arguments

  • page::Page: page
  • paragraph::String: paragraph to be added
source

@docs add_table! ````

`$@docs print$

diff --git a/dev/model-file/shocks/index.html b/dev/model-file/shocks/index.html index a682b5a..49d90e5 100644 --- a/dev/model-file/shocks/index.html +++ b/dev/model-file/shocks/index.html @@ -1,5 +1,5 @@ -Shocks on exgogenous variables · Dynare.jl

To study the effects of a temporary shock after which the system goes back to the original equilibrium (if the model is stable...) one uses a temporary shock. A temporary shock is a temporary change of value of one or several exogenous variables in the model. Temporary shocks are specified with the command shocks.

In a deterministic context, when one wants to study the transition of one equilibrium position to another, it is equivalent to analyze the consequences of a permanent shock. In Dynare this is done with initval, endval and steady.

In a stochastic framework, the exogenous variables take random values in each period. In Dynare, these random values follow a normal distribution with zero mean, but it belongs to the user to specify the variability of these shocks. The non-zero elements of the matrix of variance-covariance of the shocks can be entered with the shocks command.

Dynare commands

shocks

  • block: shocks ;
  • block: shocks(overwrite);
Options
  • overwrite: By default, if there are several shocks blocks

in the same .mod file, then they are cumulative: all the shocks declared in all the blocks are considered; however, if a shocks block is declared with the overwrite option, then it replaces all the previous shocks blocks.

In a deterministic context

For deterministic simulations, the shocks block specifies temporary changes in the value of exogenous variables. For permanent shocks, use an endval block.

The block should contain one or more occurrences of the following group of three lines:

var VARIABLE_NAME;
+Shocks on exgogenous variables · Dynare.jl

To study the effects of a temporary shock after which the system goes back to the original equilibrium (if the model is stable...) one uses a temporary shock. A temporary shock is a temporary change of value of one or several exogenous variables in the model. Temporary shocks are specified with the command shocks.

In a deterministic context, when one wants to study the transition of one equilibrium position to another, it is equivalent to analyze the consequences of a permanent shock. In Dynare this is done with initval, endval and steady.

In a stochastic framework, the exogenous variables take random values in each period. In Dynare, these random values follow a normal distribution with zero mean, but it belongs to the user to specify the variability of these shocks. The non-zero elements of the matrix of variance-covariance of the shocks can be entered with the shocks command.

Dynare commands

shocks

  • block: shocks ;
  • block: shocks(overwrite);
Options
  • overwrite: By default, if there are several shocks blocks

in the same .mod file, then they are cumulative: all the shocks declared in all the blocks are considered; however, if a shocks block is declared with the overwrite option, then it replaces all the previous shocks blocks.

In a deterministic context

For deterministic simulations, the shocks block specifies temporary changes in the value of exogenous variables. For permanent shocks, use an endval block.

The block should contain one or more occurrences of the following group of three lines:

var VARIABLE_NAME;
 periods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;
 values DOUBLE | (EXPRESSION)  [[,] DOUBLE | (EXPRESSION) ]...;

It is possible to specify shocks which last several periods and which can vary over time. The periods keyword accepts a list of several dates or date ranges, which must be matched by as many shock values in the values keyword. Note that a range in the periods keyword can be matched by only one value in the values keyword. If values represents a scalar, the same value applies to the whole range. If values represents a vector, it must have as many elements as there are periods in the range.

Note that shock values are not restricted to numerical constants: arbitrary expressions are also allowed, but you have to enclose them inside parentheses.

Example 1
shocks;
 
@@ -46,5 +46,5 @@
 stoch_simul(irf=0);
 
 forecast;

Julia function

scenario!()

The Julia function scenario!() lets you

  • declare shocks on exogenous variables as the shocks block
  • set the future value of endogenous variables (for conditional forecasts)
  • add the date at which the above information is made available to the agents in the model
Dynare.scenario!Function
scenario!(; name=Symbol, period::PeriodSinceEpoch, value<:Number, context::Context=context,
-  exogenous::Symbol=Symbol(), infoperiod::PeriodSinceEpoch=Undated(1))

Keyword arguments

  • name::Symbol: the name of an endogenous or exogenous variable [required]
  • period::PeriodSinceEpoch: the period in which the value is set
  • value<:PeriodSinceEpoch: the value of the endogenous or exogenous variables
  • context: the context is which the function operates (optional, default = context)
  • exogenous: when an endogenous variable is set, the name of the exogenous that must be freed (required when an endogenous variables is set)
  • infoperiod: the period in which the information is learned (optional, default = Undated(1))
source
Examples
scenario!(name = :e, value = 0.1, period = 2)

Exogenous variable e, takes value 0.1 in period 2.

scenario!(name = :y, value = 0.2, period=2, exogenous = :u)

Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model know at the beginning of period 1 that this will happen.

scenario!(infoperiod = 2, name = :y, value = 0.2, period = 2,
-                exogenous = :u)

Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model only learn at the beginning of period 2 that this will happen.

+ exogenous::Symbol=Symbol(), infoperiod::PeriodSinceEpoch=Undated(1))

Keyword arguments

  • name::Symbol: the name of an endogenous or exogenous variable [required]
  • period::PeriodSinceEpoch: the period in which the value is set
  • value<:PeriodSinceEpoch: the value of the endogenous or exogenous variables
  • context: the context is which the function operates (optional, default = context)
  • exogenous: when an endogenous variable is set, the name of the exogenous that must be freed (required when an endogenous variables is set)
  • infoperiod: the period in which the information is learned (optional, default = Undated(1))
source
Examples
scenario!(name = :e, value = 0.1, period = 2)

Exogenous variable e, takes value 0.1 in period 2.

scenario!(name = :y, value = 0.2, period=2, exogenous = :u)

Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model know at the beginning of period 1 that this will happen.

scenario!(infoperiod = 2, name = :y, value = 0.2, period = 2,
+                exogenous = :u)

Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model only learn at the beginning of period 2 that this will happen.

diff --git a/dev/model-file/steady-state/index.html b/dev/model-file/steady-state/index.html index 2df8710..34a6e41 100644 --- a/dev/model-file/steady-state/index.html +++ b/dev/model-file/steady-state/index.html @@ -1,5 +1,5 @@ -Steady state · Dynare.jl

There are three ways of computing the steady state (i.e. the static equilibrium) of a model. The first way is to provide the equations of the steady state in a steady_state_model block. When it is possible to derive the steady state by hand, this is the recommended way as it faster and more accurate.

The second way is to provide only a partial solution in the steady_state_model block and to compute the solution for the other variables numerically. Guess values for these other variables must be declared in a initval block. The less variables the better.

The third way is to compute the steady state value of all variables numerically. There is no steady_state_model block and a guess value must be declared for all variables. A guess value of 0 can be omitted, but be careful with variables appearing at the denominator of a fraction.

Providing the steady state to Dynare

If you know how to compute the steady state for your model, you can provide a steady_state_model block, which is described below in more details. The steady state file generated by Dynare will be called +FILENAME/output/julia/FILENAME_steadystate2.jl.

Note that this block allows for updating the parameters in each call of the function. This allows for example to calibrate a model to a labor supply of 0.2 in steady state by setting the labor disutility parameter to a corresponding value. They can also be used in estimation where some parameter may be a function of an estimated parameter and needs to be updated for every parameter draw. For example, one might want to set the capital utilization cost parameter as a function of the discount rate to ensure that capacity utilization is 1 in steady state. Treating both parameters as independent or not updating one as a function of the other would lead to wrong results. But this also means that care is required. Do not accidentally overwrite your parameters with new values as it will lead to wrong results.

Steady_state_model

Block: steady\_state\_model ;

When the analytical solution of the model is known, this command can be used to help Dynare find the steady state in a more efficient and reliable way, especially during estimation where the steady state has to be recomputed for every point in the parameter space.

Each line of this block consists of a variable (either an endogenous, a temporary variable or a parameter) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above). Each line therefore looks like:

VARIABLE_NAME = EXPRESSION;

Note that it is also possible to assign several variables at the same time, if the main function in the right hand side is a MATLAB/Octave function returning several arguments:

[ VARIABLE_NAME, VARIABLE_NAME... ] = EXPRESSION;

The steady_state_model block also works with deterministic models. An initval block and, when necessary, an endval block, is used to set the value of the exogenous variables. Each initval or endval block must be followed by steady to execute the function created by steady_state_model and set the initial, respectively terminal, steady state.

Example
var m P c e W R k d n l gy_obs gp_obs y dA;
+Steady state · Dynare.jl

There are three ways of computing the steady state (i.e. the static equilibrium) of a model. The first way is to provide the equations of the steady state in a steady_state_model block. When it is possible to derive the steady state by hand, this is the recommended way as it faster and more accurate.

The second way is to provide only a partial solution in the steady_state_model block and to compute the solution for the other variables numerically. Guess values for these other variables must be declared in a initval block. The less variables the better.

The third way is to compute the steady state value of all variables numerically. There is no steady_state_model block and a guess value must be declared for all variables. A guess value of 0 can be omitted, but be careful with variables appearing at the denominator of a fraction.

Providing the steady state to Dynare

If you know how to compute the steady state for your model, you can provide a steady_state_model block, which is described below in more details. The steady state file generated by Dynare will be called +FILENAME/output/julia/FILENAME_steadystate2.jl.

Note that this block allows for updating the parameters in each call of the function. This allows for example to calibrate a model to a labor supply of 0.2 in steady state by setting the labor disutility parameter to a corresponding value. They can also be used in estimation where some parameter may be a function of an estimated parameter and needs to be updated for every parameter draw. For example, one might want to set the capital utilization cost parameter as a function of the discount rate to ensure that capacity utilization is 1 in steady state. Treating both parameters as independent or not updating one as a function of the other would lead to wrong results. But this also means that care is required. Do not accidentally overwrite your parameters with new values as it will lead to wrong results.

Steady_state_model

Block: steady\_state\_model ;

When the analytical solution of the model is known, this command can be used to help Dynare find the steady state in a more efficient and reliable way, especially during estimation where the steady state has to be recomputed for every point in the parameter space.

Each line of this block consists of a variable (either an endogenous, a temporary variable or a parameter) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above). Each line therefore looks like:

VARIABLE_NAME = EXPRESSION;

Note that it is also possible to assign several variables at the same time, if the main function in the right hand side is a MATLAB/Octave function returning several arguments:

[ VARIABLE_NAME, VARIABLE_NAME... ] = EXPRESSION;

The steady_state_model block also works with deterministic models. An initval block and, when necessary, an endval block, is used to set the value of the exogenous variables. Each initval or endval block must be followed by steady to execute the function created by steady_state_model and set the initial, respectively terminal, steady state.

Example
var m P c e W R k d n l gy_obs gp_obs y dA;
 varexo e_a e_m;
 
 parameters alp bet gam mst rho psi del;
@@ -85,11 +85,11 @@
 
 steady(homotopy_mode = 1, homotopy_steps = 50);

Julia function

steadystate!

Dynare.steadystate!Function
steadystate!(; context::Context=context, display::Bool = true,
         maxit::Int = 50, nocheck::Bool = false, tolf::Float64 = cbrt(eps()),
-        tolx::Float64 = 0.0)

Keyword arguments

  • context::Context=context: context in which the simulation is computed
  • homotopy_steps::Int=0: number of homotopy steps
  • display::Bool=true: whether to display the results
  • maxit::Int=50 maximum number of iterations
  • nocheck::Bool=false: don't check the steady state
  • tolf::Float64=cbrt(eps()): tolerance for the norm of residualts
  • tolx::Float64=0: tolerance for the norm of the change in the result
source

Replace some equations during steady state computations

When there is no steady state file, Dynare computes the steady state by solving the static model, i.e. the model from the .mod file from which leads and lags have been removed.

In some specific cases, one may want to have more control over the way this static model is created. Dynare therefore offers the possibility to explicitly give the form of equations that should be in the static model.

More precisely, if an equation is prepended by a [static] tag, then it will appear in the static model used for steady state computation, but that equation will not be used for other computations. For every equation tagged in this way, you must tag another equation with [dynamic]: that equation will not be used for steady state computation, but will be used for other computations.

This functionality can be useful on models with a unit root, where there is an infinity of steady states. An equation (tagged [dynamic]) would give the law of motion of the nonstationary variable (like a random walk). To pin down one specific steady state, an equation tagged [static] would affect a constant value to the nonstationary variable. Another situation where the [static] tag can be useful is when one has only a partial closed form solution for the steady state.

Example

This is a trivial example with two endogenous variables. The second equation takes a different form in the static model:

var c k;
+        tolx::Float64 = 0.0)

Keyword arguments

  • context::Context=context: context in which the simulation is computed
  • homotopy_steps::Int=0: number of homotopy steps
  • display::Bool=true: whether to display the results
  • maxit::Int=50 maximum number of iterations
  • nocheck::Bool=false: don't check the steady state
  • tolf::Float64=cbrt(eps()): tolerance for the norm of residualts
  • tolx::Float64=0: tolerance for the norm of the change in the result
source

Replace some equations during steady state computations

When there is no steady state file, Dynare computes the steady state by solving the static model, i.e. the model from the .mod file from which leads and lags have been removed.

In some specific cases, one may want to have more control over the way this static model is created. Dynare therefore offers the possibility to explicitly give the form of equations that should be in the static model.

More precisely, if an equation is prepended by a [static] tag, then it will appear in the static model used for steady state computation, but that equation will not be used for other computations. For every equation tagged in this way, you must tag another equation with [dynamic]: that equation will not be used for steady state computation, but will be used for other computations.

This functionality can be useful on models with a unit root, where there is an infinity of steady states. An equation (tagged [dynamic]) would give the law of motion of the nonstationary variable (like a random walk). To pin down one specific steady state, an equation tagged [static] would affect a constant value to the nonstationary variable. Another situation where the [static] tag can be useful is when one has only a partial closed form solution for the steady state.

Example

This is a trivial example with two endogenous variables. The second equation takes a different form in the static model:

var c k;
 varexo x;
 ...
 model;
 c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
 [dynamic] c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
 [static] k = ((delt+bet)/(x*aa*alph))^(1/(alph-1));
-end;
+end; diff --git a/dev/model-file/syntax-elements/index.html b/dev/model-file/syntax-elements/index.html index 5c1b8e5..1460d30 100644 --- a/dev/model-file/syntax-elements/index.html +++ b/dev/model-file/syntax-elements/index.html @@ -1,5 +1,5 @@ -Syntax elements · Dynare.jl

Model File

Syntax elements

Conventions

A model file contains a list of commands and of blocks. Each command and each element of a block is terminated by a semicolon (;). Blocks are terminated by end;.

If Dynare encounters an unknown expression at the beginning of a line or after a semicolon, it will parse the rest of that line as native Julia code, even if there are more statements separated by semicolons present. To prevent cryptic error messages, it is strongly recommended to always only put one statement/command into each line and start a new line after each semicolon.[1]

Lines of codes can be commented out line by line or as a block. Single-line comments begin with // and stop at the end of the line. Multiline comments are introduced by /* and terminated by */.

Examples

// This is a single line comment
+Syntax elements · Dynare.jl

Model File

Syntax elements

Conventions

A model file contains a list of commands and of blocks. Each command and each element of a block is terminated by a semicolon (;). Blocks are terminated by end;.

If Dynare encounters an unknown expression at the beginning of a line or after a semicolon, it will parse the rest of that line as native Julia code, even if there are more statements separated by semicolons present. To prevent cryptic error messages, it is strongly recommended to always only put one statement/command into each line and start a new line after each semicolon.[1]

Lines of codes can be commented out line by line or as a block. Single-line comments begin with // and stop at the end of the line. Multiline comments are introduced by /* and terminated by */.

Examples

// This is a single line comment
 
 var x; // This is a comment about x
 
@@ -15,4 +15,4 @@
          0 &\quad\text{if }x=0\\
          1 &\quad\text{if }x>0
          \end{cases}
-  \end{aligned}\]

Note that this function is not continuous, hence not differentiable, at $x=0$. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at $x=0$ is equal to $0$. This assumption comes from the observation that both the right- and left-derivatives at this point exist and are equal to $0$, so we can remove the singularity by postulating that the derivative at $x=0$ is $0$.

Function: abs(x)

Absolute value.

Note that this continuous function is not differentiable at $x=0$. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at $x=0$ is equal to $0$ (even if the derivative does not exist). The rational for this mathematically unfounded definition, rely on the observation that the derivative of $\mathrm{abs}(x)$ is equal to $\mathrm{sign}(x)$ for any $x\neq 0$ in $\mathbb R$ and from the convention for the value of $\mathrm{sign}(x)$ at $x=0$).

Function: sin(x)

Function: cos(x)

Function: tan(x)

Function: asin(x)

Function: acos(x)

Function: atan(x)

Trigonometric functions.

Function: sinh(x)

Function: cosh(x)

Function: tanh(x)

Function: asinh(x)

Function: acosh(x)

Function: atanh(x)

Hyperbolic functions.

Function: max(a, b)

Function: min(a, b)

Maximum and minimum of two reals.

Note that these functions are differentiable everywhere except on a line of the 2-dimensional real plane defined by $a=b$. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivative of these functions with respect to the first (resp. the second) argument is equal to $1$ (resp. to $0$) (i.e. the derivatives at the kink are equal to the derivatives observed on the half-plane where the function is equal to its first argument).

Function: normcdf(x)

Function: normcdf(x, mu, sigma)

Gaussian cumulative density function, with mean mu and standard deviation sigma. Note that normcdf(x) is equivalent to normcdf(x,0,1).

Function: normpdf(x) Function: normpdf(x, mu, sigma)

Gaussian probability density function, with mean mu and standard deviation sigma. Note that normpdf(x) is equivalent to normpdf(x,0,1).

Function: erf(x)

Gauss error function.

Function: erfc(x)

Complementary error function, i.e. $\mathrm{erfc}(x) = 1-\mathrm{erf}(x)$.

A few words of warning in stochastic context

The use of the following functions and operators is strongly discouraged in a stochastic context: max, min, abs, sign, <, >, <=, >=, ==, !=.

The reason is that the local approximation used by stoch_simul or estimation will by nature ignore the non-linearities introduced by these functions if the steady state is away from the kink. And, if the steady state is exactly at the kink, then the approximation will be bogus because the derivative of these functions at the kink is bogus (as explained in the respective documentations of these functions and operators).

Note that extended_path is not affected by this problem, because it does not rely on a local approximation of the mode.

Footnotes

  • 1A .mod file must have lines that end with a line feed character, which is not commonly visible in text editors. Files created on Windows and Unix-based systems have always conformed to this requirement, as have files created on OS X and macOS. Files created on old, pre-OS X Macs used carriage returns as end of line characters. If you get a Dynare parsing error of the form ERROR: <<mod file>>: line 1, cols 341-347: syntax error,... and there's more than one line in your .mod file, know that it uses the carriage return as an end of line character. To get more helpful error messages, the carriage returns should be changed to line feeds.
  • 2Note that arbitrary Julia expressions can be put in a .mod file, but those expressions have to be on separate lines, generally at the end of the file for post-processing purposes. They are not interpreted by Dynare, and are simply passed on unmodified to Julia. Those constructions are not addresses in this section.
+ \end{aligned}\]

Note that this function is not continuous, hence not differentiable, at $x=0$. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at $x=0$ is equal to $0$. This assumption comes from the observation that both the right- and left-derivatives at this point exist and are equal to $0$, so we can remove the singularity by postulating that the derivative at $x=0$ is $0$.

Function: abs(x)

Absolute value.

Note that this continuous function is not differentiable at $x=0$. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at $x=0$ is equal to $0$ (even if the derivative does not exist). The rational for this mathematically unfounded definition, rely on the observation that the derivative of $\mathrm{abs}(x)$ is equal to $\mathrm{sign}(x)$ for any $x\neq 0$ in $\mathbb R$ and from the convention for the value of $\mathrm{sign}(x)$ at $x=0$).

Function: sin(x)

Function: cos(x)

Function: tan(x)

Function: asin(x)

Function: acos(x)

Function: atan(x)

Trigonometric functions.

Function: sinh(x)

Function: cosh(x)

Function: tanh(x)

Function: asinh(x)

Function: acosh(x)

Function: atanh(x)

Hyperbolic functions.

Function: max(a, b)

Function: min(a, b)

Maximum and minimum of two reals.

Note that these functions are differentiable everywhere except on a line of the 2-dimensional real plane defined by $a=b$. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivative of these functions with respect to the first (resp. the second) argument is equal to $1$ (resp. to $0$) (i.e. the derivatives at the kink are equal to the derivatives observed on the half-plane where the function is equal to its first argument).

Function: normcdf(x)

Function: normcdf(x, mu, sigma)

Gaussian cumulative density function, with mean mu and standard deviation sigma. Note that normcdf(x) is equivalent to normcdf(x,0,1).

Function: normpdf(x) Function: normpdf(x, mu, sigma)

Gaussian probability density function, with mean mu and standard deviation sigma. Note that normpdf(x) is equivalent to normpdf(x,0,1).

Function: erf(x)

Gauss error function.

Function: erfc(x)

Complementary error function, i.e. $\mathrm{erfc}(x) = 1-\mathrm{erf}(x)$.

A few words of warning in stochastic context

The use of the following functions and operators is strongly discouraged in a stochastic context: max, min, abs, sign, <, >, <=, >=, ==, !=.

The reason is that the local approximation used by stoch_simul or estimation will by nature ignore the non-linearities introduced by these functions if the steady state is away from the kink. And, if the steady state is exactly at the kink, then the approximation will be bogus because the derivative of these functions at the kink is bogus (as explained in the respective documentations of these functions and operators).

Note that extended_path is not affected by this problem, because it does not rely on a local approximation of the mode.

Footnotes

  • 1A .mod file must have lines that end with a line feed character, which is not commonly visible in text editors. Files created on Windows and Unix-based systems have always conformed to this requirement, as have files created on OS X and macOS. Files created on old, pre-OS X Macs used carriage returns as end of line characters. If you get a Dynare parsing error of the form ERROR: <<mod file>>: line 1, cols 341-347: syntax error,... and there's more than one line in your .mod file, know that it uses the carriage return as an end of line character. To get more helpful error messages, the carriage returns should be changed to line feeds.
  • 2Note that arbitrary Julia expressions can be put in a .mod file, but those expressions have to be on separate lines, generally at the end of the file for post-processing purposes. They are not interpreted by Dynare, and are simply passed on unmodified to Julia. Those constructions are not addresses in this section.
diff --git a/dev/model-file/variable-declarations/index.html b/dev/model-file/variable-declarations/index.html index 40d60dd..ddc1b24 100644 --- a/dev/model-file/variable-declarations/index.html +++ b/dev/model-file/variable-declarations/index.html @@ -1,5 +1,5 @@ -Variables and parameters declaration · Dynare.jl

While Dynare allows the user to choose their own variable names, there are some restrictions to be kept in mind. First, variables and parameters must not have the same name as Dynare commands or built-in functions. In this respect, Dynare is not case-sensitive. For example, do not use Ln or Sigma_e to name your variable. Not conforming to this rule might yield hard-to-debug error messages or crashes.

var

command

var VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRINGNAME=QUOTED_STRING)]...;
var (deflator=MODEL_EXPR) VAR_NAME (... same options apply) var(log,deflator=MODEL_EXPR) VAR_NAME (... same options apply)
var (log_deflator=MODEL_EXPR) VAR_NAME (... same options apply)

This required command declares the endogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable or, if it is nonstationary, provide information regarding its deflator. The variables in the list can be separated by spaces or by commas. var commands can appear several times in the file and Dynare will concatenate them.

If the model is nonstationary and is to be written as such in the model block, Dynare will need the trend deflator for the appropriate endogenous variables in order to stationarize the model. The trend deflator must be provided alongside the variables that follow this trend.

Options

  • log

    In addition to the endogenous variable(s) thus declared, this option also triggers the creation of auxiliary variable(s) equal to the log of the corresponding endogenous variable(s). For example, given a var(log) y statement, two endogenous will be created (y and LOG_y), and an auxiliary equation linking the two will also be added (equal to LOG_y = log(y)). Moreover, every occurence of y in the model will be replaced by exp(LOG_y). This option is for example useful when one wants to perform a loglinear approximation of some variable(s) in the context of a first-order stochastic approximation; or when one wants to ensure the variable(s) stay(s) in the definition domain of the function defining the steady state or the dynamic residuals when the nonlinear solver is used.

  • deflator = MODEL_EXPR

    The expression used to detrend an endogenous variable. All trend variables, endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the trend_var, log_trend_var, var and parameters commands. The deflator is assumed to be multiplicative; for an additive deflator, use log_deflator. This option can be used together with the log option (the latter must come first).

  • log_deflator = MODEL_EXPR

    Same as deflator, except that the deflator is assumed to be additive instead of multiplicative (or, to put it otherwise, the declared variable is equal to the log of a variable with a multiplicative trend). This option cannot be used together with the log option, because it would not make much sense from an economic point of view (the corresponding auxiliary variable would correspond to the log taken two times on a variable with a multiplicative trend).

  • long_name = QUOTED_STRING

    This is the long version of the variable name. Its value is stored in M_.endo_names_long (a column cell array, in the same order as M_.endo_names). In case multiple long_name options are provided, the last one will be used. Default: VAR_NAME.

Example

var c gnp cva 
+Variables and parameters declaration · Dynare.jl

While Dynare allows the user to choose their own variable names, there are some restrictions to be kept in mind. First, variables and parameters must not have the same name as Dynare commands or built-in functions. In this respect, Dynare is not case-sensitive. For example, do not use Ln or Sigma_e to name your variable. Not conforming to this rule might yield hard-to-debug error messages or crashes.

var

command

var VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRINGNAME=QUOTED_STRING)]...;
var (deflator=MODEL_EXPR) VAR_NAME (... same options apply) var(log,deflator=MODEL_EXPR) VAR_NAME (... same options apply)
var (log_deflator=MODEL_EXPR) VAR_NAME (... same options apply)

This required command declares the endogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable or, if it is nonstationary, provide information regarding its deflator. The variables in the list can be separated by spaces or by commas. var commands can appear several times in the file and Dynare will concatenate them.

If the model is nonstationary and is to be written as such in the model block, Dynare will need the trend deflator for the appropriate endogenous variables in order to stationarize the model. The trend deflator must be provided alongside the variables that follow this trend.

Options

  • log

    In addition to the endogenous variable(s) thus declared, this option also triggers the creation of auxiliary variable(s) equal to the log of the corresponding endogenous variable(s). For example, given a var(log) y statement, two endogenous will be created (y and LOG_y), and an auxiliary equation linking the two will also be added (equal to LOG_y = log(y)). Moreover, every occurence of y in the model will be replaced by exp(LOG_y). This option is for example useful when one wants to perform a loglinear approximation of some variable(s) in the context of a first-order stochastic approximation; or when one wants to ensure the variable(s) stay(s) in the definition domain of the function defining the steady state or the dynamic residuals when the nonlinear solver is used.

  • deflator = MODEL_EXPR

    The expression used to detrend an endogenous variable. All trend variables, endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the trend_var, log_trend_var, var and parameters commands. The deflator is assumed to be multiplicative; for an additive deflator, use log_deflator. This option can be used together with the log option (the latter must come first).

  • log_deflator = MODEL_EXPR

    Same as deflator, except that the deflator is assumed to be additive instead of multiplicative (or, to put it otherwise, the declared variable is equal to the log of a variable with a multiplicative trend). This option cannot be used together with the log option, because it would not make much sense from an economic point of view (the corresponding auxiliary variable would correspond to the log taken two times on a variable with a multiplicative trend).

  • long_name = QUOTED_STRING

    This is the long version of the variable name. Its value is stored in M_.endo_names_long (a column cell array, in the same order as M_.endo_names). In case multiple long_name options are provided, the last one will be used. Default: VAR_NAME.

Example

var c gnp cva 
           cca (long_name=`Consumption CA');
 var(deflator=A) i b;
 var c $C$ (long_name=`Consumption');

varexo

Command:

 varexo VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];
This optional command declares the exogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable. Exogenous variables are required if the user wants to be able to apply shocks to her model. The variables in the list can be separated by spaces or by commas. varexo commands can appear several times in the file and Dynare will concatenate them.

Options

  • long_name = QUOTED_STRING

Example

    varexo m gov;

Remarks

An exogenous variable is an innovation, in the sense that this
@@ -55,4 +55,4 @@
   k(1) = i|e + (1-delta|p)*k;
   y|e = k|e^alpha|p;
   ...
-end;
+end;
diff --git a/dev/objects.inv b/dev/objects.inv index 9de85eeadeaef4f42a545373ca50edf4e5b0a59c..467c5e4e5709194b1972ccc93a710b24b736b094 100644 GIT binary patch delta 1795 zcmV+e2mJV~4)6|;K>;?ALPUQsNCUJ$*+p_{a&u!FaZw{i?BpuY5_gx4B&sB}-p#M? zkQ60S5~bC)7sC=~9;x|!!(~-Yk4UQgL(VgV-y-yhmo#CORHP_~V!Xnn%5lc4E!#E1 zyz%AdB{%5KTSu^tKKkp4XsU`;JDi^?BB&1>u58d3`;4y5b5io07I=Tl3c8V}N|7U` z1ubc%qz@98+Mq}C0=XAH;(-W8o(qa|nia$zHHJGWyFuUD*V24+4GSezR7m8B`CHn5 zy~W6OBe@N_*RNu@Qc;qhFgQWcm}NW>FpGIY<|zQ$^Xz-nxMmTQtq`1^9(R04E8a-t zEEJeH*VZUm#iU{xmaKnlidi#9UAa|iDQHt44NKR72BG$XJC z`$P`eOKi|>|KOttT5~aj(XB(yx_^_BWP*eFGAbnxO%$v^G<$!~dXs`wyN2v&0xn?B zX<+4oJVWHq+WGZQ2q!faTbijmFm=q#w$M6G6GLJ8AjEp#l6-4#Y202u}3DJ1tzp%@&csgyWj zv->iNuVYUvlg|)?L~*e)WF8?-br&qzk?P)B)^-_6syboV7V2sl$DEDh78@CCG{8m< zJMjwtyc=+0doyO$0h~XMjzLQY6{~=H1qT7ADNQLnJIjAts8$i|t>GX7ArNRa;r#{T z0*DR*^$^Kd;7gEvAg@2<0cxG|JiZYE{@%j_R4cjk)kUCd1(QFUf)QMBUP}xmS2hxxl)=5_%;Hj3 z860FqEslQ`LcQV4qOO5ClYFhWb*^pIiw-_P|7n=;*yIWr2ZDT%RTKu zj<0+2dya!TFk@xu@inBlyL9KLE5I(5dr~z+FMtkcxO!#7y3;^bBY8U2 zO!v=bqL_@$(n=#MoqTT8dl`J8S?-o+$Q5}tnj-^=gm~SyuCDVggwTfkp4R(b9 z7a4zC#J8x$g)f}qU^1f+=ZwGl`Ikis;bh;ud;8|y?{D6{?@C1ul@u8FVL26Sh3Msz zKN_G4`lGj(kankyI_>11$;|PS<>P>`<0LY89e_7fUqPXV z%8|#;bVjl|i2kIuKbZFL>dYqMsel8)bzgr?X`gCt%gJDLT`#)>BF*zA8`ljJ=ijJ! z2E`KGlogE}cd(IHoCfMNbdlrFannsrl@RLHj;88V$9wmAZR3fOa;{0}^_B+?Z-~wg zo$)PEH|5*R&3nlqZQ!_EA%Wjy#F$Fj^onYl)uKRUP^^hr>()5ek z=G>y~T0NxobU$!<$tPZN#cL=Kvt4XRMV%TlYNK|1b|avg;*b)uf<0iA9eW1;)fG~j~`MpaPeie zIiOY-7FtvA$ zuHsbzA58>axPTqvx9H=ESEIW&*`Xtg-d-mCmT_Z2Jzo7?d~i$-%~p?AwWF_bO=r)6 zhUGx*OOog5PLO&(gVW!ezaDA@SXw2uX-#L~{12MY3?S`2y~Z+RCUz{(E;W3iShu@T z3AP1}-UtaSJ@tNfm;v>Fop^UWhY{>zem8KnW)6K&l%~`JVADv0JM0T8B3DY!~aJjwML?N2uGqz>xOSarf`yE(j= l!FD0i<#`Z`e!Y!RU41ws5HWjNbE$u@;<9LPUSCNCUJ$*+p_{b8}-GaZw{d?BpuY5_io;B2|)F@8;Kc zNQx3EiPG-2m%uB|Jd*SIhGD#<2c&fQt`r5rZxH$*YML>wG^r}0nc$f45*LDR*{+rL zODMlAxj}cqI)ZidK3vaa%Q@paTpl@*Gz5-UHt4hajjrwQtQIA$@Rom7bfb=3lLMv| zttrpLQOT53I$@}mhR7B zF|pl5ZiDX4rxdQzl$1vdPS7-EnLq^0Vt*m~D*}2J#kZt!?II{UAvirf?8J_8(JJIE z6q&d*)~Fe0O0xnhR=0oEqM4KO8+08mp?wbbtW=RFh}=axz4{U1 ztf6vC3!R(eDYkpoxf0cW0VEwQ7Voy@#SmL^yv9w?OM@_#sb2sAqT9n^m)BBFRE*6JXr=|QJW>}m#p z-a%(TgC^=UGaG+Om>wEwVrlBGIPw6nNd)JF&_>LJSfu zvcvM<1QAo)Pv zT;!9az31_bl<@C8{D5ku)@~jFp%4gJAmo8E+n(_)-1?l*aZTN5Wy*KtgmT!vts8-J zv65o2tc&<__I0`lbe&-KXIn9XDWs@Sy@-A+I<)R#wxzapH`sf*g?RMQ%9L++V((Ng1vGO zxJ3C8T-uc_7wn(umI7cw@jc<~*bATo8opk+uj}0^Zvz;j>Q?qo^$Vq1( zTYY%~cgjHqUuc%Q^%?Mtyqe5`kwo?|GsB&D;qe^TML8{V8&fKW_L*iOci;&_m@YQ)fCMSv|yXQr91B zd-&nRCK9NC1HpA)Y-yisZtKZlb$u_p10sJd%C?x+4IAfQseA&(8r)P=t(tbQiC4S^ z>NQM}6HjT=%}tdM>U>9YeQeUb`?R+4NJ+iaB+Pop1II5sCx_1Tm8YNfl=Z=SNY3QP zfMJXB5S86?+pPPiY~KD@xZ$OFHKOdh!B296NkBw;!D|~(9Ad_z)5d=v zxII0HOJboW-)L?p=6u}^3plm_=e84^IhdP%T~ae-s|pJ`JOpnpo#6vG_g z)^ORHC%Tyao3XpqWF^)|=j-s1!AE~RK63c+L=fV~lnh*aS#6G}7&yF3S}31X?(Nsy z^6B%cDby#RFOq$qt8J5@!`Vk}`R%qkVpkdci#fhNp+qK~H^6ok)5D?ww#)P!2-qdz z0aKHwZnXSw32z_GVjg(ryIG{%(>B9-&zm1_8J{0;UzmROjgAXm!KI1BD-VCLWBd+% zI`JBG-zIx>gUTMCDe?MUkROC->dWEKb!;7DG+7rR5d!z<&l<( Vui=7uBb51%FdA&gF6W3b2UZDU0 diff --git a/dev/running-dynare/index.html b/dev/running-dynare/index.html index 84f012d..64eb182 100644 --- a/dev/running-dynare/index.html +++ b/dev/running-dynare/index.html @@ -1,3 +1,3 @@ -Running Dynare · Dynare.jl

Running Dynare

In order to give instructions to Dynare, the user has to write a model file whose filename extension must be .mod. This file contains the description of the model and the computing tasks required by the user. Its contents are described in The model file

Dynare invocation

Once the model file is written, Dynare is invoked using the @dynare Julia macro (with the filename of the .mod given as argument).

In practice, the handling of the model file is done in two steps: in the first one, the model and the processing instructions written by the user in a model file are interpreted and the proper Julia instructions are generated; in the second step, the program actually runs the computations. Both steps are triggered automatically by the @dynare macro:

context = @dynare "FILENAME [.mod ]" [OPTIONS... ]";

This command launches Dynare and executes the instructions included in FILENAME.mod. This user-supplied file contains the model and the processing instructions, as described in The model file. The options, listed below, can be passed on the command line, following the name of the .mod file or in the first line of the .mod file itself (see below).

Dynare begins by launching the preprocessor on the .mod file.

Options

  • debug

    Instructs the preprocessor to write some debugging information about the scanning and parsing of the .mod file.

  • notmpterms

    Instructs the preprocessor to omit temporary terms in the static and dynamic files; this generally decreases performance, but is used for debugging purposes since it makes the static and dynamic files more readable.

  • savemacro\[=FILENAME\]

    Instructs Dynare to save the intermediary file which is obtained after macro processing (see (@ref "Macro processing language")); the saved output will go in the file specified, or if no file is specified in FILENAME-macroexp.mod. See the (@ref "note on quotes") for info on passing a FILENAME argument containing spaces.

  • onlymacro

    Instructs the preprocessor to only perform the macro processing step, and stop just after. Useful for debugging purposes or for using the macro processor independently of the rest of Dynare toolbox.

  • linemacro

    Instructs the macro preprocessor include @#line directives specifying the line on which macro directives were encountered and expanded from. Only useful in conjunction with savemacro <savemacro[=FILENAME]>.

  • onlymodel

    Instructs the preprocessor to print only information about the model in the driver file; no Dynare commands (other than the shocks statement and parameter initializations) are printed and hence no computational tasks performed. The same ancillary files are created as would otherwise be created (dynamic, static files, etc.).

  • nolog

    Instructs Dynare to no create a logfile of this run in FILENAME.log. The default is to create the logfile.

  • output=second\|third

    Instructs the preprocessor to output derivatives of the dynamic model at least up to the given order.

  • language=matlab\|julia

Instructs the preprocessor to write output for MATLAB or Julia. Default: MATLAB

  • params\_derivs\_order=0\|1\|2

    When (@ref "identification"), (@ref "dynaresensitivity") (with identification), or (@ref "estimationcmd") are present, this option is used to limit the order of the derivatives with respect to the parameters that are calculated by the preprocessor. 0 means no derivatives, 1 means first derivatives, and 2 means second derivatives. Default: 2

  • transform\_unary\_ops

    Transform the following operators in the model block into auxiliary variables: exp, log, log10, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, sqrt, cbrt, abs, sign, erf. Default: no obligatory transformation

  • json = parse\|transform\|compute

    Causes the preprocessor to output a version of the .mod file in JSON format to <<M_.fname>>/model/json/. When the JSON output is created depends on the value passed. These values represent various steps of processing in the preprocessor.

    If parse is passed, the output will be written after the parsing of the .mod file to a file called FILENAME.json but before file has been checked (e.g. if there are unused exogenous in the model block, the JSON output will be created before the preprocessor exits).

If check is passed, the output will be written to a file called FILENAME.json after the model has been checked.

If transform is passed, the JSON output of the transformed model (maximum lead of 1, minimum lag of -1, expectation operators substituted, etc.) will be written to a file called FILENAME.json and the original, untransformed model will be written in FILENAME_original.json.

And if compute is passed, the output is written after the computing pass. In this case, the transformed model is written to FILENAME.json, the original model is written to FILENAME_original.json, and the dynamic and static files are written to FILENAME_dynamic.json and FILENAME_static.json.

  • jsonstdout

    Instead of writing output requested by json to files, write to standard out, i.e. to the Julia command window (and the log-file).

  • onlyjson

    Quit processing once the output requested by json has been written.

  • jsonderivsimple

    Print a simplified version (excluding variable name(s) and lag information) of the static and dynamic files in FILENAME_static.json and FILENAME_dynamic..

  • warn\_uninit

Display a warning for each variable or parameter which is not initialized. See (@ref "Parameter initialization"), or (@ref "loadparamsandsteadystate") for initialization of parameters. See (@ref "Initial and Terminal conditions"), or (@ref "loadparamsandsteadystate") for initialization of endogenous and exogenous variables.

  • nopreprocessoroutput

    Prevent Dynare from printing the output of the steps leading up to the preprocessor as well as the preprocessor output itself.

  • -DMACRO\_VARIABLE\[=MACRO\_EXPRESSION\]

    Defines a macro-variable from the command line (the same effect as using the Macro directive @#define in a model file, see (@ref "Macro processing language")). See the (@ref "note on quotes") for info on passing a MACRO_EXPRESSION argument containing spaces. Note that an expression passed on the command line can reference variables defined before it. If MACRO_EXPRESSION is omitted, the variable is assigned the true logical value.

    Example

    Call dynare with command line defines

    julia julia> @dynare <<modfile.mod>> -DA=true '-DB="A string with space"' -DC=[1,2,3] '-DD=[ i in C when i > 1 ]' -DE;

  • -I\<\<path\>\>

    Defines a path to search for files to be included by the macro processor (using the @#include command). Multiple -I flags can be passed on the command line. The paths will be searched in the order that the -I flags are passed and the first matching file will be used. The flags passed here take priority over those passed to @#includepath. See the (@ref "note on quotes") for info on passing a <<path>> argument containing spaces.

  • nostrict

    Allows Dynare to issue a warning and continue processing when

  1. there are more endogenous variables than equations.
  2. an undeclared symbol is assigned in initval or endval.
  3. an undeclared symbol is found in the model block in this case, it is automatically declared exogenous.
  4. exogenous variables were declared but not used in the model block.
  • stochastic

    Tells Dynare that the model to be solved is stochastic. If no Dynare commands related to stochastic models (stoch_simul, estimation, ...) are present in the .mod file, Dynare understands by default that the model to be solved is deterministic.

  • exclude\_eqs=\<\<equation\_tags\_to\_exclude\>\>

    Tells Dynare to exclude all equations specified by the argument. As a .mod file must have the same number of endogenous variables as equations, when ***exclude_eqs*** is passed, certain rules are followed for excluding endogenous variables. If the endogenous tag has been set for the excluded equation, the variable it specifies is excluded. Otherwise, if the left hand side of the excluded equation is an expression that contains only one endogenous variable, that variable is excluded. If neither of these conditions hold, processing stops with an error. If an endogenous variable has been excluded by the ***exclude_eqs*** option and it exists in an equation that has not been excluded, it is transformed into an exogenous variable.

    To specify which equations to exclude, you must pass the argument <<equation_tags_to_exclude>>. This argument takes either a list of equation tags specifying the equations to be excluded or a filename that contains those tags.

If <<equation_tags_to_exclude>> is a list of equation tags, it can take one of the following forms:

  1. Given a single argument, e.g. exclude_eqs=eq1, the equation with the tag [name='eq1'] will be excluded. Note that if there is a file called eq1 in the current directory, Dynare will instead try to open this and read equations to exclude from it (see info on filename argument to exclude_eqs below). Further note that if the tag value contains a space, you must use the variant specified in 2 below, i.e. exclude_eqs=[eq 1].
  2. Given two or more arguments, e.g. exclude_eqs=[eq1, eq 2], the equations with the tags [name='eq1'] and [name='eq 2'] will be excluded.
  3. If you\'d like to exclude equations based on another tag name (as opposed to the default name), you can pass the argument as either e.g. exclude_eqs=[tagname=a tag] if a single equation with tag [tagname='a tag'] is to be excluded or as e.g. exclude_eqs=[tagname=(a tag, 'a tag with a, comma')] if more than one equation with tags [tagname='a tag'] and [tagname='a tag with a, comma'] will be excluded (note the parenthesis, which are required when more than one equation is specified). Note that if the value of a tag contains a comma, it must be included inside single quotes.

If <<equation_tags_to_exclude>> is a filename, the file can take one of the following forms:

  1. One equation per line of the file, where every line represents the value passed to the name tag. e.g., a file such as: julia eq1 eq 2 would exclude equations with tags [name='eq1'] and [name='eq 2'].

  2. One equation per line of the file, where every line after the first line represents the value passed to the tag specified by the first line. e.g., a file such as: julia tagname= a tag a tag with a, comma would exclude equations with tags [tagname='a tag'] and [tagname='a tag with a, comma']. Here note that the first line must end in an equal sign.

  • include\_eqs=\<\<equation\_tags\_to\_include\>\>

    Tells Dynare to run with only those equations specified by the argument; in other words, Dynare will exclude all equations not specified by the argument. The argument <<equation_tags_to_include>> is specified in the same way as the argument to exclude_eqs <exclude_eqs>. The functionality of include_eqs is to find which equations to exclude then take actions in accord with (@ref "exclude_eqs").

  • nocommutativity

This option tells the preprocessor not to use the commutativity of addition and multiplication when looking for common subexpressions. As a consequence, when using this option, equations in various outputs (LaTeX, JSON...) will appear as the user entered them (without terms or factors swapped). Note that using this option may have a performance impact on the preprocessing stage, though it is likely to be small.

These options can be passed to the preprocessor by listing them after the name of the .mod file. They can alternatively be defined in the first line of the .mod file, this avoids typing them on the command line each time a .mod file is to be run. This line must be a Dynare one-line comment (i.e. must begin with //) and the options must be whitespace separated between --+ options: and +--. Note that any text after the +-- will be discarded. As in the command line, if an option admits a value the equal symbol must not be surrounded by spaces. For instance json = compute is not correct, and should be written json=compute. The nopathchange option cannot be specified in this way, it must be passed on the command-line.

Understanding Preprocessor Error Messages

If the preprocessor runs into an error while processing your .mod file, it will issue an error. Due to the way that a parser works, sometimes these errors can be misleading. Here, we aim to demystify these error messages.

The preprocessor issues error messages of the form:

  1. ERROR: <<file.mod>>: line A, col B: <<error message>>
  2. ERROR: <<file.mod>>: line A, cols B-C: <<error message>>
  3. ERROR: <<file.mod>>: line A, col B - line C, col D: <<error message>>

The first two errors occur on a single line, with error two spanning multiple columns. Error three spans multiple rows.

Often, the line and column numbers are precise, leading you directly to the offending syntax. Infrequently however, because of the way the parser works, this is not the case. The most common example of misleading line and column numbers (and error message for that matter) is the case of a missing semicolon, as seen in the following example:

varexo a, b
-parameters c, ...;

In this case, the parser doesn't know a semicolon is missing at the end of the varexo command until it begins parsing the second line and bumps into the parameters command. This is because we allow commands to span multiple lines and, hence, the parser cannot know that the second line will not have a semicolon on it until it gets there. Once the parser begins parsing the second line, it realizes that it has encountered a keyword, parameters, which it did not expect. Hence, it throws an error of the form: ERROR: <<file.mod>>: line 2, cols 0-9: syntax error, unexpected PARAMETERS. In this case, you would simply place a semicolon at the end of line one and the parser would continue processing.

+Running Dynare · Dynare.jl

Running Dynare

In order to give instructions to Dynare, the user has to write a model file whose filename extension must be .mod. This file contains the description of the model and the computing tasks required by the user. Its contents are described in The model file

Dynare invocation

Once the model file is written, Dynare is invoked using the @dynare Julia macro (with the filename of the .mod given as argument).

In practice, the handling of the model file is done in two steps: in the first one, the model and the processing instructions written by the user in a model file are interpreted and the proper Julia instructions are generated; in the second step, the program actually runs the computations. Both steps are triggered automatically by the @dynare macro:

context = @dynare "FILENAME [.mod ]" [OPTIONS... ]";

This command launches Dynare and executes the instructions included in FILENAME.mod. This user-supplied file contains the model and the processing instructions, as described in The model file. The options, listed below, can be passed on the command line, following the name of the .mod file or in the first line of the .mod file itself (see below).

Dynare begins by launching the preprocessor on the .mod file.

Options

  • debug

    Instructs the preprocessor to write some debugging information about the scanning and parsing of the .mod file.

  • notmpterms

    Instructs the preprocessor to omit temporary terms in the static and dynamic files; this generally decreases performance, but is used for debugging purposes since it makes the static and dynamic files more readable.

  • savemacro\[=FILENAME\]

    Instructs Dynare to save the intermediary file which is obtained after macro processing (see (@ref "Macro processing language")); the saved output will go in the file specified, or if no file is specified in FILENAME-macroexp.mod. See the (@ref "note on quotes") for info on passing a FILENAME argument containing spaces.

  • onlymacro

    Instructs the preprocessor to only perform the macro processing step, and stop just after. Useful for debugging purposes or for using the macro processor independently of the rest of Dynare toolbox.

  • linemacro

    Instructs the macro preprocessor include @#line directives specifying the line on which macro directives were encountered and expanded from. Only useful in conjunction with savemacro <savemacro[=FILENAME]>.

  • onlymodel

    Instructs the preprocessor to print only information about the model in the driver file; no Dynare commands (other than the shocks statement and parameter initializations) are printed and hence no computational tasks performed. The same ancillary files are created as would otherwise be created (dynamic, static files, etc.).

  • nolog

    Instructs Dynare to no create a logfile of this run in FILENAME.log. The default is to create the logfile.

  • output=second\|third

    Instructs the preprocessor to output derivatives of the dynamic model at least up to the given order.

  • language=matlab\|julia

Instructs the preprocessor to write output for MATLAB or Julia. Default: MATLAB

  • params\_derivs\_order=0\|1\|2

    When (@ref "identification"), (@ref "dynaresensitivity") (with identification), or (@ref "estimationcmd") are present, this option is used to limit the order of the derivatives with respect to the parameters that are calculated by the preprocessor. 0 means no derivatives, 1 means first derivatives, and 2 means second derivatives. Default: 2

  • transform\_unary\_ops

    Transform the following operators in the model block into auxiliary variables: exp, log, log10, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, sqrt, cbrt, abs, sign, erf. Default: no obligatory transformation

  • json = parse\|transform\|compute

    Causes the preprocessor to output a version of the .mod file in JSON format to <<M_.fname>>/model/json/. When the JSON output is created depends on the value passed. These values represent various steps of processing in the preprocessor.

    If parse is passed, the output will be written after the parsing of the .mod file to a file called FILENAME.json but before file has been checked (e.g. if there are unused exogenous in the model block, the JSON output will be created before the preprocessor exits).

If check is passed, the output will be written to a file called FILENAME.json after the model has been checked.

If transform is passed, the JSON output of the transformed model (maximum lead of 1, minimum lag of -1, expectation operators substituted, etc.) will be written to a file called FILENAME.json and the original, untransformed model will be written in FILENAME_original.json.

And if compute is passed, the output is written after the computing pass. In this case, the transformed model is written to FILENAME.json, the original model is written to FILENAME_original.json, and the dynamic and static files are written to FILENAME_dynamic.json and FILENAME_static.json.

  • jsonstdout

    Instead of writing output requested by json to files, write to standard out, i.e. to the Julia command window (and the log-file).

  • onlyjson

    Quit processing once the output requested by json has been written.

  • jsonderivsimple

    Print a simplified version (excluding variable name(s) and lag information) of the static and dynamic files in FILENAME_static.json and FILENAME_dynamic..

  • warn\_uninit

Display a warning for each variable or parameter which is not initialized. See (@ref "Parameter initialization"), or (@ref "loadparamsandsteadystate") for initialization of parameters. See (@ref "Initial and Terminal conditions"), or (@ref "loadparamsandsteadystate") for initialization of endogenous and exogenous variables.

  • nopreprocessoroutput

    Prevent Dynare from printing the output of the steps leading up to the preprocessor as well as the preprocessor output itself.

  • -DMACRO\_VARIABLE\[=MACRO\_EXPRESSION\]

    Defines a macro-variable from the command line (the same effect as using the Macro directive @#define in a model file, see (@ref "Macro processing language")). See the (@ref "note on quotes") for info on passing a MACRO_EXPRESSION argument containing spaces. Note that an expression passed on the command line can reference variables defined before it. If MACRO_EXPRESSION is omitted, the variable is assigned the true logical value.

    Example

    Call dynare with command line defines

    julia julia> @dynare <<modfile.mod>> -DA=true '-DB="A string with space"' -DC=[1,2,3] '-DD=[ i in C when i > 1 ]' -DE;

  • -I\<\<path\>\>

    Defines a path to search for files to be included by the macro processor (using the @#include command). Multiple -I flags can be passed on the command line. The paths will be searched in the order that the -I flags are passed and the first matching file will be used. The flags passed here take priority over those passed to @#includepath. See the (@ref "note on quotes") for info on passing a <<path>> argument containing spaces.

  • nostrict

    Allows Dynare to issue a warning and continue processing when

  1. there are more endogenous variables than equations.
  2. an undeclared symbol is assigned in initval or endval.
  3. an undeclared symbol is found in the model block in this case, it is automatically declared exogenous.
  4. exogenous variables were declared but not used in the model block.
  • stochastic

    Tells Dynare that the model to be solved is stochastic. If no Dynare commands related to stochastic models (stoch_simul, estimation, ...) are present in the .mod file, Dynare understands by default that the model to be solved is deterministic.

  • exclude\_eqs=\<\<equation\_tags\_to\_exclude\>\>

    Tells Dynare to exclude all equations specified by the argument. As a .mod file must have the same number of endogenous variables as equations, when ***exclude_eqs*** is passed, certain rules are followed for excluding endogenous variables. If the endogenous tag has been set for the excluded equation, the variable it specifies is excluded. Otherwise, if the left hand side of the excluded equation is an expression that contains only one endogenous variable, that variable is excluded. If neither of these conditions hold, processing stops with an error. If an endogenous variable has been excluded by the ***exclude_eqs*** option and it exists in an equation that has not been excluded, it is transformed into an exogenous variable.

    To specify which equations to exclude, you must pass the argument <<equation_tags_to_exclude>>. This argument takes either a list of equation tags specifying the equations to be excluded or a filename that contains those tags.

If <<equation_tags_to_exclude>> is a list of equation tags, it can take one of the following forms:

  1. Given a single argument, e.g. exclude_eqs=eq1, the equation with the tag [name='eq1'] will be excluded. Note that if there is a file called eq1 in the current directory, Dynare will instead try to open this and read equations to exclude from it (see info on filename argument to exclude_eqs below). Further note that if the tag value contains a space, you must use the variant specified in 2 below, i.e. exclude_eqs=[eq 1].
  2. Given two or more arguments, e.g. exclude_eqs=[eq1, eq 2], the equations with the tags [name='eq1'] and [name='eq 2'] will be excluded.
  3. If you\'d like to exclude equations based on another tag name (as opposed to the default name), you can pass the argument as either e.g. exclude_eqs=[tagname=a tag] if a single equation with tag [tagname='a tag'] is to be excluded or as e.g. exclude_eqs=[tagname=(a tag, 'a tag with a, comma')] if more than one equation with tags [tagname='a tag'] and [tagname='a tag with a, comma'] will be excluded (note the parenthesis, which are required when more than one equation is specified). Note that if the value of a tag contains a comma, it must be included inside single quotes.

If <<equation_tags_to_exclude>> is a filename, the file can take one of the following forms:

  1. One equation per line of the file, where every line represents the value passed to the name tag. e.g., a file such as: julia eq1 eq 2 would exclude equations with tags [name='eq1'] and [name='eq 2'].

  2. One equation per line of the file, where every line after the first line represents the value passed to the tag specified by the first line. e.g., a file such as: julia tagname= a tag a tag with a, comma would exclude equations with tags [tagname='a tag'] and [tagname='a tag with a, comma']. Here note that the first line must end in an equal sign.

  • include\_eqs=\<\<equation\_tags\_to\_include\>\>

    Tells Dynare to run with only those equations specified by the argument; in other words, Dynare will exclude all equations not specified by the argument. The argument <<equation_tags_to_include>> is specified in the same way as the argument to exclude_eqs <exclude_eqs>. The functionality of include_eqs is to find which equations to exclude then take actions in accord with (@ref "exclude_eqs").

  • nocommutativity

This option tells the preprocessor not to use the commutativity of addition and multiplication when looking for common subexpressions. As a consequence, when using this option, equations in various outputs (LaTeX, JSON...) will appear as the user entered them (without terms or factors swapped). Note that using this option may have a performance impact on the preprocessing stage, though it is likely to be small.

These options can be passed to the preprocessor by listing them after the name of the .mod file. They can alternatively be defined in the first line of the .mod file, this avoids typing them on the command line each time a .mod file is to be run. This line must be a Dynare one-line comment (i.e. must begin with //) and the options must be whitespace separated between --+ options: and +--. Note that any text after the +-- will be discarded. As in the command line, if an option admits a value the equal symbol must not be surrounded by spaces. For instance json = compute is not correct, and should be written json=compute. The nopathchange option cannot be specified in this way, it must be passed on the command-line.

Understanding Preprocessor Error Messages

If the preprocessor runs into an error while processing your .mod file, it will issue an error. Due to the way that a parser works, sometimes these errors can be misleading. Here, we aim to demystify these error messages.

The preprocessor issues error messages of the form:

  1. ERROR: <<file.mod>>: line A, col B: <<error message>>
  2. ERROR: <<file.mod>>: line A, cols B-C: <<error message>>
  3. ERROR: <<file.mod>>: line A, col B - line C, col D: <<error message>>

The first two errors occur on a single line, with error two spanning multiple columns. Error three spans multiple rows.

Often, the line and column numbers are precise, leading you directly to the offending syntax. Infrequently however, because of the way the parser works, this is not the case. The most common example of misleading line and column numbers (and error message for that matter) is the case of a missing semicolon, as seen in the following example:

varexo a, b
+parameters c, ...;

In this case, the parser doesn't know a semicolon is missing at the end of the varexo command until it begins parsing the second line and bumps into the parameters command. This is because we allow commands to span multiple lines and, hence, the parser cannot know that the second line will not have a semicolon on it until it gets there. Once the parser begins parsing the second line, it realizes that it has encountered a keyword, parameters, which it did not expect. Hence, it throws an error of the form: ERROR: <<file.mod>>: line 2, cols 0-9: syntax error, unexpected PARAMETERS. In this case, you would simply place a semicolon at the end of line one and the parser would continue processing.

diff --git a/dev/search_index.js b/dev/search_index.js index 77765bc..9973e02 100644 --- a/dev/search_index.js +++ b/dev/search_index.js @@ -1,3 +1,3 @@ var documenterSearchIndex = {"docs": -[{"location":"macroprocessor/#Macro-processing-language","page":"Macroprocessing language","title":"Macro processing language","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is possible to use \"macro\" commands in the .mod file for performing tasks such as: including modular source files, replicating blocks of equations through loops, conditionally executing some code, writing indexed sums or products inside equations...","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The Dynare macro-language provides a new set of macro-commands which can be used in .mod files. It features:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"File inclusion\nLoops (for structure)\nConditional inclusion (if/then/else structures)\nExpression substitution","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This macro-language is totally independent of the basic Dynare language, and is processed by a separate component of the Dynare pre-processor. The macro processor transforms a .mod file with macros into a .mod file without macros (doing expansions/inclusions), and then feeds it to the Dynare parser. The key point to understand is that the macro processor only does text substitution (like the C preprocessor or the PHP language). Note that it is possible to see the output of the macro processor by using the savemacro option of the dynare command (see dyn-invoc).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The macro processor is invoked by placing macro directives in the .mod file. Directives begin with an at-sign followed by a pound sign (@#). They produce no output, but give instructions to the macro processor. In most cases, directives occupy exactly one line of text. If needed, two backslashes (\\\\) at the end of the line indicate that the directive is continued on the next line. Macro directives following // are not interpreted by the macro processor. For historical reasons, directives in commented blocks, ie surrounded by /* and */, are interpreted by the macro processor. The user should not rely on this behavior. The main directives are:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"@#includepath, paths to search for files that are to be included,\n@#include, for file inclusion,\n@#define, for defining a macro processor variable,\n@#if, @#ifdef, @#ifndef, @#elseif, @#else, @#endif for conditional statements,\n@#for, @#endfor for constructing loops.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The macro processor maintains its own list of variables (distinct from model variables and Julia variables). These macro-variables are assigned using the @#define directive and can be of the following basic types: boolean, real, string, tuple, function, and array (of any of the previous types).","category":"page"},{"location":"macroprocessor/#Macro-expressions","page":"Macroprocessing language","title":"Macro expressions","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro-expressions can be used in two places:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Inside macro directives, directly;\nIn the body of the .mod file, between an at-sign and curly braces: the macro processor will substitute the expression with its value","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is possible to construct macro-expressions that can be assigned to macro-variables or used within a macro-directive. The expressions are constructed using literals of the basic types (boolean, real, string, tuple, array), comprehensions, macro-variables, macro-functions, and standard operators.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"note: Note\nElsewhere in the manual, MACRO_EXPRESSION designates an expression constructed as explained in this section.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Boolean","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on booleans:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nLogical operators: &&, ||, !","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Real","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on reals:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Arithmetic operators: +, -, *, /, ^\nComparison operators: <, >, <=, >=, ==, !=\nLogical operators: &&, ||, !\nRanges with an increment of 1: REAL1:REAL2 (for example, 1:4 is equivalent to real array [1, 2, 3, 4]).\n4.6 Previously, putting brackets around the arguments to the colon operator (e.g. [1:4]) had no effect. Now, [1:4] will create an array containing an array (i.e. [ [1, 2, 3, 4] ]).\nRanges with user-defined increment: REAL1:REAL2:REAL3 (for example, 6:-2.1:-1 is equivalent to real array [6, 3.9, 1.8, -0.3]).\nFunctions: max, min, mod, exp, log, log10, sin, cos, tan, asin, acos, atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma, round, normpdf, normcdf. NB ln can be used instead of log","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"String","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"String literals have to be enclosed by double quotes (like \"name\").","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on strings:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: <, >, <=, >=, ==, !=\nConcatenation of two strings: +\nExtraction of substrings: if s is a string, then s[3] is a string containing only the third character of s, and s[4:6] contains the characters from 4th to 6th\nFunction: length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Tuple","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Tuples are enclosed by parenthesis and elements separated by commas (like (a,b,c) or (1,2,3)).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on tuples:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nFunctions: empty, length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Array","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Arrays are enclosed by brackets, and their elements are separated by commas (like [1,[2,3],4] or [\"US\", \"FR\"]).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on arrays:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nDereferencing: if v is an array, then v[2] is its 2nd element\nConcatenation of two arrays: +\nSet union of two arrays: |\nSet intersection of two arrays: &\nDifference -: returns the first operand from which the elements of the second operand have been removed.\nCartesian product of two arrays: *\nCartesian product of one array N times: ^N\nExtraction of sub-arrays: e.g. v[4:6]\nTesting membership of an array: in operator (for example: \"b\" in [\"a\", \"b\", \"c\"] returns 1)\nFunctions: empty, sum, length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comprehension","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comprehension syntax is a shorthand way to make arrays from other arrays. There are three different ways the comprehension syntax can be employed: [filtering], [mapping], and [filtering and mapping].","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering allows one to choose those elements from an array for which a certain condition hold.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, choosing the even numbers from the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i in 1:5 when mod(i,2) == 0 ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [2, 4]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Mapping","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Mapping allows you to apply a transformation to every element of an array.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, squaring all elements of the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i^2 for i in 1:5 ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [1, 4, 9, 16, 25]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering and Mapping","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Combining the two preceding ideas would allow one to apply a transformation to every selected element of an array.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, squaring all even elements of the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i^2 for i in 1:5 when mod(i,2) == 0]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [4, 16]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Further Examples :","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ (j, i+1) for (i,j) in (1:2)^2 ]\n [ (j, i+1) for (i,j) in (1:2)*(1:2) when i < j ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [(1, 2), (2, 2), (1, 3), (2, 3)]\n [(2, 2)]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Function","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Functions can be defined in the macro processor using the @#define directive (see below). A function is evaluated at the time it is invoked, not at define time. Functions can be included in expressions and the operators that can be combined with them depend on their return type.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Checking variable type","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Given a variable name or literal, you can check the type it evaluates to using the following functions: isboolean, isreal, isstring, istuple, and isarray.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\nisboolean(0) false\nisboolean(true) true\nisreal(\"str\") false","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Casting between types","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Variables and literals of one type can be cast into another type. Some type changes are straightforward (e.g. changing a [real]{.title-ref} to a [string]{.title-ref}) whereas others have certain requirements (e.g. to cast an [array]{.title-ref} to a [real]{.title-ref} it must be a one element array containing a type that can be cast to [real]{.title-ref}).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\n(bool) -1.1 true\n(bool) 0 false\n(real) \"2.2\" 2.2\n(tuple) [3.3] (3.3)\n(array) 4.4 [4.4]\n(real) [5.5] 5.5\n(real) [6.6, 7.7] error\n(real) \"8.8 in a string\" error","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Casts can be used in expressions:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\n(bool) 0 && true false\n(real) \"1\" + 2 3\n(string) (3 + 4) \"7\"\n(array) 5 + (array) 6 [5, 6]","category":"page"},{"location":"macroprocessor/#Macro-directives","page":"Macroprocessing language","title":"Macro directives","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#includepath \"PATH\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive @#includepath MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This directive adds the path contained in PATH to the list of those to search when looking for a .mod file specified by @#include. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that these paths are added after any paths passed using -I <-I\\<\\\\>>{.interpreted-text role=\"opt\"}.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#includepath \"/path/to/folder/containing/modfiles\"\n @#includepath folders_containing_mod_files","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#include \"FILENAME\" ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#include MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This directive simply includes the content of another file in its place; it is exactly equivalent to a copy/paste of the content of the included file. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that it is possible to nest includes (i.e. to include a file from an included file). The file will be searched for in the current directory. If it is not found, the file will be searched for in the folders provided by -I <-I\\<\\\\>>{.interpreted-text role=\"opt\"} and @#includepath.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#include \"modelcomponent.mod\"\n @#include location_of_modfile","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_VARIABLE ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_VARIABLE = MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_FUNCTION = MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Defines a macro-variable or macro function.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define var // Equals true\n @#define x = 5 // Real\n @#define y = \"US\" // String\n @#define v = [ 1, 2, 4 ] // Real array\n @#define w = [ \"US\", \"EA\" ] // String array\n @#define u = [ 1, [\"EA\"] ] // Mixed array\n @#define z = 3 + v[2] // Equals 5\n @#define t = (\"US\" in w) // Equals true\n @#define f(x) = \" \" + x + y // Function `f` with argument `x`\n // returns the string ' ' + x + 'US'","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define x = 1\n @#define y = [ \"B\", \"C\" ]\n @#define i = 2\n @#define f(x) = x + \" + \" + y[i]\n @#define i = 1\n\n model;\n A = @{y[i] + f(\"D\")};\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is strictly equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n A = BD + B;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#if MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#ifdef MACRO_VARIABLE","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#ifndef MACRO_VARIABLE ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#elseif MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#else @#endif","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Conditional inclusion of some part of the .mod file. The lines between @#if, @#ifdef, or @#ifndef and the next @#elseif, @#else or @#endif is executed only if the condition evaluates to true. Following the @#if body, you can zero or more @#elseif branches. An @#elseif condition is only evaluated if the preceding @#if or @#elseif condition evaluated to false. The @#else branch is optional and is only evaluated if all @#if and @#elseif statements evaluate to false.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that when using @#ifdef, the condition will evaluate to true if the MACROVARIABLE has been previously defined, regardless of its value. Conversely, @#ifndef will evaluate to true if the MACROVARIABLE has not yet been defined.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that when using @#elseif you can check whether or not a variable has been defined by using the defined operator. Hence, to enter the body of an @#elseif branch if the variable X has not been defined, you would write: @#elseif !defined(X).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that if a real appears as the result of the MACROEXPRESSION, it will be interpreted as a boolean; a value of 0 is interpreted as false, otherwise it is interpreted as true. Further note that because of the imprecision of reals, extra care must be taken when testing them in the MACROEXPRESSION. For example, exp(log(5)) == 5 will evaluate to false. Hence, when comparing real values, you should generally use a zero tolerance around the value desired, e.g. exp(log(5)) > 5-1e-14 && exp(log(5)) < 5+1e-14","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Choose between two alternative monetary policy rules using a macro-variable:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define linear_mon_pol = false // 0 would be treated the same\n ...\n model;\n @#if linear_mon_pol\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n @#else\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n @#endif\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" ...\n model;\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Choose between two alternative monetary policy rules using a macro-variable. The only difference between this example and the previous one is the use of @#ifdef instead of @#if. Even though linear_mon_pol contains the value false because @#ifdef only checks that the variable has been defined, the linear monetary policy is output:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define linear_mon_pol = false // 0 would be treated the same\n ...\n model;\n @#ifdef linear_mon_pol\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n @#else\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n @#endif\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" ...\n model;\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_VARIABLE in MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_VARIABLE in MACRO_EXPRESSION when MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_TUPLE in MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_TUPLE in MACRO_EXPRESSION when MACRO\\_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Loop construction for replicating portions of the .mod file. Note that this construct can enclose variable/parameters declaration, computational tasks, but not a model declaration.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n @#for country in [ \"home\", \"foreign\" ]\n GDP_@{country} = A * K_@{country}^a * L_@{country}^(1-a);\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n GDP_home = A * K_home^a * L_home^(1-a);\n GDP_foreign = A * K_foreign^a * L_foreign^(1-a);\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n @#for (i, j) in [\"GDP\"] * [\"home\", \"foreign\"]\n @{i}_@{j} = A * K_@{j}^a * L_@{j}^(1-a);\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n GDP_home = A * K_home^a * L_home^(1-a);\n GDP_foreign = A * K_foreign^a * L_foreign^(1-a);\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define countries = [\"US\", \"FR\", \"JA\"]\n @#define nth_co = \"US\"\n model;\n @#for co in countries when co != nth_co\n (1+i_@{co}) = (1+i_@{nth_co}) * E_@{co}(+1) / E_@{co};\n @#endfor\n E_@{nth_co} = 1;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n (1+i_FR) = (1+i_US) * E_FR(+1) / E_FR;\n (1+i_JA) = (1+i_US) * E_JA(+1) / E_JA;\n E_US = 1;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echo MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display some message on standard output. The argument must evaluate to a string.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#error MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display some error message on standard output and to abort. The argument must evaluate to a string.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars MACRO_VARIABLE_LIST","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars(save) MACRO_VARIABLE_LIST","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display the value of all macro variables up until this point. If the save option is passed, then values of the macro variables are saved to options_.macrovars_line_<>. If NAME_LIST is passed, only display/save variables and functions with that name.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define A = 1\n @#define B = 2\n @#define C(x) = x*2\n @#echomacrovars A C D","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The output of the command above is:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" Macro Variables:\n A = 1\n Macro Functions:\n C(x) = (x * 2)","category":"page"},{"location":"macroprocessor/#Typical-usages","page":"Macroprocessing language","title":"Typical usages","text":"","category":"section"},{"location":"macroprocessor/#Modularization","page":"Macroprocessing language","title":"Modularization","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The @#include directive can be used to split .mod files into several modular components.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example setup:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"modeldesc.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Contains variable declarations, model equations, and shocks declarations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"simul.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Includes modeldesc.mod, calibrates parameter,s and runs stochastic simulations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"estim.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Includes modeldesc.mod, declares priors on parameters, and runs Bayesian estimation.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Dynare can be called on simul.mod and estim.mod but it makes no sense to run it on modeldesc.mod.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The main advantage is that you don't have to copy/paste the whole model (at the beginning) or changes to the model (during development).","category":"page"},{"location":"macroprocessor/#Indexed-sums-of-products","page":"Macroprocessing language","title":"Indexed sums of products","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following example shows how to construct a moving average:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define window = 2\n\n var x MA_x;\n ...\n model;\n ...\n MA_x = @{1/(2*window+1)}*(\n @#for i in -window:window\n +x(@{i})\n @#endfor\n );\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"After macro processing, this is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" var x MA_x;\n ...\n model;\n ...\n MA_x = 0.2*(\n +x(-2)\n +x(-1)\n +x(0)\n +x(1)\n +x(2)\n );\n ...\n end;","category":"page"},{"location":"macroprocessor/#Multi-country-models","page":"Macroprocessing language","title":"Multi-country models","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Here is a skeleton example for a multi-country model:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define countries = [ \"US\", \"EA\", \"AS\", \"JP\", \"RC\" ]\n @#define nth_co = \"US\"\n\n @#for co in countries\n var Y_@{co} K_@{co} L_@{co} i_@{co} E_@{co} ...;\n parameters a_@{co} ...;\n varexo ...;\n @#endfor\n\n model;\n @#for co in countries\n Y_@{co} = K_@{co}^a_@{co} * L_@{co}^(1-a_@{co});\n ...\n @#if co != nth_co\n (1+i_@{co}) = (1+i_@{nth_co}) * E_@{co}(+1) / E_@{co}; // UIP relation\n @#else\n E_@{co} = 1;\n @#endif\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/#Endogeneizing-parameters","page":"Macroprocessing language","title":"Endogeneizing parameters","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"When calibrating the model, it may be useful to consider a parameter as an endogenous variable (and vice-versa).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For example, suppose production is defined by a CES function:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"y = left(alpha^1xi ell^1-1xi+(1-alpha)^1xik^1-1xiright)^xi(xi-1)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"and the labor share in GDP is defined as:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"textrmlab_rat = (w ell)(p y)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In the model, alpha is a (share) parameter and lab_rat is an endogenous variable.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is clear that calibrating alpha is not straightforward; on the contrary, we have real world data for lab_rat and it is clear that these two variables are economically linked.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The solution is to use a method called variable flipping, which consists in changing the way of computing the steady state. During this computation, alpha will be made an endogenous variable and lab_rat will be made a parameter. An economically relevant value will be calibrated for lab_rat, and the solution algorithm will deduce the implied value for alpha.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"An implementation could consist of the following files:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"modeqs.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file contains variable declarations and model equations. The code for the declaration of alpha and lab_rat would look like:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#if steady\n var alpha;\n parameter lab_rat;\n @#else\n parameter alpha;\n var lab_rat;\n @#endif","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"steady.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file computes the steady state. It begins with:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define steady = 1\n @#include \"modeqs.mod\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Then it initializes parameters (including lab_rat, excluding alpha), computes the steady state (using guess values for endogenous, including alpha), then saves values of parameters and endogenous at steady state in a file, using the save_params_and_steady_state command.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"simul.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file computes the simulation. It begins with:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define steady = 0\n @#include \"modeqs.mod\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Then it loads values of parameters and endogenous at steady state from file, using the load_params_and_steady_state command, and computes the simulations.","category":"page"},{"location":"macroprocessor/#Julia-loops-versus-macro-processor-loops","page":"Macroprocessing language","title":"Julia loops versus macro processor loops","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Suppose you have a model with a parameter rho and you want to run simulations for three values: rho = 08 09 1. There are several ways of doing this:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a Julia loop","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" rhos = [ 0.8, 0.9, 1];\n for i = 1:length(rhos)\n rho = rhos(i);\n stoch_simul(order=1);\n end","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Here the loop is not unrolled, Julia manages the iterations. This is interesting when there are a lot of iterations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a macro processor loop (case 1)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" rhos = [ 0.8, 0.9, 1];\n @#for i in 1:3\n rho = rhos(@{i});\n stoch_simul(order=1);\n @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This is very similar to the previous example, except that the loop is unrolled. The macro processor manages the loop index but not the data array (rhos).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a macro processor loop (case 2)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#for rho_val in [ 0.8, 0.9, 1]\n rho = @{rho_val};\n stoch_simul(order=1);\n @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The advantage of this method is that it uses a shorter syntax, since the list of values is directly given in the loop construct. The inconvenience is that you can not reuse the macro array in Julia.","category":"page"},{"location":"macroprocessor/#Verbatim-inclusion","page":"Macroprocessing language","title":"Verbatim inclusion","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Pass everything contained within the verbatim block to the .m file.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Block: verbatim ;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"By default, whenever Dynare encounters code that is not understood by the parser, it is directly passed to the preprocessor output.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In order to force this behavior you can use the verbatim block. This is useful when the code you want passed to the .m file contains tokens recognized by the Dynare preprocessor.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" verbatim;\n % Anything contained in this block will be passed\n % directly to the .m file, including comments\n var = 1;\n end;","category":"page"},{"location":"macroprocessor/#Misc-commands","page":"Macroprocessing language","title":"Misc commands","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Command: `saveparamsandsteadystate (FILENAME); ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For all parameters, endogenous and exogenous variables, stores their value in a text file, using a simple name/value associative table.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"for parameters, the value is taken from the last parameter initialization.\nfor exogenous, the value is taken from the last initval block.\nfor endogenous, the value is taken from the last steady state computation (or, if no steady state has been computed, from the last initval block).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that no variable type is stored in the file, so that the values can be reloaded with load_params_and_steady_state in a setup where the variable types are different.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The typical usage of this function is to compute the steady-state of a model by calibrating the steady-state value of some endogenous variables (which implies that some parameters must be endogeneized during the steady-state computation).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"You would then write a first .mod file which computes the steady state and saves the result of the computation at the end of the file, using save_params_and_steady_state.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In a second file designed to perform the actual simulations, you would use load_params_and_steady_state just after your variable declarations, in order to load the steady state previously computed (including the parameters which had been endogeneized during the steady state computation).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The need for two separate .mod files arises from the fact that the variable declarations differ between the files for steady state calibration and for simulation (the set of endogenous and parameters differ between the two); this leads to different var and parameters statements.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Also note that you can take advantage of the @#include directive to share the model equations between the two files (see macro-proc-lang).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"load_params_and_steady_state (FILENAME);","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For all parameters, endogenous and exogenous variables, loads their value from a file created with save_params_and_steady_state.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"for parameters, their value will be initialized as if they had been calibrated in the .mod file.\nfor endogenous and exogenous variables, their value will be initialized as they would have been from an initval block .","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This function is used in conjunction with save_params_and_steady_state; see the documentation of that function for more information.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"When the framework is deterministic, Dynare can be used for models with the assumption of perfect foresight. The system is supposed to be in a given state before a period 1 (often a steady state) when the news of a contemporaneous or of a future shock is learned by the agents in the model. The purpose of the simulation is to describe the reaction in anticipation of, then in reaction to the shock, until the system returns to equilibrium. This return to equilibrium is only an asymptotic phenomenon, which one must approximate by an horizon of simulation far enough in the future. Another exercise for which Dynare is well suited is to study the transition path to a new equilibrium following a permanent shock. For deterministic simulations, the numerical problem consists of solving a nonlinear system of simultaneous equations in n endogenous variables in T periods. Dynare uses a Newton-type method to solve the simultaneous equation system. Because the resulting Jacobian is in the order of n by T and hence will be very large for long simulations with many variables, Dynare makes use of the sparse matrix code .","category":"page"},{"location":"model-file/deterministic-simulations/#Dynare-commands","page":"Deterministic simulations","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/deterministic-simulations/#perfect_foresight_setup","page":"Deterministic simulations","title":"perfect_foresight_setup","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_setup;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_setup (OPTIONS...);","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Prepares a perfect foresight simulation, by extracting the information in the initval, endval and shocks blocks and converting them into simulation paths for exogenous and endogenous variables.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"This command must always be called before running the simulation with perfect\\_foresight\\_solver.","category":"page"},{"location":"model-file/deterministic-simulations/#Options","page":"Deterministic simulations","title":"Options","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"periods = INTEGER","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Number of periods of the simulation.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"datafile = FILENAME","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Used to specify path for all endogenous and exogenous variables. Strictly equivalent to initval_file.","category":"page"},{"location":"model-file/deterministic-simulations/#Output","page":"Deterministic simulations","title":"Output","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The paths for the exogenous variables are stored into context.results.model_resultst[1].simulations.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The initial and terminal conditions for the endogenous variables and the initial guess for the path of endogenous variables are stored into context.results.model_results[1].simulations.","category":"page"},{"location":"model-file/deterministic-simulations/#perfect_foresight_solver","page":"Deterministic simulations","title":"perfect_foresight_solver","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_solver ;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_solver (OPTIONS...);","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Computes the perfect foresight (or deterministic) simulation of the model.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Note that perfect\\_foresight\\_setup must be called before this command, in order to setup the environment for the simulation.","category":"page"},{"location":"model-file/deterministic-simulations/#Options-2","page":"Deterministic simulations","title":"Options","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"maxit = INTEGER","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"tolf = DOUBLE","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Convergence criterion for termination based on the function value. Iteration will cease when it proves impossible to improve the function value by more than tolf. Default: 1e-5","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"tolx = DOUBLE","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Convergence criterion for termination based on the change in the function argument. Iteration will cease when the solver attempts to take a step that is smaller than tolx. Default: 1e-5","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"noprint","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Don't print anything. Useful for loops.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"print","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Print results (opposite of noprint).","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"lmmcp","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Solves mixed complementarity problems (the term refers to the LMMCP solver (Kanzow and Petra, 2004), that is used by DynareMatlab. DynareJulia uses the PATHSovler package)","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"endogenous_terminal_period","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The number of periods is not constant across Newton iterations when solving the perfect foresight model. The size of the nonlinear system of equations is reduced by removing the portion of the paths (and associated equations) for which the solution has already been identified (up to the tolerance parameter). This strategy can be interpreted as a mix of the shooting and relaxation approaches. Note that round off errors are more important with this mixed strategy (user should check the reported value of the maximum absolute error). Only available with option stack_solve_algo==0.","category":"page"},{"location":"model-file/deterministic-simulations/#Remark","page":"Deterministic simulations","title":"Remark","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Be careful when employing auxiliary variables in the context of perfect\nforesight computations. The same model may work for stochastic\nsimulations, but fail for perfect foresight simulations. The issue\narises when an equation suddenly only contains variables dated `t+1` (or\n`t-1` for that matter). In this case, the derivative in the last (first)\nperiod with respect to all variables will be 0, rendering the stacked\nJacobian singular.","category":"page"},{"location":"model-file/deterministic-simulations/#Example","page":"Deterministic simulations","title":"Example","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Consider the following specification of an Euler equation with log utility:","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Lambda = beta*C(-1)/C;\nLambda(+1)*R(+1)= 1;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Clearly, the derivative of the second equation with respect to all endogenous variables at time t is zero, causing perfect_foresight_solver to generally fail. This is due to the use of the Lagrange multiplier Lambda as an auxiliary variable. Instead, employing the identical","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"beta*C/C(+1)*R(+1)= 1;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"will work.","category":"page"},{"location":"model-file/deterministic-simulations/#Julia-function","page":"Deterministic simulations","title":"Julia function","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"perfect_foresight!","category":"page"},{"location":"model-file/deterministic-simulations/#Dynare.perfect_foresight!","page":"Deterministic simulations","title":"Dynare.perfect_foresight!","text":"perfect_foresight!(; periods, context = context, display = true,\n linear_solve_algo=ilu, maxit = 50, mcp = false,\n tolf = 1e-5, tolx = 1e-5)\n\nKeyword arguments\n\nperiods::Int: number of periods in the simulation [required]\ncontext::Context=context: context in which the simulation is computed\ndisplay::Bool=true: whether to display the results\nlinear_solve_algo::LinearSolveAlgo=ilu: algorithm used for the solution of the linear problem. Either ilu or pardiso. ilu is the sparse linear solver used by default in Julia. To use the Pardiso solver, write using Pardiso before running Dynare.\nmaxit::Int=50 maximum number of iterations\nmcp::Bool=falseL whether to solve a mixed complementarity problem with occasionally binding constraints\ntolf::Float64=1e-5: tolerance for the norm of residualts\ntolx::Float64=1e-5: tolerance for the norm of the change in the result\n\n\n\n\n\n","category":"function"},{"location":"model-file/deterministic-simulations/#Output-2","page":"Deterministic simulations","title":"Output","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The simulated endogenous variables are available in context.results.model_results[1].simulations. This is a vector of AxisArrayTable, one for each simulations stored in context. Each AxisArrayTable contains the trajectories for endogenous and exogenous variables","category":"page"},{"location":"model-file/deterministic-simulations/#Solving-mixed-complementarity-problems","page":"Deterministic simulations","title":"Solving mixed complementarity problems","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"requires a particular model setup as the goal is to get rid of any min/max operators and complementary slackness conditions that might introduce a singularity into the Jacobian. This is done by attaching an equation tag (see model-decl) with the mcp keyword to affected equations. The format of the mcp tag is","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"[mcp = 'VARIABBLENAME OP CONSTANT']","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"where VARIABLENAME is an endogenous variable and OP is either > or <. For complicated occasionally binding constraints, it may be necessary to declare a new endogenous variable.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"This tag states that the equation to which the tag is attached has to hold unless the expression within the tag is binding. For instance, a ZLB on the nominal interest rate would be specified as follows in the model block:","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":" model;\n ...\n [mcp = 'r > -1.94478']\n r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;\n ...\n end;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"where r is the nominal interest rate in deviation from the steady state. This construct implies that the Taylor rule is operative, unless the implied interest rate r<=-1.94478, in which case the r is fixed at -1.94478. This is equavalant to","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"(r_t -194478) bot r_t = rho r_t-1 + (1-rho) (g_pi Infl_t+g_y YGap_t) + e_t","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"By restricting the value of r coming out of this equation, the mcp tag also avoids using max(r,-1.94478) for other occurrences of r in the rest of the model. It is important to keep in mind that, because the mcp tag effectively replaces a complementary slackness condition, it cannot be simply attached to any equation.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Note that in the current implementation, the content of the mcp equation tag is not parsed by the preprocessor. The inequalities must therefore be as simple as possible: an endogenous variable, followed by a relational operator, followed by a number (not a variable, parameter or expression).","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Provided that you have observations on some endogenous variables, it is possible to use Dynare to estimate some or all parameters. Bayesian techniques (as in Fernández-Villaverde and Rubio-Ramírez (2004), Rabanal and Rubio-Ramirez (2003), Schorfheide (2000) or Smets and Wouters (2003)) are available. Using Bayesian methods, it is possible to estimate DSGE models.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Note that in order to avoid stochastic singularity, you must have at least as many shocks or measurement errors in your model as you have observed variables.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Before using the estimation commands described below, you need to define some elements of the state space representation of the model. At the minimum, you need to declare the observed variables with var_obs and, possibly, deterministic trends with observation_trends (see the previous section: State space, filtering and smoothing)","category":"page"},{"location":"model-file/estimation/#Dynare-commands","page":"Estimation","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/estimation/#estimated_params","page":"Estimation","title":"estimated_params","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params (overwrite) ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This block lists all parameters to be estimated and specifies bounds and priors as necessary.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Each line corresponds to an estimated parameter.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In a maximum likelihood or a method of moments estimation, each line follows this syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME\n , INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND ];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In a Bayesian MCMC or a penalized method of moments estimation, each line follows this syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME | DSGE_PRIOR_WEIGHT\n [, INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND]], PRIOR_SHAPE,\n PRIOR_MEAN, PRIOR_STANDARD_ERROR [, PRIOR_3RD_PARAMETER [,\n PRIOR_4TH_PARAMETER [, SCALE_PARAMETER ] ] ];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The first part of the line consists of one of the four following alternatives:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"stderr VARIABLE_NAME\nIndicates that the standard error of the exogenous variable VARIABLENAME, or of the observation error/measurement errors associated with endogenous observed variable VARIABLENAME, is to be estimated.\ncorr VARIABLE_NAME1, VARIABLE_NAME2\nIndicates that the correlation between the exogenous variables VARIABLENAME1 and VARIABLENAME2, or the correlation of the observation errors/measurement errors associated with endogenous observed variables VARIABLENAME1 and VARIABLENAME2, is to be estimated. Note that correlations set by previous shocks-blocks or estimation-commands are kept at their value set prior to estimation if they are not estimated again subsequently. Thus, the treatment is the same as in the case of deep parameters set during model calibration and not estimated.\nPARAMETER_NAME\nThe name of a model parameter to be estimated\nDSGE_PRIOR_WEIGHT\nSpecial name for the weigh of the DSGE model in DSGE-VAR model.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The rest of the line consists of the following fields, some of them being optional:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"INITIAL_VALUE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Specifies a starting value for the posterior mode optimizer or the maximum likelihood estimation. If unset, defaults to the prior mean.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"LOWER_BOUND","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"UPPER_BOUND","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_SHAPE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"A keyword specifying the shape of the prior density. The possible values are: beta_pdf, gamma_pdf, normal_pdf, uniform_pdf, inv_gamma_pdf, inv_gamma1_pdf, inv_gamma2_pdf and weibull_pdf. Note that inv_gamma_pdf is equivalent to inv_gamma1_pdf.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_MEAN","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The mean of the prior distribution.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_STANDARD_ERROR","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The standard error of the prior distribution.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_3RD_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported except for the Uniform","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_4TH_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"SCALE_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"A parameter specific scale parameter for the jumping distribution's covariance matrix of the Metropolis-Hasting algorithm.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Note that INITIALVALUE, LOWERBOUND, UPPERBOUND, PRIORMEAN, PRIORSTANDARDERROR, PRIOR3RDPARAMETER, PRIOR4THPARAMETER and SCALE_PARAMETER can be any valid EXPRESSION. Some of them can be empty, in which Dynare will select a default value depending on the context and the prior shape.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In case of the uniform distribution, it can be specified either by providing an upper and a lower bound using PRIOR_3RD_PARAMETER and PRIOR_4TH_PARAMETER or via mean and standard deviation using PRIOR_MEAN, PRIOR_STANDARD_ERROR. The other two will automatically be filled out. Note that providing both sets of hyperparameters will yield an error message.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"As one uses options more towards the end of the list, all previous options must be filled: for example, if you want to specify SCALEPARAMETER, you must specify `PRIOR3RDPARAMETERandPRIOR4TH_PARAMETER`. Use empty values, if these parameters don't apply.","category":"page"},{"location":"model-file/estimation/#Parameter-transformation","page":"Estimation","title":"Parameter transformation","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Sometimes, it is desirable to estimate a transformation of a parameter appearing in the model, rather than the parameter itself. It is of course possible to replace the original parameter by a function of the estimated parameter everywhere is the model, but it is often unpractical.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In such a case, it is possible to declare the parameter to be estimated in the parameters statement and to define the transformation, using a pound sign (#) expression.","category":"page"},{"location":"model-file/estimation/#Example","page":"Estimation","title":"Example","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" parameters bet;\n\n model;\n # sig = 1/bet;\n c = sig*c(+1)*mpk;\n end;\n\n estimated_params;\n bet, normal_pdf, 1, 0.05;\n end;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"It is possible to have several estimated_params blocks. By default, subsequent blocks are concatenated with the previous ones; this can be useful when building models in a modular fashion (see also estimated_params_remove for that use case). However, if an estimated_params block has the overwrite option, its contents becomes the new list of estimated parameters, cancelling previous blocks; this can be useful when doing several estimations in a single .mod file.","category":"page"},{"location":"model-file/estimation/#estimated_params_init","page":"Estimation","title":"estimated_params_init","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params_init ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params_init (OPTIONS...);","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This block declares numerical initial values for the optimizer when these ones are different from the prior mean. It should be specified after the estimated_params block as otherwise the specified starting values are overwritten by the latter.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Each line has the following syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME, INITIAL_VALUE;","category":"page"},{"location":"model-file/estimation/#estimation","page":"Estimation","title":"estimation","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Command: estimation [VARIABLE_NAME...];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Command: estimation (OPTIONS...)[VARIABLE_NAME...];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This command runs Bayesian estimation.","category":"page"},{"location":"model-file/estimation/#Options","page":"Estimation","title":"Options","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"datafile = FILENAME","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The datafile must be in CSV format","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" estimation(datafile='../fsdat_simul.csv',...);","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"nobs = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The number of observations following first_obs to be used. Default: all observations in the file after first_obs.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"first_obs = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The number of the first observation to be used. In case of estimating a DSGE-VAR, first_obs needs to be larger than the number of lags. Default: 1.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_priors = INTEGER: Control the plotting of priors, 0, no prior plot, 1, pPrior density for each estimated parameter is plotted. It is important to check that the actual shape of prior densities matches what you have in mind. Ill-chosen values for the prior standard density can result in absurd prior densities (default valueL 1).\nmh_replic = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Number of replications for each chain of the Metropolis-Hastings algorithm. The number of draws should be sufficient to achieve convergence of the MCMC and to meaningfully compute posterior objects. Default: 20000.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mh_nblocks = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Number of parallel chains for Metropolis-Hastings algorithm. Default: 2.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mh_jscale = DOUBLE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The scale parameter of the jumping distribution's covariance matrix. The default value is rarely satisfactory. This option must be tuned to obtain, ideally, an acceptance ratio of 25%-33%. Basically, the idea is to increase the variance of the jumping distribution if the acceptance ratio is too high, and decrease the same variance if the acceptance ratio is too low. In some situations it may help to consider parameter-specific values for this scale parameter. This can be done in the estimated_params block. Default: 0.2.","category":"page"},{"location":"model-file/estimation/#Julia-functions","page":"Estimation","title":"Julia functions","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"covariance","category":"page"},{"location":"model-file/estimation/#Dynare.covariance","page":"Estimation","title":"Dynare.covariance","text":"covariance(chain:Chains)\n\ncomputes the covariance matrix of MCMC chain\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mode_compute!","category":"page"},{"location":"model-file/estimation/#Dynare.mode_compute!","page":"Estimation","title":"Dynare.mode_compute!","text":" mode_compute!(; \n context=context,\n data = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),\n datafile = \"\",\n diffuse_filter::Bool = false,\n display::Bool = false,\n fast_kalman_filter::Bool = true,\n first_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n initial_values = get_initial_value_or_mean(),\n last_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n mode_check::Bool = false,\n nobs::Int = 0,\n order::Int = 1,\n presample::Int = 0,\n transformed_parameters = true)\n\ncomputes the posterior mode.\n\nKeyword arguments\n\ncontext::Context=context: context of the computation\ndata::AxisArrayTable: AxisArrayTable containing observed variables\ndatafile::String: data filename (can't be used as the same time asdataset`)\nfirst_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)\ninitial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)\nlast_obs::PeriodsSinceEpoch: last period (default: last period of the dataset)\nnobs::Int = 0: number of observations (default: entire dataset)\ntransformed_parameters = true: whether to transform estimated parameter so as they take their value on R\n\nEither data or datafile must be specified.\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_priors ","category":"page"},{"location":"model-file/estimation/#Dynare.plot_priors","page":"Estimation","title":"Dynare.plot_priors","text":"plot_priors(; context::Context = context, n_points::Int = 100)\n\nplots prior density\n\nKeyword arguments\n\ncontext::Context = context: context in which to take the date to be ploted\nn_points::Int = 100: number of points used for a curve\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_prior_posterior ","category":"page"},{"location":"model-file/estimation/#Dynare.plot_prior_posterior","page":"Estimation","title":"Dynare.plot_prior_posterior","text":"plot_prior_posterior(chains; context::Context=context)\n\nplots priors posterios and mode if computed on the same plots\n\nKeyword arguments\n\ncontext::Context=context: context used to get the estimation results\n\nOutput\n\nthe plots are saved in .//Graphs/PriorPosterior_.png\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"prior!","category":"page"},{"location":"model-file/estimation/#Dynare.prior!","page":"Estimation","title":"Dynare.prior!","text":" prior!(s::Symbol; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::stdev; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::variance; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::corr; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n\ngenerates a prior for a symbol of a parameter, the standard deviation (stdev) or the variance (variance) of an exogenous variable or an endogenous variable (measurement error) or the correlation (corr) between 2 endogenous or exogenous variables\n\nKeywor arguments\n\nshape <: Distributions: the shape of the prior distribution (Beta, InvertedGamma, InvertedGamma1, Gamma, Normal, Uniform, Weibull) [required]\ncontext::Context=context: context in which the prior is declared\ndomain::Vector{<:Real}=Float64[]: domain for a uniform distribution\ninitialvalue::Union{Real,Missing}=missing: initialvalue for mode finding or MCMC iterations\nmean::Union{Real,Missing}=missing: mean of the prior distribution\nstdev::Union{Real,Missing}=missing: stdev of the prior distribution\nvariance::Union{Real,Missing}=missing: variance of the prior distribution\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"rwmh_compute!","category":"page"},{"location":"model-file/estimation/#Dynare.rwmh_compute!","page":"Estimation","title":"Dynare.rwmh_compute!","text":"rwmh_compute!(;context::Context=context,\n back_transformation::Bool = true,\n datafile::String = \"\",\n data::AxisArrayTable = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),\n diffuse_filter::Bool = false,\n display::Bool = true,\n fast_kalman_filter::Bool = true,\n first_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n initial_values = prior_mean(context.work.estimated_parameters),\n covariance::AbstractMatrix{Float64} = Matrix(prior_variance(context.work.estimated_parameters)),\n transformed_covariance::Matrix{Float64} = Matrix{Float64}(undef, 0,0),\n last_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n mcmc_chains::Int = 1,\n mcmc_init_scale::Float64 = 0.0,\n mcmc_jscale::Float64 = 0.0,\n mcmc_replic::Int = 0,\n mode_compute::Bool = true,\n nobs::Int = 0,\n order::Int = 1,\n plot_chain::Bool = true,\n plot_posterior_density::Bool = false, \n presample::Int = 0,\n transformed_parameters::Bool = true\n\n)\n\nruns random walk Monte Carlo simulations of the posterior\n\nKeyword arguments\n\ncontext::Context=context: context of the computation\ncovariance::AbstractMatrix{Float64}: \ndata::AxisArrayTable: AxisArrayTable containing observed variables\ndatafile::String: data filename\nfirst_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)\ninitial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)\nlast_obs::PeriodsSinceEpoch: last period (default: last dataseet in the dataset)\nmcmc_chains::Int number of MCMC chains (default: 1)\nmcmc_jscale::Float64: scale factor of proposal\nmcmc_replic::Int: = 0,\nnobs::Int = 0: number of observations (default: entire dataset)\nplot_chain::Bool: whether to display standard MCMC chain output (default:true)\nplot_posterior_density::Bool: wether to display plots with prior and posterior densities (default: false)\ntransformed_covariance::Matrix{Float64}: covariance of transformed parameters (default: empty)\ntransformed_parameters = true: whether to transform estimated parameter so as they take their value on R\n\nEither data or datafile must be specified.\n\n\n\n\n\n","category":"function"},{"location":"installation-and-configuration/#Installation-and-configuration","page":"Installation and Configuration","title":"Installation and configuration","text":"","category":"section"},{"location":"installation-and-configuration/#Software-requirements","page":"Installation and Configuration","title":"Software requirements","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"Dynare is available for all plateforms supported by the current stable version of Julia (https://julialang.org/downloads/#supported_platforms). It should also work with older versions of Julia starting with version 1.6.3","category":"page"},{"location":"installation-and-configuration/#Installation-of-Dynare","page":"Installation and Configuration","title":"Installation of Dynare","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"In Julia, install the Dynare.jl package:","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using Pkg\npkg\"add Dynare\"","category":"page"},{"location":"installation-and-configuration/#Using-Dynare","page":"Installation and Configuration","title":"Using Dynare","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"In order to start using Dynare in Julia, type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using Dynare","category":"page"},{"location":"installation-and-configuration/#Optional-extensions","page":"Installation and Configuration","title":"Optional extensions","text":"","category":"section"},{"location":"installation-and-configuration/#Pardiso","page":"Installation and Configuration","title":"Pardiso","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"If you want the solution of very large perfect foresight models and reduce the memory consumption, use the Pardiso package (https://github.com/JuliaSparse/Pardiso.jl) and type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using MKL, Pardiso","category":"page"},{"location":"installation-and-configuration/#PATHSolver","page":"Installation and Configuration","title":"PATHSolver","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"If youw want to solve perfect foresight models with occasionally binding constraints use the PATHSolver package (https://github.com/chkwon/PATHSolver.jl) and type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using PATHSolver","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"While Dynare allows the user to choose their own variable names, there are some restrictions to be kept in mind. First, variables and parameters must not have the same name as Dynare commands or built-in functions. In this respect, Dynare is not case-sensitive. For example, do not use Ln or Sigma_e to name your variable. Not conforming to this rule might yield hard-to-debug error messages or crashes. ","category":"page"},{"location":"model-file/variable-declarations/#var","page":"Variables and parameters declaration","title":"var","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRINGNAME=QUOTED_STRING)]...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var (deflator=MODEL_EXPR) VAR_NAME (... same options apply) var(log,deflator=MODEL_EXPR) VAR_NAME (... same options apply)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var (log_deflator=MODEL_EXPR) VAR_NAME (... same options apply)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This required command declares the endogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable or, if it is nonstationary, provide information regarding its deflator. The variables in the list can be separated by spaces or by commas. var commands can appear several times in the file and Dynare will concatenate them. ","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"If the model is nonstationary and is to be written as such in the model block, Dynare will need the trend deflator for the appropriate endogenous variables in order to stationarize the model. The trend deflator must be provided alongside the variables that follow this trend.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"log\nIn addition to the endogenous variable(s) thus declared, this option also triggers the creation of auxiliary variable(s) equal to the log of the corresponding endogenous variable(s). For example, given a var(log) y statement, two endogenous will be created (y and LOG_y), and an auxiliary equation linking the two will also be added (equal to LOG_y = log(y)). Moreover, every occurence of y in the model will be replaced by exp(LOG_y). This option is for example useful when one wants to perform a loglinear approximation of some variable(s) in the context of a first-order stochastic approximation; or when one wants to ensure the variable(s) stay(s) in the definition domain of the function defining the steady state or the dynamic residuals when the nonlinear solver is used.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"deflator = MODEL_EXPR\nThe expression used to detrend an endogenous variable. All trend variables, endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the trend_var, log_trend_var, var and parameters commands. The deflator is assumed to be multiplicative; for an additive deflator, use log_deflator. This option can be used together with the log option (the latter must come first).","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"log_deflator = MODEL_EXPR\nSame as deflator, except that the deflator is assumed to be additive instead of multiplicative (or, to put it otherwise, the declared variable is equal to the log of a variable with a multiplicative trend). This option cannot be used together with the log option, because it would not make much sense from an economic point of view (the corresponding auxiliary variable would correspond to the log taken two times on a variable with a multiplicative trend).","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nThis is the long version of the variable name. Its value is stored in M_.endo_names_long (a column cell array, in the same order as M_.endo_names). In case multiple long_name options are provided, the last one will be used. Default: VAR_NAME.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var c gnp cva \n cca (long_name=`Consumption CA');\nvar(deflator=A) i b;\nvar c $C$ (long_name=`Consumption');","category":"page"},{"location":"model-file/variable-declarations/#varexo","page":"Variables and parameters declaration","title":"varexo","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":" varexo VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares the exogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable. Exogenous variables are required if the user wants to be able to apply shocks to her model. The variables in the list can be separated by spaces or by commas. varexo commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":" varexo m gov;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Remarks","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"An exogenous variable is an innovation, in the sense that this\nvariable cannot be predicted from the knowledge of the current\nstate of the economy. For instance, if logged TFP is a first order\nautoregressive process:\n```math\na_t=ρa_{t−1}+ε_t\n```","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"then logged TFP is an endogenous variable to be declared with var, while the innovation ε_t is to be declared with varexo.","category":"page"},{"location":"model-file/variable-declarations/#varexo_det","page":"Variables and parameters declaration","title":"varexo_det","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"varexo_det VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares exogenous deterministic variables in a stochastic model. Optionally it is possible to give a LaTeX name to the variable. The variables in the list can be separated by spaces or by commas. varexo_det commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"It is possible to mix deterministic and stochastic shocks to build models where agents know from the start of the simulation about future exogenous changes. In that case stoch_simul will compute the rational expectation solution adding future information to the state space (nothing is shown in the output of stoch_simul) and forecast will compute a simulation conditional on initial conditions and future information.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Note that exogenous deterministic variables cannot appear with a lead or a lag in the model.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nNAME = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"varexo m gov;\nvarexo_det tau;","category":"page"},{"location":"model-file/variable-declarations/#parameters","page":"Variables and parameters declaration","title":"parameters","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters PARAM_NAME [$TEX_NAME$] [(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This command declares parameters used in the model, in variable\ninitialization or in shocks declaration. Optionally it is possible to give a\nLaTeX name to the parameter.\n\nThe parameters must subsequently be assigned values.\n\nThe parameters in the list can be separated by spaces or by commas.\n``parameters`` commands can appear several times in the file and Dynare\nwill concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nNAME = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters alpha, bet;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Parameter initialization","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"When using Dynare for computing simulations, it is necessary to calibrate the parameters of the model. This is done through parameter initialization.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The syntax is the following:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"PARAMETER_NAME = EXPRESSION;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Here is an example of calibration:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters alpha, beta;\n\nbeta = 0.99;\nalpha = 0.36;\nA = 1-alpha*beta;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Internally, the parameter values are stored in context.work.params","category":"page"},{"location":"model-file/variable-declarations/#Advanced-commands","page":"Variables and parameters declaration","title":"Advanced commands","text":"","category":"section"},{"location":"model-file/variable-declarations/#change_type","page":"Variables and parameters declaration","title":"change_type","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"change_type (var|varexo|varexo_det|parameters) VAR_NAME | PARAM_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Changes the types of the specified variables/parameters to another type: endogenous, exogenous, exogenous deterministic or parameter. It is important to understand that this command has a global effect on the mod file: the type change is effective after, but also before, the change_type command. This command is typically used when flipping some variables for steady state calibration: typically a separate model file is used for calibration, which includes the list of variable declarations with the macro processor, and flips some variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, w;\nparameters alpha, beta;\n...\nchange_type(var) alpha, beta;\nchange_type(parameters) y, w;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Here, in the whole model file, alpha and beta will be endogenous and y and w will be parameters.","category":"page"},{"location":"model-file/variable-declarations/#var_remove","page":"Variables and parameters declaration","title":"var_remove","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var_remove VAR_NAME | PARAM_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Removes the listed variables (or parameters) from the model. Removing a variable that has already been used in a model equation or elsewhere will lead to an error.","category":"page"},{"location":"model-file/variable-declarations/#predetermined_variables","page":"Variables and parameters declaration","title":"predetermined_variables","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"predetermined_variables VAR_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"In Dynare, the default convention is that the timing of a variable reflects when this variable is decided. The typical example is for capital stock: since the capital stock used at current period is actually decided at the previous period, then the capital stock entering the production function is k(-1), and the law of motion of capital must be written:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"k = i + (1-delta)*k(-1)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Put another way, for stock variables, the default in Dynare is to use a \"stock at the end of the period\" concept, instead of a \"stock at the beginning of the period\" convention.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The predetermined_variables is used to change that convention. The endogenous variables declared as predetermined variables are supposed to be decided one period ahead of all other endogenous variables. For stock variables, they are supposed to follow a \"stock at the beginning of the period\" convention.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Note that Dynare internally always uses the \"stock at the end of the period\" concept, even when the model has been entered using the predetermined_variables command. Thus, when plotting, computing or simulating variables, Dynare will follow the convention to use variables that are decided in the current period. For example, when generating impulse response functions for capital, Dynare will plot k, which is the capital stock decided upon by investment today (and which will be used in tomorrow's production function). This is the reason that capital is shown to be moving on impact, because it is k and not the predetermined k(-1) that is displayed. It is important to remember that this also affects simulated time series and output from smoother routines for predetermined variables. Compared to non-predetermined variables they might otherwise appear to be falsely shifted to the future by one period.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The following two program snippets are strictly equivalent.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Using default Dynare timing convention:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, k, i;\n...\nmodel;\ny = k(-1)^alpha;\nk = i + (1-delta)*k(-1);\n...\nend;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Using the alternative timing convention:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, k, i;\npredetermined_variables k;\n...\nmodel;\ny = k^alpha;\nk(+1) = i + (1-delta)*k;\n...\nend;","category":"page"},{"location":"model-file/variable-declarations/#trend_var","page":"Variables and parameters declaration","title":"trend_var","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var (growth_factor = MODEL_EXPR) VAR_NAME[$LATEX_NAME$]...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares the trend variables in the model. See conv for the syntax of MODEL_EXPR and VAR_NAME. Optionally it is possible to give a LaTeX name to the variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The variable is assumed to have a multiplicative growth trend. For an additive growth trend, use log_trend_var instead.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Trend variables are required if the user wants to be able to write a nonstationary model in the model block. The trend_var command must appear before the var command that references the trend variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"If the model is nonstationary and is to be written as such in the model block, Dynare will need the growth factor of every trend variable in order to stationarize the model. The growth factor must be provided within the declaration of the trend variable, using the growth_factor keyword. All endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the var and parameters commands.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var (growth_factor=gA) A;","category":"page"},{"location":"model-file/variable-declarations/#make_local_variables","page":"Variables and parameters declaration","title":"make_local_variables","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model_local_variable VARIABLE_NAME [LATEX_NAME]... ;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares a model local variable. See conv for the syntax of VARIABLE_NAME. As you can create model local variables on the fly in the model block, the interest of this command is primarily to assign a LATEX_NAME to the model local variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model_local_variable GDP_US $GDPUS$;","category":"page"},{"location":"model-file/variable-declarations/#On-the-fly-Model-Variable-Declaration","page":"Variables and parameters declaration","title":"On-the-fly Model Variable Declaration","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Endogenous variables, exogenous variables, and parameters can also be declared inside the model block. You can do this in two different ways: either via the equation tag or directly in an equation.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"To declare a variable on-the-fly in an equation tag, simply state the type of variable to be declared (endogenous, exogenous, or parameter followed by an equal sign and the variable name in single quotes. Hence, to declare a variable c as endogenous in an equation tag, you can type [endogenous='c'].","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"To perform on-the-fly variable declaration in an equation, simply follow the symbol name with a vertical line (|, pipe character) and either an e, an x, or a p. For example, to declare a parameter named alphaa in the model block, you could write alphaa|p directly in an equation where it appears. Similarly, to declare an endogenous variable c in the model block you could write c|e. Note that in-equation on-the-fly variable declarations must be made on contemporaneous variables.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"On-the-fly variable declarations do not have to appear in the first place where this variable is encountered.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The following two snippets are equivalent:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model;\n [endogenous='k',name='law of motion of capital']\n k(+1) = i|e + (1-delta|p)*k;\n y|e = k^alpha|p;\n ...\nend;\ndelta = 0.025;\nalpha = 0.36;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var k, i, y;\nparameters delta, alpha;\ndelta = 0.025;\nalpha = 0.36;\n...\nmodel;\n [name='law of motion of capital']\n k(1) = i|e + (1-delta|p)*k;\n y|e = k|e^alpha|p;\n ...\nend;","category":"page"},{"location":"model-file/model-declaration/#Model-declaration","page":"Model declaration","title":"Model declaration","text":"","category":"section"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The model is declared inside a model block:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Block: model ; ","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Block: model (OPTIONS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The equations of the model are written in a block delimited by model and end keywords.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"There must be as many equations as there are endogenous variables in the model, except when computing the unconstrained optimal policy with ramsey_model, ramsey_policy or discretionary_policy.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The syntax of equations must follow the conventions for MODEL_EXPRESSION as described in expr. Each equation must be terminated by a semicolon (';'). A normal equation looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"MODEL_EXPRESSION = MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"When the equations are written in homogenous form, it is possible to omit the '=0' part and write only the left hand side of the equation. A homogenous equation looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Inside the model block, Dynare allows the creation of model-local variables, which constitute a simple way to share a common expression between several equations. The syntax consists of a pound sign (#) followed by the name of the new model local variable (which must not be declared as in var-decl, but may have been declared by model_local_variable), an equal sign, and the expression for which this new variable will stand. Later on, every time this variable appears in the model, Dynare will substitute it by the expression assigned to the variable. Note that the scope of this variable is restricted to the model block; it cannot be used outside. To assign a LaTeX name to the model local variable, use the declaration syntax outlined by model_local_variable. A model local variable declaration looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"#VARIABLE_NAME = MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"It is possible to tag equations written in the model block. A tag can serve different purposes by allowing the user to attach arbitrary informations to each equation and to recover them at runtime. For instance, it is possible to name the equations with a name-tag, using a syntax like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n\n[name = 'Budget constraint'];\nc + k = k^theta*A;\n\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Here, name is the keyword indicating that the tag names the equation. If an equation of the model is tagged with a name, the resid command will display the name of the equations (which may be more informative than the equation numbers) in addition to the equation number. Several tags for one equation can be separated using a comma:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n\n[name='Taylor rule',mcp = 'r > -1.94478']\nr = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;\n\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"More information on tags is available at https://git.dynare.org/Dynare/dynare/-/wikis/Equations-Tags.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"There can be several model blocks, in which case they are simply concatenated. The set of effective options is also the concatenation of the options declared in all the blocks, but in that case you may rather want to use the model_options command.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Options","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"linear","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Declares the model as being linear. It spares oneself from having to declare initial values for computing the steady state of a stationary linear model. This option can't be used with non-linear models, it will NOT trigger linearization of the model.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"no_static","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Don't create the static model file. This can be useful for models which don't have a steady state.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"differentiate_forward_vars differentiate_forward_vars = (VARIABLE_NAME [VARIABLE_NAME ...] )","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Tells Dynare to create a new auxiliary variable for each endogenous variable that appears with a lead, such that the new variable is the time differentiate of the original one. More precisely, if the model contains x(+1), then a variable AUX_DIFF_VAR will be created such that AUX_DIFF_VAR=x-x(-1), and x(+1) will be replaced with x+AUX_DIFF_VAR(+1).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The transformation is applied to all endogenous variables with a lead if the option is given without a list of variables. If there is a list, the transformation is restricted to endogenous with a lead that also appear in the list.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This option can useful for some deterministic simulations where convergence is hard to obtain. Bad values for terminal conditions in the case of very persistent dynamics or permanent shocks can hinder correct solutions or any convergence. The new differentiated variables have obvious zero terminal conditions (if the terminal condition is a steady state) and this in many cases helps convergence of simulations.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"parallel_local_files = ( FILENAME [, FILENAME]... )","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Declares a list of extra files that should be transferred to follower nodes when doing a parallel computation (see paral-conf).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"balanced_growth_test_tol = DOUBLE","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Tolerance used for determining whether cross-derivatives are zero in the test for balanced growth path (the latter is documented on https://archives.dynare.org/DynareWiki/RemovingTrends). Default: 1e-6","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (Elementary RBC model)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k;\nvarexo x;\nparameters aa alph bet delt gam;\n\nmodel;\nc = - k + aa*x*k(-1)^alph + (1-delt)*k(-1);\nc^(-gam) = (aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam)/(1+bet);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (Use of model local variables)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The following program:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n# gamma = 1 - 1/sigma;\nu1 = c1^gamma/gamma;\nu2 = c2^gamma/gamma;\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"...is formally equivalent to:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\nu1 = c1^(1-1/sigma)/(1-1/sigma);\nu2 = c2^(1-1/sigma)/(1-1/sigma);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (A linear model)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model(linear);\nx = a*x(-1)+b*y(+1)+e_x;\ny = d*y(-1)+e_y;\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model_options (OPTIONS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This command accepts the same options as the model block.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The purpose of this statement is to specify the options that apply to the whole model, when there are several model blocks, so as to restore the symmetry between those blocks (since otherwise one model block would typically bear the options, while the other ones would typically have no option).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model_remove (TAGS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This command removes equations that appeared in a previous model block.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The equations must be specified by a list of tag values, separated by commas. Each element of the list is either a simple quoted string, in which case it designates an equation by its name tag; or a tag name (without quotes), followed by an equal sign, then by the tag value (within quotes).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Each removed equation must either have an endogenous tag, or have a left hand side containing a single endogenous variable. The corresponding endogenous variable will be either turned into an exogenous (if it is still used in somewhere in the model at that point), otherwise it will be removed from the model.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k dummy1 dummy2;\n\nmodel;\n c + k - aa*x*k(-1)^alph - (1-delt)*k(-1) + dummy1;\n c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\n [ name = 'eq:dummy1', endogenous = 'dummy1' ]\n c*k = dummy1;\n [ foo = 'eq:dummy2' ]\n log(dummy2) = k + 2;\nend;\n\n model_remove('eq:dummy1', foo = 'eq:dummy2');","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"In the above example, the last two equations will be removed, dummy1 will be turned into an exogenous, and dummy2 will be removed.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"block: model_replace (TAGS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This block replaces several equations in the model. It removes the equations given by the tags list (with the same syntax as in model_remove), and it adds equations given within the block (with the same syntax as model).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"No variable is removed or has its type changed in the process.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k;\n\nmodel;\n c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\n [ name = 'dummy' ]\n c*k = 1;\nend;\n\nmodel_replace('dummy');\n c^(-gam) = (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"In the above example, the dummy equation is replaced by a proper Euler equation.","category":"page"},{"location":"model-file/model-declaration/#Auxiliary-variables","page":"Model declaration","title":"Auxiliary variables","text":"","category":"section"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The model which is solved internally by Dynare is not exactly the model declared by the user. In some cases, Dynare will introduce auxiliary endogenous variables–-along with corresponding auxiliary equations–-which will appear in the final output.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The main transformation concerns leads and lags. Dynare will perform a transformation of the model so that there is only one lead and one lag on endogenous variables and no leads/lags on exogenous variables.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This transformation is achieved by the creation of auxiliary variables and corresponding equations. For example, if x(+2) exists in the model, Dynare will create one auxiliary variable AUX_ENDO_LEAD = x(+1), and replace x(+2) by AUX_ENDO_LEAD(+1).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"A similar transformation is done for lags greater than 2 on endogenous (auxiliary variables will have a name beginning with AUX_ENDO_LAG), and for exogenous with leads and lags (auxiliary variables will have a name beginning with AUX_EXO_LEAD or AUX_EXO_LAG respectively).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Another transformation is done for the EXPECTATION operator. For each occurrence of this operator, Dynare creates an auxiliary variable defined by a new equation, and replaces the expectation operator by a reference to the new auxiliary variable. For example, the expression EXPECTATION(-1)(x(+1)) is replaced by AUX_EXPECT_LAG_1(-1), and the new auxiliary variable is declared as AUX_EXPECT_LAG_1 = x(+2).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Auxiliary variables are also introduced by the preprocessor for the ramsey_model and ramsey_policy commands. In this case, they are used to represent the Lagrange multipliers when first order conditions of the Ramsey problem are computed. The new variables take the form MULT_i, where i represents the constraint with which the multiplier is associated (counted from the order of declaration in the model block).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Auxiliary variables are also introduced by the differentiate_forward_vars option of the model block. The new variables take the form AUX_DIFF_FWRD_i, and are equal to x-x(-1) for some endogenous variable x.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Finally, auxiliary variables will arise in the context of employing the diff-operator.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Once created, all auxiliary variables are included in the set of endogenous variables. The output of decision rules (see below) is such that auxiliary variable names are replaced by the original variables they refer to.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The number of endogenous variables before the creation of auxiliary variables is stored in context.models[1].orig_endo_nbr, and the number of endogenous variables after the creation of auxiliary variables is stored in context.models[1].endogenous_nbr.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"To study the effects of a temporary shock after which the system goes back to the original equilibrium (if the model is stable...) one uses a temporary shock. A temporary shock is a temporary change of value of one or several exogenous variables in the model. Temporary shocks are specified with the command shocks.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In a deterministic context, when one wants to study the transition of one equilibrium position to another, it is equivalent to analyze the consequences of a permanent shock. In Dynare this is done with initval, endval and steady.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In a stochastic framework, the exogenous variables take random values in each period. In Dynare, these random values follow a normal distribution with zero mean, but it belongs to the user to specify the variability of these shocks. The non-zero elements of the matrix of variance-covariance of the shocks can be entered with the shocks command.","category":"page"},{"location":"model-file/shocks/#Dynare-commands","page":"Shocks on exgogenous variables","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/shocks/#shocks","page":"Shocks on exgogenous variables","title":"shocks","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"block: shocks ; \nblock: shocks(overwrite);","category":"page"},{"location":"model-file/shocks/#Options","page":"Shocks on exgogenous variables","title":"Options","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"overwrite: By default, if there are several shocks blocks","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"in the same .mod file, then they are cumulative: all the shocks declared in all the blocks are considered; however, if a shocks block is declared with the overwrite option, then it replaces all the previous shocks blocks.","category":"page"},{"location":"model-file/shocks/#In-a-deterministic-context","page":"Shocks on exgogenous variables","title":"In a deterministic context","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"For deterministic simulations, the shocks block specifies temporary changes in the value of exogenous variables. For permanent shocks, use an endval block.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"The block should contain one or more occurrences of the following group of three lines:","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME;\nperiods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;\nvalues DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"It is possible to specify shocks which last several periods and which can vary over time. The periods keyword accepts a list of several dates or date ranges, which must be matched by as many shock values in the values keyword. Note that a range in the periods keyword can be matched by only one value in the values keyword. If values represents a scalar, the same value applies to the whole range. If values represents a vector, it must have as many elements as there are periods in the range.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Note that shock values are not restricted to numerical constants: arbitrary expressions are also allowed, but you have to enclose them inside parentheses.","category":"page"},{"location":"model-file/shocks/#Example-1","page":"Shocks on exgogenous variables","title":"Example 1","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\n\nvar e;\nperiods 1;\nvalues 0.5;\nvar u;\nperiods 4:5;\nvalues 0;\nvar v;\nperiods 4:5 6 7:9;\nvalues 1 1.1 0.9;\nvar w;\nperiods 1 2;\nvalues (1+p) (exp(z));\n\nend;","category":"page"},{"location":"model-file/shocks/#Example-2","page":"Shocks on exgogenous variables","title":"Example 2","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"xx = [1.2; 1.3; 1];\n\nshocks;\nvar e;\nperiods 1:3;\nvalues (xx);\nend;","category":"page"},{"location":"model-file/shocks/#In-a-stochastic-context","page":"Shocks on exgogenous variables","title":"In a stochastic context","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"For stochastic simulations, the shocks block specifies the non zero elements of the covariance matrix of the shocks of exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"You can use the following types of entries in the block:","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the standard error of an exogenous variable.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME; \nstderr EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the variance of an exogenous variable.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification the covariance of two exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME, VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the correlation of two exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"corr VARIABLE_NAME, VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In an estimation context, it is also possible to specify variances and covariances on endogenous variables: in that case, these values are interpreted as the calibration of the measurement errors on these variables. This requires the varobs command to be specified before the shocks block.","category":"page"},{"location":"model-file/shocks/#Example","page":"Shocks on exgogenous variables","title":"Example","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\nvar e = 0.000081;\nvar u; stderr 0.009;\ncorr e, u = 0.8;\nvar v, w = 2;\nend;","category":"page"},{"location":"model-file/shocks/#Remark","page":"Shocks on exgogenous variables","title":"Remark","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"If the variance of an exogenous variable is set to zero, this variable will appear in the report on policy and transition functions, but isn't used in the computation of moments and of Impulse Response Functions. Setting a variance to zero is an easy way of removing an exogenous shock.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In stochastic optimal policy context","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"When computing conditional welfare in a ramsey_model or discretionary_policy context, welfare is conditional on the state values inherited by planner when making choices in the first period. The information set of the first period includes the respective exogenous shock realizations. Thus, their known value can be specified using the perfect foresight syntax. Note that i) all other values specified for periods than period 1 will be ignored and ii) the value of lagged shocks (e.g. in the case of news shocks) is specified with histval.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Example","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\nvar u; stderr 0.008;\nvar u;\nperiods 1;\nvalues 1;\nend;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Mixing deterministic and stochastic shocks","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"It is possible to mix deterministic and stochastic shocks to build models where agents know from the start of the simulation about future exogenous changes. In that case stoch_simul will compute the rational expectation solution adding future information to the state space (nothing is shown in the output of stoch_simul) and forecast will compute a simulation conditional on initial conditions and future information.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Example","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"varexo_det tau;\nvarexo e;\n...\nshocks;\nvar e; stderr 0.01;\nvar tau;\nperiods 1:9;\nvalues -0.15;\nend;\n\nstoch_simul(irf=0);\n\nforecast;","category":"page"},{"location":"model-file/shocks/#Julia-function","page":"Shocks on exgogenous variables","title":"Julia function","text":"","category":"section"},{"location":"model-file/shocks/#scenario!()","page":"Shocks on exgogenous variables","title":"scenario!()","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"The Julia function scenario!() lets you","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"declare shocks on exogenous variables as the shocks block\nset the future value of endogenous variables (for conditional forecasts)\nadd the date at which the above information is made available to the agents in the model","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!","category":"page"},{"location":"model-file/shocks/#Dynare.scenario!","page":"Shocks on exgogenous variables","title":"Dynare.scenario!","text":"scenario!(; name=Symbol, period::PeriodSinceEpoch, value<:Number, context::Context=context,\n exogenous::Symbol=Symbol(), infoperiod::PeriodSinceEpoch=Undated(1))\n\nKeyword arguments\n\nname::Symbol: the name of an endogenous or exogenous variable [required]\nperiod::PeriodSinceEpoch: the period in which the value is set\nvalue<:PeriodSinceEpoch: the value of the endogenous or exogenous variables\ncontext: the context is which the function operates (optional, default = context)\nexogenous: when an endogenous variable is set, the name of the exogenous that must be freed (required when an endogenous variables is set)\ninfoperiod: the period in which the information is learned (optional, default = Undated(1))\n\n\n\n\n\n","category":"function"},{"location":"model-file/shocks/#Examples","page":"Shocks on exgogenous variables","title":"Examples","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(name = :e, value = 0.1, period = 2)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Exogenous variable e, takes value 0.1 in period 2.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(name = :y, value = 0.2, period=2, exogenous = :u)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model know at the beginning of period 1 that this will happen.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(infoperiod = 2, name = :y, value = 0.2, period = 2,\n exogenous = :u)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model only learn at the beginning of period 2 that this will happen.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"In a stochastic context, Dynare computes one or several simulations corresponding to a random draw of the shocks.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The main algorithm for solving stochastic models relies on a Taylor approximation, up to second order, of the solution function (see Judd (1996), Collard and Juillard (2001a, 2001b), and Schmitt-Grohé and Uríbe (2004)). The details of the Dynare implementation of the first order solution are given in Villemot (2011). Such a solution is computed using the stoch_simul command.","category":"page"},{"location":"model-file/local-approxiation/#Dynare-commands","page":"Local approximation","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/local-approxiation/#stoch_simul","page":"Local approximation","title":"stoch_simul","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Command: `stoch_simul;","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Command: `stoch_simul (OPTIONS...);","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Solves a stochastic (i.e. rational expectations) model, using perturbation techniques.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"More precisely, stoch_simul computes a Taylor approximation of the model around the deterministic steady state and solves of the the decision and transition functions for the approximated model. Using this, it computes impulse response functions and various descriptive statistics (moments, variance decomposition, correlation and autocorrelation coefficients). For correlated shocks, the variance decomposition is computed as in the VAR literature through a Cholesky decomposition of the covariance matrix of the exogenous variables. When the shocks are correlated, the variance decomposition depends upon the order of the variables in the varexo command.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The IRFs are computed as the difference between the trajectory of a variable following a shock at the beginning of period 1 and its steady state value. More details on the computation of IRFs can be found at https://archives.dynare.org/DynareWiki/IrFs.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Variance decomposition, correlation, autocorrelation are only displayed for variables with strictly positive variance. Impulse response functions are only plotted for variables with response larger than 10^-10.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Variance decomposition is computed relative to the sum of the contribution of each shock. Normally, this is of course equal to aggregate variance, but if a model generates very large variances, it may happen that, due to numerical error, the two differ by a significant amount. Dynare issues a warning if the maximum relative difference between the sum of the contribution of each shock and aggregate variance is larger than 0.01%.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The covariance matrix of the shocks is specified with the shocks command (see shocks-exo).","category":"page"},{"location":"model-file/local-approxiation/#Options","page":"Local approximation","title":"Options","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"ar = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Order of autocorrelation coefficients to compute. Default: 5","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"irf = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Number of periods on which to compute the IRFs. Setting irf=0 suppresses the plotting of IRFs. Default: 40.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"nonstationary: declares the model as nonstationary.\nnoprint: don't print the results\norder = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Order of Taylor approximation. Note that for third order and above, the k_order_solver option is implied and only empirical moments are available (you must provide a value for periods option). Default: 2","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"periods = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"If different from zero, empirical moments will be computed instead of theoretical moments. The value of the option specifies the number of periods to use in the simulations. Values of the initval block, possibly recomputed by steady, will be used as starting point for the simulation. The simulated endogenous variables are made available to the user in Julia variable context.results.model_results[1].simulation. Default: 0.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"dr = OPTION","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Determines the method used to compute the decision rule. Possible values for OPTION are:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"default","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Uses the default method to compute the decision rule based on the generalized Schur decomposition (see Villemot (2011) for more information).","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"cycle_reduction","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Uses the cycle reduction algorithm to solve the polynomial equation for retrieving the coefficients associated to the endogenous variables in the decision rule. This method is faster than the default one for large scale models.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Default value is default.","category":"page"},{"location":"model-file/local-approxiation/#Output","page":"Local approximation","title":"Output","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The derivatives of the approximated solution function are availabe in the vector of matrices context.results.model_results[1].solution_derivatives. The first element contains the matrix of first order derivatives. The second element, the matrix of second order derivatives.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The matrix of first order derivatives is a n x (n_s + n_x + 1) matrix where n is the number of endogenous variables, n_s, the number of state variables (variables appearing in the model with a lag), and n_x, the number of exogenous variables. An element of this matrix is","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"beginalign*\nX_ij = fracpartial g_ipartial y_jj=1ldotsn_s\nX_in_s+j = fracpartial g_ipartial x_jj=1ldotsn_x\nX_in_s+n_k+1 = fracpartial g_ipartial sigma = 0\nendalign*","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where g_i is the solution function for variable i, y, the vector of endogenous variables, x, the vector en exogenous variables and sigma the stochastic scale of the model. Note that at first order, this derivative is alwasy equal to zero. ","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The matrix of second order derivatives is n times n^2 matrix where each column contains derivatives with respect to a pair of endogenous variables","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"eigenvalues::Vector{Complex{Float64}}\ng1::Matrix{Float64} # full approximation\ngs1::Matrix{Float64} # state transition matrices: states x states\nhs1::Matrix{Float64} # states x shocks\ngns1::Matrix{Float64} # non states x states\nhns1::Matrix{Float64} # non states x shocsks\ng1_1::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int}}, UnitRange{Int}}, true}\t # solution first order derivatives w.r. to state variables\ng1_2::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int}}, UnitRange{Int}}, true} # solution first order derivatives w.r. to current exogenous variables\nendogenous_variance::Matrix{Float64}\nstationary_variables::Vector{Bool}","category":"page"},{"location":"model-file/local-approxiation/#Example-1","page":"Local approximation","title":"Example 1","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"shocks;\nvar e;\nstderr 0.0348;\nend;\n\nstoch_simul;","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Performs the simulation of the 1st-order approximation of a model with a single stochastic shock e, with a standard error of 0.0348.","category":"page"},{"location":"model-file/local-approxiation/#Example-2","page":"Local approximation","title":"Example 2","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":" stoch_simul(irf=60);","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Performs the simulation of a model and displays impulse response functions on 60 periods.","category":"page"},{"location":"model-file/local-approxiation/#Julia-function","page":"Local approximation","title":"Julia function","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"localapproximation!","category":"page"},{"location":"model-file/local-approxiation/#Dynare.localapproximation!","page":"Local approximation","title":"Dynare.localapproximation!","text":"localapproximation!(; context::Context=context, display = true,\n dr_algo::String = \"GS\", irf::Int = 40,\n LRE_options = LinearRationalExpectationsOptions(),\n nar::Int = 5, nonstationary::Bool = false,\n order::Int = 1, periods::Int = 0 )\n\ncomputes a local approximation of a model contained in context\n\nKeyword arguments\n\ncontext::Context=context: context in which the simulation is computed\ndisplay::Bool=true: whether to display the results\ndr_algo::String: solution algorithm, either \"GS\" for generalized Schur decomposition (default) or \"CR\" for cyclic reduction\nirf::Int = 40: number of periods for IRFs. Use 0 for no IRF computation\nLRE_options::LinearRationalExpectationsOptions = LinearRationalExpectationsOptions(): options passed to the LinearRationalExpectation package\nnar::Int = 5: numnber of periods for autocorrelations. Use 0 for no autocorrelation computation\nnonstationary::Bool = false: to specify a nonstationary model\nperiods::Int = 0: number of periods for an optional Monte Carlo simulation of the model\n\n\n\n\n\n","category":"function"},{"location":"model-file/local-approxiation/#First-order-approximation","page":"Local approximation","title":"First-order approximation","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The approximation has the stylized form:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"y_t = y^s + A phi(y_t-1) + B u_t","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where y^s is the steady state value of y and phi(y_t-1)=y_t-1-y^s. Matrices of coefficients A and B are computed by Dynare.","category":"page"},{"location":"model-file/local-approxiation/#Second-order-approximation","page":"Local approximation","title":"Second-order approximation","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The approximation has the form:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"y_t = y^s + 05 Delta^2 + A phi(y_t-1) + B u_t + 05 C\n(phi(y_t-1)otimes phi(y_t-1)) + 05 D (u_t otimes u_t) + E\n(phi(y_t-1) otimes u_t)","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where y^s is the steady state value of y, phi(y_t-1)=y_t-1-y^s, and Delta^2 is the shift effect of the variance of future shocks. Matrices of coefficients A, B, C, D and E are computed by Dynare. ","category":"page"},{"location":"model-file/forecasting/#Julia-functions","page":"Forecasting","title":"Julia functions","text":"","category":"section"},{"location":"model-file/forecasting/","page":"Forecasting","title":"Forecasting","text":"forecasting!","category":"page"},{"location":"model-file/forecasting/#Dynare.forecasting!","page":"Forecasting","title":"Dynare.forecasting!","text":"forecasting!(; periods::Integer,\n forecast_mode::ForecastModes,\n context::Context=context,\n datafile::String=\"\",\n first_obs::PeriodsSinceEpoch=Undated(typemin(Int)),\n first_period::PeriodsSinceEpoch=Undated(0),\n last_obs::PeriodsSinceEpoch=Undated(typemin(Int)),\n order::Integer=1)\n\ncomputes an unconditional forecast of the variables of the model\n\nKeyword arguments\n\nperiods::Integer: number of forecasted periods [required]\nforecast_mode::ForecastModes: one of histval or calibsmoother [required]\ndatafile::String: file with the observations for the smoother\nfirst_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file) \nfirst_period::PeriodsSinceEpoch: initial_period for the forecast (default when histval: Undated(0), default when calibsmoother: last period of the smoother)\nlast_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)\norder::Integer: order of local approximation\n\n\n\n\n\n","category":"function"},{"location":"model-file/forecasting/","page":"Forecasting","title":"Forecasting","text":"recursive_forecasting!","category":"page"},{"location":"model-file/forecasting/#Dynare.recursive_forecasting!","page":"Forecasting","title":"Dynare.recursive_forecasting!","text":"function recursiveforecasting!(; Np::Integer, firstperiod::PeriodsSinceEpoch, lastperiod::PeriodsSinceEpoch, context::Context=context, datafile::String=\"\", firstobs::PeriodsSinceEpoch=Undated(1), last_obs::PeriodsSinceEpoch=Undated(0), order::Integer=1) computes an unconditional recursive forecast for one variable by adding one period to the sample used for the smoother before forecasting over Np periods.\n\nKeyword arguments\n\nNp::Integer: number of forecasted periods [required]\nfirst_period::PeriodsSinceEpoch: initial period of first forecast [required]\nlast_period::PeriodsSinceEpoch: initial period of last forecast [required]\ndatafile::String: file with the observations for the smoother\nfirst_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file) \nlast_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)\norder::Integer: order of local approximation\n\n\n\n\n\n","category":"function"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"From a statistical point of view, DSGE models are unobserved components models: only a few variables are observed. Filtering or smoothing provide estimate of the unobserved variables given the observations.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"The model is put in state space form","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"beginalign*\ny^o_t = M s_t + Nepsilon_t\ns_t = Ts_t-1 + Reta_t\nendalign*","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where y^o_t represents observed variable at period t. The coefficient matrices of the transition equation, T and R are provided by the solution of the linear(-isze) rational expectation model. epsilon_t are possible measurement errors and eta_t the structural shocks. Most often matrix M is a selection matrix.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Filtering provides estimates conditional only on past observations:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"mathbbE(y^no_tY^o_t-1)","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where y^no_t are unobserved variables at period t and Y^o_t-1 represent the set observations until period t-1 included.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Smoothing provides estimates of unobserved variables conditional on the entire sample of observations:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"mathbbE(y^no_tY^o_T)","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where Y^o_T represents the all observations in the sample.","category":"page"},{"location":"model-file/filtersmoother/#Dynare-command","page":"State space, filtering and smoothing","title":"Dynare command","text":"","category":"section"},{"location":"model-file/filtersmoother/#varobs","page":"State space, filtering and smoothing","title":"varobs","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Observed variables are declared with the varobs command","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: varobs VARIABLE_NAME...;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command lists the name of observed endogenous variables for the estimation procedure. These variables must be available in the data file (see estimation_cmd ).","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Alternatively, this command is also used in conjunction with the partial_information option of stoch_simul, for declaring the set of observed variables when solving the model under partial information.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Only one instance of varobs is allowed in a model file. If one needs to declare observed variables in a loop, the macro processor can be used as shown in the second example below.","category":"page"},{"location":"model-file/filtersmoother/#Example","page":"State space, filtering and smoothing","title":"Example","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" varobs C y rr;","category":"page"},{"location":"model-file/filtersmoother/#observation_trends","page":"State space, filtering and smoothing","title":"observation_trends","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"It is possible to declare a deterministic linear trend that is removed for the computations and added back in the results","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Block: observation_trends ;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This block specifies linear trends for observed variables as functions of model parameters. In case the loglinear option is used, this corresponds to a linear trend in the logged observables, i.e. an exponential trend in the level of the observables.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Each line inside of the block should be of the form:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" VARIABLE_NAME(EXPRESSION);","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"In most cases, variables shouldn't be centered when observation_trends is used.","category":"page"},{"location":"model-file/filtersmoother/#Example-2","page":"State space, filtering and smoothing","title":"Example","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" observation_trends;\n Y (eta);\n P (mu/eta);\n end;","category":"page"},{"location":"model-file/filtersmoother/#calib_smoother","page":"State space, filtering and smoothing","title":"calib_smoother","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command triggers the computation of the filter and smoother for calibrated models","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: calib_smoother [VARIABLE_NAME]...; ","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: calib_smoother (OPTIONS...)[VARIABLE_NAME]...;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command computes the smoothed variables (and possible the filtered variables) on a calibrated model.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"A datafile must be provided, and the observable variables declared with varobs. The smoother is based on a first-order approximation of the model.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"By default, the command computes the smoothed variables and shocks and stores the results in oo_.SmoothedVariables and oo_.SmoothedShocks. It also fills oo_.UpdatedVariables.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Options","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"datafile = FILENAME: file containing the observation in CSV format.\nfiltered_vars: triggers the computation of filtered variables.\nfirst_obs = INTEGER: first observation\ndiffuse_filter = INTEGER: use a diffuse filter for nonstationary models.","category":"page"},{"location":"model-file/filtersmoother/#Julia-functions","page":"State space, filtering and smoothing","title":"Julia functions","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"calibsmoother!","category":"page"},{"location":"model-file/filtersmoother/#Dynare.calibsmoother!","page":"State space, filtering and smoothing","title":"Dynare.calibsmoother!","text":"calibsmoother!(; context::Context=context,\n datafile::String = \"\",\n data::AxisArrayTable = AxisArrayTable(Matrix{Float64}(undef, 0, 0), Undated[], Symbol[]),\n first_obs::PeriodSinceEpoch = Undated(typemin(Int)),\n last_obs::PeriodSinceEpoch = Undated(typemin(Int)),\n nobs::Int = 0\n )\n\nCompute the smoothed values of the variables for an estimated model\n\n#Keyword arguments\n\nperiods::Integer: number of forecasted periods [required]\ndatafile::String: file with the observations for the smoother\ndata::AxisArrayTable: AxisArrayTable containing observed variables (can't be used at the same time as datafile)\nfirst_obs::PeriodSinceEpoch: first period used by smoother (default: first observation in the dataset) \nlast_obs::PeriodSinceEpoch: last period used by smoother (default: last observation in the dataset)\nnobs::Int: number of observations (default: entire dataset)\n\n\n\n\n\n","category":"function"},{"location":"model-file/syntax-elements/#Model-File","page":"Syntax elements","title":"Model File","text":"","category":"section"},{"location":"model-file/syntax-elements/#Syntax-elements","page":"Syntax elements","title":"Syntax elements","text":"","category":"section"},{"location":"model-file/syntax-elements/#Conventions","page":"Syntax elements","title":"Conventions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"A model file contains a list of commands and of blocks. Each command and each element of a block is terminated by a semicolon (;). Blocks are terminated by end;.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"If Dynare encounters an unknown expression at the beginning of a line or after a semicolon, it will parse the rest of that line as native Julia code, even if there are more statements separated by semicolons present. To prevent cryptic error messages, it is strongly recommended to always only put one statement/command into each line and start a new line after each semicolon.[1]","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Lines of codes can be commented out line by line or as a block. Single-line comments begin with // and stop at the end of the line. Multiline comments are introduced by /* and terminated by */.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Examples","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"// This is a single line comment\n\nvar x; // This is a comment about x\n\n/* This is another inline comment about alpha */ alpha = 0.3;\n\n /*\n This comment is spanning\n two lines.\n */","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that these comment marks should not be used in native Julia code regions where the [#] should be preferred instead to introduce a comment. In a verbatim block, see verbatim, this would result in a crash since // is not a valid Julia statement).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Most Dynare commands have arguments and several accept options, indicated in parentheses after the command keyword. Several options are separated by commas.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"In the description of Dynare commands, the following conventions are observed:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Optional arguments or options are indicated between square brackets: '[]';\nRepeated arguments are indicated by ellipses: \"...\";\nMutually exclusive arguments are separated by vertical bars: '|';\nINTEGER indicates an integer number;\nINTEGER_VECTOR indicates a vector of integer numbers separated by spaces, enclosed by square brackets;\nDOUBLE indicates a double precision number. The following syntaxes are valid: 1.1e3, 1.1E3, 1.1d3, 1.1D3. In some places, infinite Values Inf and -Inf are also allowed;\nNUMERICAL_VECTOR indicates a vector of numbers separated by spaces, enclosed by square brackets;\nEXPRESSION indicates a mathematical expression valid outside the model description (see expr);\nMODEL_EXPRESSION (sometimes MODEL_EXP) indicates a mathematical expression valid in the model description (see expr and model-decl);\nMACRO_EXPRESSION designates an expression of the macro processor (see macro-exp);\nVARIABLE_NAME (sometimes VAR_NAME) indicates a variable name starting with an alphabetical character and can't contain: '()+-*/\\^=!;:@#.' or accentuated characters;\nPARAMETER_NAME (sometimes PARAM_NAME) indicates a parameter name starting with an alphabetical character and can't contain: '()+-*/\\^=!;:@#.' or accentuated characters;\nLATEX_NAME (sometimes TEX_NAME) indicates a valid LaTeX expression in math mode (not including the dollar signs);\nFUNCTION_NAME indicates a valid Julia function name;\nFILENAME indicates a filename valid in the underlying operating system; it is necessary to put it between quotes when specifying the extension or if the filename contains a non-alphanumeric character;\nQUOTED_STRING indicates an arbitrary string enclosed between (single) quotes. Note that Dynare commands call for single quotes around a string while in Julia strings are enclosed between double quotes.","category":"page"},{"location":"model-file/syntax-elements/#Expressions","page":"Syntax elements","title":"Expressions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Dynare distinguishes between two types of mathematical expressions: those that are used to describe the model, and those that are used outside the model block (e.g. for initializing parameters or variables, or as command options). In this manual, those two types of expressions are respectively denoted by MODEL_EXPRESSION and EXPRESSION.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Unlike Julia expressions, Dynare expressions are necessarily scalar ones: they cannot contain matrices or evaluate to matrices.[2]","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Expressions can be constructed using integers (INTEGER), floating point numbers (DOUBLE), parameter names (PARAMETER_NAME), variable names (VARIABLE_NAME), operators and functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following special constants are also accepted in some contexts:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Constant: inf","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Represents infinity.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Constant: nan","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"\"Not a number\": represents an undefined or unrepresentable value.","category":"page"},{"location":"model-file/syntax-elements/#Parameters-and-variables","page":"Syntax elements","title":"Parameters and variables","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Parameters and variables can be introduced in expressions by simply typing their names. The semantics of parameters and variables is quite different whether they are used inside or outside the model block.","category":"page"},{"location":"model-file/syntax-elements/#Inside-the-model","page":"Syntax elements","title":"Inside the model","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Parameters used inside the model refer to the value given through parameter initialization (see param-init) or homotopy_setup when doing a simulation, or are the estimated variables when doing an estimation.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Variables used in a MODEL_EXPRESSION denote current period values when neither a lead or a lag is given. A lead or a lag can be given by enclosing an integer between parenthesis just after the variable name: a positive integer means a lead, a negative one means a lag. Leads or lags of more than one period are allowed. For example, if c is an endogenous variable, then c(+1) is the variable one period ahead, and c(-2) is the variable two periods before.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"When specifying the leads and lags of endogenous variables, it is important to respect the following convention: in Dynare, the timing of a variable reflects when that variable is decided. A control variable –- which by definition is decided in the current period –- must have no lead. A predetermined variable –- which by definition has been decided in a previous period –- must have a lag. A consequence of this is that all stock variables must use the \"stock at the end of the period\" convention.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Leads and lags are primarily used for endogenous variables, but can be used for exogenous variables. They have no effect on parameters and are forbidden for local model variables (see Model declaration).","category":"page"},{"location":"model-file/syntax-elements/#Outside-the-model","page":"Syntax elements","title":"Outside the model","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"When used in an expression outside the model block, a parameter or a variable simply refers to the last value given to that variable. More precisely, for a parameter it refers to the value given in the corresponding parameter initialization (see param-init); for an endogenous or exogenous variable, it refers to the value given in the most recent initval or endval block.","category":"page"},{"location":"model-file/syntax-elements/#Operators","page":"Syntax elements","title":"Operators","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following operators are allowed in both MODEL_EXPRESSION and EXPRESSION:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Binary arithmetic operators: +, -, *, /, ^\nUnary arithmetic operators: +, -\nBinary comparison operators (which evaluate to either 0 or 1): <, >, <=, >=, ==, !=","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note the binary comparison operators are differentiable everywhere except on a line of the 2-dimensional real plane. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivatives of these operators with respect to both arguments is equal to 0 (since this is the value of the partial derivatives everywhere else).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following special operators are accepted in MODEL_EXPRESSION (but not in EXPRESSION):","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Operator: STEADYSTATE (MODELEXPRESSION)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"This operator is used to take the value of the enclosed expression at the steady state. A typical usage is in the Taylor rule, where you may want to use the value of GDP at steady state to compute the output gap.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Exogenous and exogenous deterministic variables may not appear in MODEL_EXPRESSION.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"note: Note\nThe concept of a steady state is ambiguous in a perfect foresight context with permament and potentially anticipated shocks occuring. Dynare will use the contents of oo_.steady_state as its reference for calls to the STEADY_STATE()-operator. In the presence of endval, this implies that the terminal state provided by the user is used. This may be a steady state computed by Dynare (if endval is followed by steady) or simply the terminal state provided by the user (if endval is not followed by steady). Put differently, Dynare will not automatically compute the steady state conditional on the specificed value of the exogenous variables in the respective periods.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Operator: EXPECTATION (INTEGER) (MODEL_EXPRESSION","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"This operator is used to take the expectation of some expression using a different information set than the information available at current period. For example, EXPECTATION(-1)(x(+1)) is equal to the expected value of variable x at next period, using the information set available at the previous period. See aux-variables for an explanation of how this operator is handled internally and how this affects the output.","category":"page"},{"location":"model-file/syntax-elements/#Functions","page":"Syntax elements","title":"Functions","text":"","category":"section"},{"location":"model-file/syntax-elements/#Built-in-functions","page":"Syntax elements","title":"Built-in functions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following standard functions are supported internally for both MODEL_EXPRESSION and EXPRESSION:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: exp(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Natural exponential.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: log(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: ln(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Natural logarithm.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: log10(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Base 10 logarithm.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sqrt(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Square root.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cbrt(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Cube root.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sign(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Signum function, defined as:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"beginaligned\n textrmsign(x) =\n begincases\n -1 quadtextif x0\n 0 quadtextif x=0\n 1 quadtextif x0\n endcases\n endaligned","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that this function is not continuous, hence not differentiable, at x=0. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at x=0 is equal to 0. This assumption comes from the observation that both the right- and left-derivatives at this point exist and are equal to 0, so we can remove the singularity by postulating that the derivative at x=0 is 0.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: abs(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Absolute value.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that this continuous function is not differentiable at x=0. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at x=0 is equal to 0 (even if the derivative does not exist). The rational for this mathematically unfounded definition, rely on the observation that the derivative of mathrmabs(x) is equal to mathrmsign(x) for any xneq 0 in mathbb R and from the convention for the value of mathrmsign(x) at x=0).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sin(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cos(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: tan(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: asin(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: acos(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: atan(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Trigonometric functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sinh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cosh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: tanh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: asinh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: acosh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: atanh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Hyperbolic functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: max(a, b)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: min(a, b)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Maximum and minimum of two reals.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that these functions are differentiable everywhere except on a line of the 2-dimensional real plane defined by a=b. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivative of these functions with respect to the first (resp. the second) argument is equal to 1 (resp. to 0) (i.e. the derivatives at the kink are equal to the derivatives observed on the half-plane where the function is equal to its first argument).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normcdf(x) ","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normcdf(x, mu, sigma)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gaussian cumulative density function, with mean mu and standard deviation sigma. Note that normcdf(x) is equivalent to normcdf(x,0,1).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normpdf(x) Function: normpdf(x, mu, sigma)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gaussian probability density function, with mean mu and standard deviation sigma. Note that normpdf(x) is equivalent to normpdf(x,0,1).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: erf(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gauss error function.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: erfc(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Complementary error function, i.e. mathrmerfc(x) = 1-mathrmerf(x).","category":"page"},{"location":"model-file/syntax-elements/#A-few-words-of-warning-in-stochastic-context","page":"Syntax elements","title":"A few words of warning in stochastic context","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The use of the following functions and operators is strongly discouraged in a stochastic context: max, min, abs, sign, <, >, <=, >=, ==, !=.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The reason is that the local approximation used by stoch_simul or estimation will by nature ignore the non-linearities introduced by these functions if the steady state is away from the kink. And, if the steady state is exactly at the kink, then the approximation will be bogus because the derivative of these functions at the kink is bogus (as explained in the respective documentations of these functions and operators).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that extended_path is not affected by this problem, because it does not rely on a local approximation of the mode.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Footnotes","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"[1]: A .mod file must have lines that end with a line feed character, which is not commonly visible in text editors. Files created on Windows and Unix-based systems have always conformed to this requirement, as have files created on OS X and macOS. Files created on old, pre-OS X Macs used carriage returns as end of line characters. If you get a Dynare parsing error of the form ERROR: <>: line 1, cols 341-347: syntax error,... and there's more than one line in your .mod file, know that it uses the carriage return as an end of line character. To get more helpful error messages, the carriage returns should be changed to line feeds.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"[2]: Note that arbitrary Julia expressions can be put in a .mod file, but those expressions have to be on separate lines, generally at the end of the file for post-processing purposes. They are not interpreted by Dynare, and are simply passed on unmodified to Julia. Those constructions are not addresses in this section.","category":"page"},{"location":"running-dynare/#Running-Dynare","page":"Running Dynare","title":"Running Dynare","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In order to give instructions to Dynare, the user has to write a model file whose filename extension must be .mod. This file contains the description of the model and the computing tasks required by the user. Its contents are described in The model file","category":"page"},{"location":"running-dynare/#Dynare-invocation","page":"Running Dynare","title":"Dynare invocation","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Once the model file is written, Dynare is invoked using the @dynare Julia macro (with the filename of the .mod given as argument).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In practice, the handling of the model file is done in two steps: in the first one, the model and the processing instructions written by the user in a model file are interpreted and the proper Julia instructions are generated; in the second step, the program actually runs the computations. Both steps are triggered automatically by the @dynare macro:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"context = @dynare \"FILENAME [.mod ]\" [OPTIONS... ]\";","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"This command launches Dynare and executes the instructions included in FILENAME.mod. This user-supplied file contains the model and the processing instructions, as described in The model file. The options, listed below, can be passed on the command line, following the name of the .mod file or in the first line of the .mod file itself (see below).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Dynare begins by launching the preprocessor on the .mod file.","category":"page"},{"location":"running-dynare/#Options","page":"Running Dynare","title":"Options","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"debug\nInstructs the preprocessor to write some debugging information about the scanning and parsing of the .mod file.\nnotmpterms\nInstructs the preprocessor to omit temporary terms in the static and dynamic files; this generally decreases performance, but is used for debugging purposes since it makes the static and dynamic files more readable.\nsavemacro\\[=FILENAME\\]\nInstructs Dynare to save the intermediary file which is obtained after macro processing (see (@ref \"Macro processing language\")); the saved output will go in the file specified, or if no file is specified in FILENAME-macroexp.mod. See the (@ref \"note on quotes\") for info on passing a FILENAME argument containing spaces.\nonlymacro\nInstructs the preprocessor to only perform the macro processing step, and stop just after. Useful for debugging purposes or for using the macro processor independently of the rest of Dynare toolbox.\nlinemacro\nInstructs the macro preprocessor include @#line directives specifying the line on which macro directives were encountered and expanded from. Only useful in conjunction with savemacro .\nonlymodel\nInstructs the preprocessor to print only information about the model in the driver file; no Dynare commands (other than the shocks statement and parameter initializations) are printed and hence no computational tasks performed. The same ancillary files are created as would otherwise be created (dynamic, static files, etc.).\nnolog\nInstructs Dynare to no create a logfile of this run in FILENAME.log. The default is to create the logfile.\noutput=second\\|third\nInstructs the preprocessor to output derivatives of the dynamic model at least up to the given order.\nlanguage=matlab\\|julia","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Instructs the preprocessor to write output for MATLAB or Julia. Default: MATLAB","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"params\\_derivs\\_order=0\\|1\\|2\nWhen (@ref \"identification\"), (@ref \"dynaresensitivity\") (with identification), or (@ref \"estimationcmd\") are present, this option is used to limit the order of the derivatives with respect to the parameters that are calculated by the preprocessor. 0 means no derivatives, 1 means first derivatives, and 2 means second derivatives. Default: 2\ntransform\\_unary\\_ops\nTransform the following operators in the model block into auxiliary variables: exp, log, log10, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, sqrt, cbrt, abs, sign, erf. Default: no obligatory transformation\njson = parse\\|transform\\|compute\nCauses the preprocessor to output a version of the .mod file in JSON format to <>/model/json/. When the JSON output is created depends on the value passed. These values represent various steps of processing in the preprocessor.\nIf parse is passed, the output will be written after the parsing of the .mod file to a file called FILENAME.json but before file has been checked (e.g. if there are unused exogenous in the model block, the JSON output will be created before the preprocessor exits).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If check is passed, the output will be written to a file called FILENAME.json after the model has been checked.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If transform is passed, the JSON output of the transformed model (maximum lead of 1, minimum lag of -1, expectation operators substituted, etc.) will be written to a file called FILENAME.json and the original, untransformed model will be written in FILENAME_original.json.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"And if compute is passed, the output is written after the computing pass. In this case, the transformed model is written to FILENAME.json, the original model is written to FILENAME_original.json, and the dynamic and static files are written to FILENAME_dynamic.json and FILENAME_static.json.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"jsonstdout\nInstead of writing output requested by json to files, write to standard out, i.e. to the Julia command window (and the log-file).\nonlyjson\nQuit processing once the output requested by json has been written.\njsonderivsimple\nPrint a simplified version (excluding variable name(s) and lag information) of the static and dynamic files in FILENAME_static.json and FILENAME_dynamic..\nwarn\\_uninit","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Display a warning for each variable or parameter which is not initialized. See (@ref \"Parameter initialization\"), or (@ref \"loadparamsandsteadystate\") for initialization of parameters. See (@ref \"Initial and Terminal conditions\"), or (@ref \"loadparamsandsteadystate\") for initialization of endogenous and exogenous variables.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"nopreprocessoroutput\nPrevent Dynare from printing the output of the steps leading up to the preprocessor as well as the preprocessor output itself.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"-DMACRO\\_VARIABLE\\[=MACRO\\_EXPRESSION\\]\nDefines a macro-variable from the command line (the same effect as using the Macro directive @#define in a model file, see (@ref \"Macro processing language\")). See the (@ref \"note on quotes\") for info on passing a MACRO_EXPRESSION argument containing spaces. Note that an expression passed on the command line can reference variables defined before it. If MACRO_EXPRESSION is omitted, the variable is assigned the true logical value.\nExample\nCall dynare with command line defines\njulia julia> @dynare <> -DA=true '-DB=\"A string with space\"' -DC=[1,2,3] '-DD=[ i in C when i > 1 ]' -DE;\n-I\\<\\\\>\nDefines a path to search for files to be included by the macro processor (using the @#include command). Multiple -I flags can be passed on the command line. The paths will be searched in the order that the -I flags are passed and the first matching file will be used. The flags passed here take priority over those passed to @#includepath. See the (@ref \"note on quotes\") for info on passing a <> argument containing spaces.\nnostrict\nAllows Dynare to issue a warning and continue processing when","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"there are more endogenous variables than equations.\nan undeclared symbol is assigned in initval or endval.\nan undeclared symbol is found in the model block in this case, it is automatically declared exogenous.\nexogenous variables were declared but not used in the model block.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"stochastic\nTells Dynare that the model to be solved is stochastic. If no Dynare commands related to stochastic models (stoch_simul, estimation, ...) are present in the .mod file, Dynare understands by default that the model to be solved is deterministic.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"exclude\\_eqs=\\<\\\\>\nTells Dynare to exclude all equations specified by the argument. As a .mod file must have the same number of endogenous variables as equations, when ***exclude_eqs*** is passed, certain rules are followed for excluding endogenous variables. If the endogenous tag has been set for the excluded equation, the variable it specifies is excluded. Otherwise, if the left hand side of the excluded equation is an expression that contains only one endogenous variable, that variable is excluded. If neither of these conditions hold, processing stops with an error. If an endogenous variable has been excluded by the ***exclude_eqs*** option and it exists in an equation that has not been excluded, it is transformed into an exogenous variable.\nTo specify which equations to exclude, you must pass the argument <>. This argument takes either a list of equation tags specifying the equations to be excluded or a filename that contains those tags.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If <> is a list of equation tags, it can take one of the following forms:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Given a single argument, e.g. exclude_eqs=eq1, the equation with the tag [name='eq1'] will be excluded. Note that if there is a file called eq1 in the current directory, Dynare will instead try to open this and read equations to exclude from it (see info on filename argument to exclude_eqs below). Further note that if the tag value contains a space, you must use the variant specified in 2 below, i.e. exclude_eqs=[eq 1].\nGiven two or more arguments, e.g. exclude_eqs=[eq1, eq 2], the equations with the tags [name='eq1'] and [name='eq 2'] will be excluded.\nIf you\\'d like to exclude equations based on another tag name (as opposed to the default name), you can pass the argument as either e.g. exclude_eqs=[tagname=a tag] if a single equation with tag [tagname='a tag'] is to be excluded or as e.g. exclude_eqs=[tagname=(a tag, 'a tag with a, comma')] if more than one equation with tags [tagname='a tag'] and [tagname='a tag with a, comma'] will be excluded (note the parenthesis, which are required when more than one equation is specified). Note that if the value of a tag contains a comma, it must be included inside single quotes.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If <> is a filename, the file can take one of the following forms:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"One equation per line of the file, where every line represents the value passed to the name tag. e.g., a file such as: julia eq1 eq 2 would exclude equations with tags [name='eq1'] and [name='eq 2'].\nOne equation per line of the file, where every line after the first line represents the value passed to the tag specified by the first line. e.g., a file such as: julia tagname= a tag a tag with a, comma would exclude equations with tags [tagname='a tag'] and [tagname='a tag with a, comma']. Here note that the first line must end in an equal sign.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"include\\_eqs=\\<\\\\>\nTells Dynare to run with only those equations specified by the argument; in other words, Dynare will exclude all equations not specified by the argument. The argument <> is specified in the same way as the argument to exclude_eqs . The functionality of include_eqs is to find which equations to exclude then take actions in accord with (@ref \"exclude_eqs\").\nnocommutativity","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"This option tells the preprocessor not to use the commutativity of addition and multiplication when looking for common subexpressions. As a consequence, when using this option, equations in various outputs (LaTeX, JSON...) will appear as the user entered them (without terms or factors swapped). Note that using this option may have a performance impact on the preprocessing stage, though it is likely to be small.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"These options can be passed to the preprocessor by listing them after the name of the .mod file. They can alternatively be defined in the first line of the .mod file, this avoids typing them on the command line each time a .mod file is to be run. This line must be a Dynare one-line comment (i.e. must begin with //) and the options must be whitespace separated between --+ options: and +--. Note that any text after the +-- will be discarded. As in the command line, if an option admits a value the equal symbol must not be surrounded by spaces. For instance json = compute is not correct, and should be written json=compute. The nopathchange option cannot be specified in this way, it must be passed on the command-line.","category":"page"},{"location":"running-dynare/#Understanding-Preprocessor-Error-Messages","page":"Running Dynare","title":"Understanding Preprocessor Error Messages","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If the preprocessor runs into an error while processing your .mod file, it will issue an error. Due to the way that a parser works, sometimes these errors can be misleading. Here, we aim to demystify these error messages.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"The preprocessor issues error messages of the form:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"ERROR: <>: line A, col B: <>\nERROR: <>: line A, cols B-C: <>\nERROR: <>: line A, col B - line C, col D: <>","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"The first two errors occur on a single line, with error two spanning multiple columns. Error three spans multiple rows.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Often, the line and column numbers are precise, leading you directly to the offending syntax. Infrequently however, because of the way the parser works, this is not the case. The most common example of misleading line and column numbers (and error message for that matter) is the case of a missing semicolon, as seen in the following example:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"varexo a, b\nparameters c, ...;","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In this case, the parser doesn't know a semicolon is missing at the end of the varexo command until it begins parsing the second line and bumps into the parameters command. This is because we allow commands to span multiple lines and, hence, the parser cannot know that the second line will not have a semicolon on it until it gets there. Once the parser begins parsing the second line, it realizes that it has encountered a keyword, parameters, which it did not expect. Hence, it throws an error of the form: ERROR: <>: line 2, cols 0-9: syntax error, unexpected PARAMETERS. In this case, you would simply place a semicolon at the end of line one and the parser would continue processing.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"There are three ways of computing the steady state (i.e. the static equilibrium) of a model. The first way is to provide the equations of the steady state in a steady_state_model block. When it is possible to derive the steady state by hand, this is the recommended way as it faster and more accurate.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The second way is to provide only a partial solution in the steady_state_model block and to compute the solution for the other variables numerically. Guess values for these other variables must be declared in a initval block. The less variables the better.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The third way is to compute the steady state value of all variables numerically. There is no steady_state_model block and a guess value must be declared for all variables. A guess value of 0 can be omitted, but be careful with variables appearing at the denominator of a fraction. ","category":"page"},{"location":"model-file/steady-state/#Providing-the-steady-state-to-Dynare","page":"Steady state","title":"Providing the steady state to Dynare","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"If you know how to compute the steady state for your model, you can provide a steady_state_model block, which is described below in more details. The steady state file generated by Dynare will be called +FILENAME/output/julia/FILENAME_steadystate2.jl.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Note that this block allows for updating the parameters in each call of the function. This allows for example to calibrate a model to a labor supply of 0.2 in steady state by setting the labor disutility parameter to a corresponding value. They can also be used in estimation where some parameter may be a function of an estimated parameter and needs to be updated for every parameter draw. For example, one might want to set the capital utilization cost parameter as a function of the discount rate to ensure that capacity utilization is 1 in steady state. Treating both parameters as independent or not updating one as a function of the other would lead to wrong results. But this also means that care is required. Do not accidentally overwrite your parameters with new values as it will lead to wrong results.","category":"page"},{"location":"model-file/steady-state/#Steady_state_model","page":"Steady state","title":"Steady_state_model","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: steady\\_state\\_model ;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"When the analytical solution of the model is known, this command can be used to help Dynare find the steady state in a more efficient and reliable way, especially during estimation where the steady state has to be recomputed for every point in the parameter space.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Each line of this block consists of a variable (either an endogenous, a temporary variable or a parameter) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above). Each line therefore looks like:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Note that it is also possible to assign several variables at the same time, if the main function in the right hand side is a MATLAB/Octave function returning several arguments:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"[ VARIABLE_NAME, VARIABLE_NAME... ] = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The steady_state_model block also works with deterministic models. An initval block and, when necessary, an endval block, is used to set the value of the exogenous variables. Each initval or endval block must be followed by steady to execute the function created by steady_state_model and set the initial, respectively terminal, steady state.","category":"page"},{"location":"model-file/steady-state/#Example","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var m P c e W R k d n l gy_obs gp_obs y dA;\nvarexo e_a e_m;\n\nparameters alp bet gam mst rho psi del;\n\n...\n// parameter calibration, (dynamic) model declaration, shock calibration...\n...\n\nsteady_state_model;\ndA = exp(gam);\ngst = 1/dA; // A temporary variable\nm = mst;\n\n// Three other temporary variables\nkhst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));\nxist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);\nnust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );\n\nn = xist/(nust+xist);\nP = xist + nust;\nk = khst*n;\n\nl = psi*mst*n/( (1-psi)*(1-n) );\nc = mst/P;\nd = l - mst + 1;\ny = k^alp*n^(1-alp)*gst^alp;\nR = mst/bet;\n\n// You can use MATLAB functions which return several arguments\n[W, e] = my_function(l, n);\n\ngp_obs = m/dA;\ngy_obs = dA;\nend;\n\nsteady;","category":"page"},{"location":"model-file/steady-state/#Finding-the-steady-state-with-Dynare-nonlinear-solver","page":"Steady state","title":"Finding the steady state with Dynare nonlinear solver","text":"","category":"section"},{"location":"model-file/steady-state/#Dynare-commands","page":"Steady state","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/steady-state/#initval","page":"Steady state","title":"initval","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: initval ; ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The initval block provides guess values for steady state computations. ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The initval block is terminated by end; and contains lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/#endval","page":"Steady state","title":"endval","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: endval ; ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The endval block can be used in a deterministic model to provide the guess values for computing a terminal steady state that is different from the initial steady state","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This block is terminated by end; and contains lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/#steady","page":"Steady state","title":"steady","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Command: steady ; \nCommand: steady (OPTIONS...);","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This command computes the steady state of a model using a nonlinear Newton-type solver and displays it.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"More precisely, it computes the equilibrium value of the endogenous variables for the value of the exogenous variables specified in the previous initval or endval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"steady uses an iterative procedure and takes as initial guess the value of the endogenous variables set in the previous initval or endval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"For complicated models, finding good numerical initial values for the endogenous variables is the trickiest part of finding the equilibrium of that model. Often, it is better to start with a smaller model and add new variables one by one.","category":"page"},{"location":"model-file/steady-state/#Options","page":"Steady state","title":"Options","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"maxit = INTEGER","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"tolf = DOUBLE","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Convergence criterion for termination based on the function value. Iteration will cease when the residuals are smaller than tolf. Default: eps^(1/3)","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"tolx = DOUBLE","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Convergence criterion for termination based on the step tolerance along. Iteration will cease when the attempted step size is smaller than tolx. Default: eps^(2/3)","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"homotopy_steps = INTEGER","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Defines the number of steps when performing a homotopy. See homotopy_mode option for more details.","category":"page"},{"location":"model-file/steady-state/#Output","page":"Steady state","title":"Output","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"After computation, the steady state is available in the following variables:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Julia variable: context.results.model_results[1].trends.endogenous_steady_state","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Contains the computed steady state. Endogenous variables are ordered in the order of declaration used in the var command,","category":"page"},{"location":"model-file/steady-state/#Example-2","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\nc^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;\n\ninitval;\nc = 1.2;\nk = 12;\nx = 1;\nend;\n\nsteady;\n\nendval;\nc = 2;\nk = 20;\nx = 2;\nend;\n\nsteady;\n","category":"page"},{"location":"model-file/steady-state/#Homotopy-setup","page":"Steady state","title":"Homotopy setup","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: homotopy_setup ;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This block is used to declare initial and final values for the parameters and exogenous variables when using a homotopy method. It is used in conjunction with the option homotopy_mode of the steady command.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The idea of homotopy is to subdivide the problem of finding the steady state into smaller problems. It assumes that you know how to compute the steady state for a given set of parameters, and it helps you finding the steady state for another set of parameters, by incrementally moving from one to another set of parameters.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The purpose of the homotopy_setup block is to declare the final (and possibly also the initial) values for the parameters or exogenous that will be changed during the homotopy. It should contain lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME, EXPRESSION, EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This syntax specifies the initial and final values of a given parameter/exogenous.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"There is an alternative syntax:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME, EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Here only the final value is specified for a given parameter/exogenous; the initial value is taken from the preceeding initval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"A necessary condition for a successful homotopy is that Dynare must be able to solve the steady state for the initial parameters/exogenous without additional help (using the guess values given in the initval block).","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"If the homotopy fails, a possible solution is to increase the number of steps (given in homotopy_steps option of steady).","category":"page"},{"location":"model-file/steady-state/#Example-3","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"In the following example, Dynare will first compute the steady state for the initial values (gam=0.5 and x=1), and then subdivide the problem into 50 smaller problems to find the steady state for the final values (gam=2 and x=2):","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n\nparameters alph gam delt bet aa;\nalph=0.5;\ndelt=0.02;\naa=0.5;\nbet=0.05;\n\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\nc^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;\n\ninitval;\nx = 1;\nk = ((delt+bet)/(aa*x*alph))^(1/(alph-1));\nc = aa*x*k^alph-delt*k;\nend;\n\nhomotopy_setup;\ngam, 0.5, 2;\nx, 2;\nend;\n\nsteady(homotopy_mode = 1, homotopy_steps = 50);","category":"page"},{"location":"model-file/steady-state/#Julia-function","page":"Steady state","title":"Julia function","text":"","category":"section"},{"location":"model-file/steady-state/#steadystate!","page":"Steady state","title":"steadystate!","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"steadystate!","category":"page"},{"location":"model-file/steady-state/#Dynare.steadystate!","page":"Steady state","title":"Dynare.steadystate!","text":"steadystate!(; context::Context=context, display::Bool = true,\n maxit::Int = 50, nocheck::Bool = false, tolf::Float64 = cbrt(eps()),\n tolx::Float64 = 0.0)\n\nKeyword arguments\n\ncontext::Context=context: context in which the simulation is computed\nhomotopy_steps::Int=0: number of homotopy steps\ndisplay::Bool=true: whether to display the results\nmaxit::Int=50 maximum number of iterations\nnocheck::Bool=false: don't check the steady state\ntolf::Float64=cbrt(eps()): tolerance for the norm of residualts\ntolx::Float64=0: tolerance for the norm of the change in the result\n\n\n\n\n\n","category":"function"},{"location":"model-file/steady-state/#Replace-some-equations-during-steady-state-computations","page":"Steady state","title":"Replace some equations during steady state computations","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"When there is no steady state file, Dynare computes the steady state by solving the static model, i.e. the model from the .mod file from which leads and lags have been removed.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"In some specific cases, one may want to have more control over the way this static model is created. Dynare therefore offers the possibility to explicitly give the form of equations that should be in the static model.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"More precisely, if an equation is prepended by a [static] tag, then it will appear in the static model used for steady state computation, but that equation will not be used for other computations. For every equation tagged in this way, you must tag another equation with [dynamic]: that equation will not be used for steady state computation, but will be used for other computations.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This functionality can be useful on models with a unit root, where there is an infinity of steady states. An equation (tagged [dynamic]) would give the law of motion of the nonstationary variable (like a random walk). To pin down one specific steady state, an equation tagged [static] would affect a constant value to the nonstationary variable. Another situation where the [static] tag can be useful is when one has only a partial closed form solution for the steady state.","category":"page"},{"location":"model-file/steady-state/#Example-4","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This is a trivial example with two endogenous variables. The second equation takes a different form in the static model:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n...\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\n[dynamic] c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\n[static] k = ((delt+bet)/(x*aa*alph))^(1/(alph-1));\nend;","category":"page"},{"location":"#The-Dynare-Julia-Reference-Manual","page":"Home","title":"The Dynare Julia Reference Manual","text":"","category":"section"},{"location":"#Introduction","page":"Home","title":"Introduction","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"DynareJulia is a rewriting of Dynare (https://www.dynare.org) that was initially written in Gauss in 1994 and rewritten in Matlab around 2000.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Dynare provides several algorithms to work with Dynamic Stochastic General Equilibrium (DSGE) models often used in macroeconomics. Among other features, it helps","category":"page"},{"location":"","page":"Home","title":"Home","text":"solving such models,\nsimulating them,\nestimating the parameters,\nmaking forecasts.","category":"page"},{"location":"","page":"Home","title":"Home","text":"The user of the package writes a text file, usually with an .mod extension, that contains the equations of the model and the computation tasks. Then, DynareJulia compiles the model and runs the computations.","category":"page"},{"location":"","page":"Home","title":"Home","text":"DynareJulia honors a subset of commands valid in DynareMatlab. Tell us if one of your favorite command or option is missing.","category":"page"},{"location":"","page":"Home","title":"Home","text":"For many computing tasks, DynareJulia provides also Julia functions that can be used in the *.mod file or issued interactively after having run the *.mod file. These Julia functions use keyword arguments for the options and you need only to enter them if you want to change the default value. The keyword arguments without a default value are required arguments. In the sections of this documentation, the Dynare Commands are presented first, then the Julia functions.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Dynare has benefited from many contributions over the years. Here is a list of the contributors:","category":"page"},{"location":"#The-Dynare-Team","page":"Home","title":"The Dynare Team","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Currently the development team of Dynare is composed of:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Stéphane Adjemian (Le Mans Université, Gains)\nMichel Juillard (Banque de France)\nSumudu Kankanamge (Toulouse School of Economics and CEPREMAP)\nFrédéric Karamé (Le Mans Université, Gains and CEPREMAP)\nJunior Maih (Norges Bank)\nWilli Mutschler (University of Tübingen)\nJohannes Pfeifer (Universität der Bundeswehr München)\nMarco Ratto (European Commission, Joint Research Centre - JRC)\nNormann Rion (CY Cergy Paris Université and CEPREMAP)\nSébastien Villemot (CEPREMAP)","category":"page"},{"location":"","page":"Home","title":"Home","text":"The following people contribute or have contributed to DynareJulia","category":"page"},{"location":"","page":"Home","title":"Home","text":"Satyanarayana Bade\nPetre Caraiani\nLilith Hafner\nMichel Juillard\nFélix Ordoñez\nLouis Ponet\nRohit Singh Rathaur\nDawie van Lill","category":"page"},{"location":"","page":"Home","title":"Home","text":"The following people used to be members of the Dynare team:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Houtan Bastani\nAbdeljabar Benzougar\nAlejandro Buesa\nFabrice Collard\nAssia Ezzeroug\nDóra Kocsis\nStéphane Lhuissier\nFerhat Mihoubi\nGeorge Perendia","category":"page"},{"location":"","page":"Home","title":"Home","text":"Copyright © 1996-2023, Dynare Team.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.","category":"page"},{"location":"","page":"Home","title":"Home","text":"A copy of the license can be found at https://www.gnu.org/licenses/fdl.txt.","category":"page"}] +[{"location":"macroprocessor/#Macro-processing-language","page":"Macroprocessing language","title":"Macro processing language","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is possible to use \"macro\" commands in the .mod file for performing tasks such as: including modular source files, replicating blocks of equations through loops, conditionally executing some code, writing indexed sums or products inside equations...","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The Dynare macro-language provides a new set of macro-commands which can be used in .mod files. It features:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"File inclusion\nLoops (for structure)\nConditional inclusion (if/then/else structures)\nExpression substitution","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This macro-language is totally independent of the basic Dynare language, and is processed by a separate component of the Dynare pre-processor. The macro processor transforms a .mod file with macros into a .mod file without macros (doing expansions/inclusions), and then feeds it to the Dynare parser. The key point to understand is that the macro processor only does text substitution (like the C preprocessor or the PHP language). Note that it is possible to see the output of the macro processor by using the savemacro option of the dynare command (see dyn-invoc).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The macro processor is invoked by placing macro directives in the .mod file. Directives begin with an at-sign followed by a pound sign (@#). They produce no output, but give instructions to the macro processor. In most cases, directives occupy exactly one line of text. If needed, two backslashes (\\\\) at the end of the line indicate that the directive is continued on the next line. Macro directives following // are not interpreted by the macro processor. For historical reasons, directives in commented blocks, ie surrounded by /* and */, are interpreted by the macro processor. The user should not rely on this behavior. The main directives are:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"@#includepath, paths to search for files that are to be included,\n@#include, for file inclusion,\n@#define, for defining a macro processor variable,\n@#if, @#ifdef, @#ifndef, @#elseif, @#else, @#endif for conditional statements,\n@#for, @#endfor for constructing loops.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The macro processor maintains its own list of variables (distinct from model variables and Julia variables). These macro-variables are assigned using the @#define directive and can be of the following basic types: boolean, real, string, tuple, function, and array (of any of the previous types).","category":"page"},{"location":"macroprocessor/#Macro-expressions","page":"Macroprocessing language","title":"Macro expressions","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro-expressions can be used in two places:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Inside macro directives, directly;\nIn the body of the .mod file, between an at-sign and curly braces: the macro processor will substitute the expression with its value","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is possible to construct macro-expressions that can be assigned to macro-variables or used within a macro-directive. The expressions are constructed using literals of the basic types (boolean, real, string, tuple, array), comprehensions, macro-variables, macro-functions, and standard operators.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"note: Note\nElsewhere in the manual, MACRO_EXPRESSION designates an expression constructed as explained in this section.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Boolean","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on booleans:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nLogical operators: &&, ||, !","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Real","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on reals:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Arithmetic operators: +, -, *, /, ^\nComparison operators: <, >, <=, >=, ==, !=\nLogical operators: &&, ||, !\nRanges with an increment of 1: REAL1:REAL2 (for example, 1:4 is equivalent to real array [1, 2, 3, 4]).\n4.6 Previously, putting brackets around the arguments to the colon operator (e.g. [1:4]) had no effect. Now, [1:4] will create an array containing an array (i.e. [ [1, 2, 3, 4] ]).\nRanges with user-defined increment: REAL1:REAL2:REAL3 (for example, 6:-2.1:-1 is equivalent to real array [6, 3.9, 1.8, -0.3]).\nFunctions: max, min, mod, exp, log, log10, sin, cos, tan, asin, acos, atan, sqrt, cbrt, sign, floor, ceil, trunc, erf, erfc, gamma, lgamma, round, normpdf, normcdf. NB ln can be used instead of log","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"String","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"String literals have to be enclosed by double quotes (like \"name\").","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on strings:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: <, >, <=, >=, ==, !=\nConcatenation of two strings: +\nExtraction of substrings: if s is a string, then s[3] is a string containing only the third character of s, and s[4:6] contains the characters from 4th to 6th\nFunction: length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Tuple","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Tuples are enclosed by parenthesis and elements separated by commas (like (a,b,c) or (1,2,3)).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on tuples:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nFunctions: empty, length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Array","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Arrays are enclosed by brackets, and their elements are separated by commas (like [1,[2,3],4] or [\"US\", \"FR\"]).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following operators can be used on arrays:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comparison operators: ==, !=\nDereferencing: if v is an array, then v[2] is its 2nd element\nConcatenation of two arrays: +\nSet union of two arrays: |\nSet intersection of two arrays: &\nDifference -: returns the first operand from which the elements of the second operand have been removed.\nCartesian product of two arrays: *\nCartesian product of one array N times: ^N\nExtraction of sub-arrays: e.g. v[4:6]\nTesting membership of an array: in operator (for example: \"b\" in [\"a\", \"b\", \"c\"] returns 1)\nFunctions: empty, sum, length","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comprehension","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Comprehension syntax is a shorthand way to make arrays from other arrays. There are three different ways the comprehension syntax can be employed: [filtering], [mapping], and [filtering and mapping].","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering allows one to choose those elements from an array for which a certain condition hold.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, choosing the even numbers from the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i in 1:5 when mod(i,2) == 0 ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [2, 4]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Mapping","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Mapping allows you to apply a transformation to every element of an array.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, squaring all elements of the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i^2 for i in 1:5 ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [1, 4, 9, 16, 25]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Filtering and Mapping","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Combining the two preceding ideas would allow one to apply a transformation to every selected element of an array.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Create a new array, squaring all even elements of the array 1:5:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ i^2 for i in 1:5 when mod(i,2) == 0]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [4, 16]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Further Examples :","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [ (j, i+1) for (i,j) in (1:2)^2 ]\n [ (j, i+1) for (i,j) in (1:2)*(1:2) when i < j ]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" [(1, 2), (2, 2), (1, 3), (2, 3)]\n [(2, 2)]","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Function","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Functions can be defined in the macro processor using the @#define directive (see below). A function is evaluated at the time it is invoked, not at define time. Functions can be included in expressions and the operators that can be combined with them depend on their return type.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Checking variable type","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Given a variable name or literal, you can check the type it evaluates to using the following functions: isboolean, isreal, isstring, istuple, and isarray.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\nisboolean(0) false\nisboolean(true) true\nisreal(\"str\") false","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Casting between types","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Variables and literals of one type can be cast into another type. Some type changes are straightforward (e.g. changing a [real]{.title-ref} to a [string]{.title-ref}) whereas others have certain requirements (e.g. to cast an [array]{.title-ref} to a [real]{.title-ref} it must be a one element array containing a type that can be cast to [real]{.title-ref}).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\n(bool) -1.1 true\n(bool) 0 false\n(real) \"2.2\" 2.2\n(tuple) [3.3] (3.3)\n(array) 4.4 [4.4]\n(real) [5.5] 5.5\n(real) [6.6, 7.7] error\n(real) \"8.8 in a string\" error","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Casts can be used in expressions:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Examples","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Code Output\n(bool) 0 && true false\n(real) \"1\" + 2 3\n(string) (3 + 4) \"7\"\n(array) 5 + (array) 6 [5, 6]","category":"page"},{"location":"macroprocessor/#Macro-directives","page":"Macroprocessing language","title":"Macro directives","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#includepath \"PATH\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive @#includepath MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This directive adds the path contained in PATH to the list of those to search when looking for a .mod file specified by @#include. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that these paths are added after any paths passed using -I <-I\\<\\\\>>{.interpreted-text role=\"opt\"}.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#includepath \"/path/to/folder/containing/modfiles\"\n @#includepath folders_containing_mod_files","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#include \"FILENAME\" ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#include MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This directive simply includes the content of another file in its place; it is exactly equivalent to a copy/paste of the content of the included file. If provided with a MACRO_EXPRESSION argument, the argument must evaluate to a string. Note that it is possible to nest includes (i.e. to include a file from an included file). The file will be searched for in the current directory. If it is not found, the file will be searched for in the folders provided by -I <-I\\<\\\\>>{.interpreted-text role=\"opt\"} and @#includepath.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#include \"modelcomponent.mod\"\n @#include location_of_modfile","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_VARIABLE ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_VARIABLE = MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#define MACRO_FUNCTION = MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Defines a macro-variable or macro function.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define var // Equals true\n @#define x = 5 // Real\n @#define y = \"US\" // String\n @#define v = [ 1, 2, 4 ] // Real array\n @#define w = [ \"US\", \"EA\" ] // String array\n @#define u = [ 1, [\"EA\"] ] // Mixed array\n @#define z = 3 + v[2] // Equals 5\n @#define t = (\"US\" in w) // Equals true\n @#define f(x) = \" \" + x + y // Function `f` with argument `x`\n // returns the string ' ' + x + 'US'","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define x = 1\n @#define y = [ \"B\", \"C\" ]\n @#define i = 2\n @#define f(x) = x + \" + \" + y[i]\n @#define i = 1\n\n model;\n A = @{y[i] + f(\"D\")};\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is strictly equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n A = BD + B;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#if MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#ifdef MACRO_VARIABLE","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#ifndef MACRO_VARIABLE ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#elseif MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#else @#endif","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Conditional inclusion of some part of the .mod file. The lines between @#if, @#ifdef, or @#ifndef and the next @#elseif, @#else or @#endif is executed only if the condition evaluates to true. Following the @#if body, you can zero or more @#elseif branches. An @#elseif condition is only evaluated if the preceding @#if or @#elseif condition evaluated to false. The @#else branch is optional and is only evaluated if all @#if and @#elseif statements evaluate to false.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that when using @#ifdef, the condition will evaluate to true if the MACROVARIABLE has been previously defined, regardless of its value. Conversely, @#ifndef will evaluate to true if the MACROVARIABLE has not yet been defined.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that when using @#elseif you can check whether or not a variable has been defined by using the defined operator. Hence, to enter the body of an @#elseif branch if the variable X has not been defined, you would write: @#elseif !defined(X).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that if a real appears as the result of the MACROEXPRESSION, it will be interpreted as a boolean; a value of 0 is interpreted as false, otherwise it is interpreted as true. Further note that because of the imprecision of reals, extra care must be taken when testing them in the MACROEXPRESSION. For example, exp(log(5)) == 5 will evaluate to false. Hence, when comparing real values, you should generally use a zero tolerance around the value desired, e.g. exp(log(5)) > 5-1e-14 && exp(log(5)) < 5+1e-14","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Choose between two alternative monetary policy rules using a macro-variable:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define linear_mon_pol = false // 0 would be treated the same\n ...\n model;\n @#if linear_mon_pol\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n @#else\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n @#endif\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" ...\n model;\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Choose between two alternative monetary policy rules using a macro-variable. The only difference between this example and the previous one is the use of @#ifdef instead of @#if. Even though linear_mon_pol contains the value false because @#ifdef only checks that the variable has been defined, the linear monetary policy is output:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define linear_mon_pol = false // 0 would be treated the same\n ...\n model;\n @#ifdef linear_mon_pol\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n @#else\n i = i(-1)^w * i_ss^(1-w) * (pie/piestar)^w2;\n @#endif\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This would result in:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" ...\n model;\n i = w*i(-1) + (1-w)*i_ss + w2*(pie-piestar);\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_VARIABLE in MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_VARIABLE in MACRO_EXPRESSION when MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_TUPLE in MACRO_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#for MACRO_TUPLE in MACRO_EXPRESSION when MACRO\\_EXPRESSION ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Loop construction for replicating portions of the .mod file. Note that this construct can enclose variable/parameters declaration, computational tasks, but not a model declaration.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n @#for country in [ \"home\", \"foreign\" ]\n GDP_@{country} = A * K_@{country}^a * L_@{country}^(1-a);\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n GDP_home = A * K_home^a * L_home^(1-a);\n GDP_foreign = A * K_foreign^a * L_foreign^(1-a);\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n @#for (i, j) in [\"GDP\"] * [\"home\", \"foreign\"]\n @{i}_@{j} = A * K_@{j}^a * L_@{j}^(1-a);\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n GDP_home = A * K_home^a * L_home^(1-a);\n GDP_foreign = A * K_foreign^a * L_foreign^(1-a);\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define countries = [\"US\", \"FR\", \"JA\"]\n @#define nth_co = \"US\"\n model;\n @#for co in countries when co != nth_co\n (1+i_@{co}) = (1+i_@{nth_co}) * E_@{co}(+1) / E_@{co};\n @#endfor\n E_@{nth_co} = 1;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The latter is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" model;\n (1+i_FR) = (1+i_US) * E_FR(+1) / E_FR;\n (1+i_JA) = (1+i_US) * E_JA(+1) / E_JA;\n E_US = 1;\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echo MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display some message on standard output. The argument must evaluate to a string.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#error MACRO_EXPRESSION","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display some error message on standard output and to abort. The argument must evaluate to a string.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars MACRO_VARIABLE_LIST","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Macro Directive: @#echomacrovars(save) MACRO_VARIABLE_LIST","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Asks the preprocessor to display the value of all macro variables up until this point. If the save option is passed, then values of the macro variables are saved to options_.macrovars_line_<>. If NAME_LIST is passed, only display/save variables and functions with that name.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define A = 1\n @#define B = 2\n @#define C(x) = x*2\n @#echomacrovars A C D","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The output of the command above is:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" Macro Variables:\n A = 1\n Macro Functions:\n C(x) = (x * 2)","category":"page"},{"location":"macroprocessor/#Typical-usages","page":"Macroprocessing language","title":"Typical usages","text":"","category":"section"},{"location":"macroprocessor/#Modularization","page":"Macroprocessing language","title":"Modularization","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The @#include directive can be used to split .mod files into several modular components.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example setup:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"modeldesc.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Contains variable declarations, model equations, and shocks declarations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"simul.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Includes modeldesc.mod, calibrates parameter,s and runs stochastic simulations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"estim.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Includes modeldesc.mod, declares priors on parameters, and runs Bayesian estimation.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Dynare can be called on simul.mod and estim.mod but it makes no sense to run it on modeldesc.mod.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The main advantage is that you don't have to copy/paste the whole model (at the beginning) or changes to the model (during development).","category":"page"},{"location":"macroprocessor/#Indexed-sums-of-products","page":"Macroprocessing language","title":"Indexed sums of products","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The following example shows how to construct a moving average:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define window = 2\n\n var x MA_x;\n ...\n model;\n ...\n MA_x = @{1/(2*window+1)}*(\n @#for i in -window:window\n +x(@{i})\n @#endfor\n );\n ...\n end;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"After macro processing, this is equivalent to:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" var x MA_x;\n ...\n model;\n ...\n MA_x = 0.2*(\n +x(-2)\n +x(-1)\n +x(0)\n +x(1)\n +x(2)\n );\n ...\n end;","category":"page"},{"location":"macroprocessor/#Multi-country-models","page":"Macroprocessing language","title":"Multi-country models","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Here is a skeleton example for a multi-country model:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define countries = [ \"US\", \"EA\", \"AS\", \"JP\", \"RC\" ]\n @#define nth_co = \"US\"\n\n @#for co in countries\n var Y_@{co} K_@{co} L_@{co} i_@{co} E_@{co} ...;\n parameters a_@{co} ...;\n varexo ...;\n @#endfor\n\n model;\n @#for co in countries\n Y_@{co} = K_@{co}^a_@{co} * L_@{co}^(1-a_@{co});\n ...\n @#if co != nth_co\n (1+i_@{co}) = (1+i_@{nth_co}) * E_@{co}(+1) / E_@{co}; // UIP relation\n @#else\n E_@{co} = 1;\n @#endif\n @#endfor\n end;","category":"page"},{"location":"macroprocessor/#Endogeneizing-parameters","page":"Macroprocessing language","title":"Endogeneizing parameters","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"When calibrating the model, it may be useful to consider a parameter as an endogenous variable (and vice-versa).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For example, suppose production is defined by a CES function:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"y = left(alpha^1xi ell^1-1xi+(1-alpha)^1xik^1-1xiright)^xi(xi-1)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"and the labor share in GDP is defined as:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"textrmlab_rat = (w ell)(p y)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In the model, alpha is a (share) parameter and lab_rat is an endogenous variable.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"It is clear that calibrating alpha is not straightforward; on the contrary, we have real world data for lab_rat and it is clear that these two variables are economically linked.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The solution is to use a method called variable flipping, which consists in changing the way of computing the steady state. During this computation, alpha will be made an endogenous variable and lab_rat will be made a parameter. An economically relevant value will be calibrated for lab_rat, and the solution algorithm will deduce the implied value for alpha.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"An implementation could consist of the following files:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"modeqs.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file contains variable declarations and model equations. The code for the declaration of alpha and lab_rat would look like:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#if steady\n var alpha;\n parameter lab_rat;\n @#else\n parameter alpha;\n var lab_rat;\n @#endif","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"steady.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file computes the steady state. It begins with:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define steady = 1\n @#include \"modeqs.mod\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Then it initializes parameters (including lab_rat, excluding alpha), computes the steady state (using guess values for endogenous, including alpha), then saves values of parameters and endogenous at steady state in a file, using the save_params_and_steady_state command.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"simul.mod","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This file computes the simulation. It begins with:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#define steady = 0\n @#include \"modeqs.mod\"","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Then it loads values of parameters and endogenous at steady state from file, using the load_params_and_steady_state command, and computes the simulations.","category":"page"},{"location":"macroprocessor/#Julia-loops-versus-macro-processor-loops","page":"Macroprocessing language","title":"Julia loops versus macro processor loops","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Suppose you have a model with a parameter rho and you want to run simulations for three values: rho = 08 09 1. There are several ways of doing this:","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a Julia loop","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" rhos = [ 0.8, 0.9, 1];\n for i = 1:length(rhos)\n rho = rhos(i);\n stoch_simul(order=1);\n end","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Here the loop is not unrolled, Julia manages the iterations. This is interesting when there are a lot of iterations.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a macro processor loop (case 1)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" rhos = [ 0.8, 0.9, 1];\n @#for i in 1:3\n rho = rhos(@{i});\n stoch_simul(order=1);\n @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This is very similar to the previous example, except that the loop is unrolled. The macro processor manages the loop index but not the data array (rhos).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"With a macro processor loop (case 2)","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" @#for rho_val in [ 0.8, 0.9, 1]\n rho = @{rho_val};\n stoch_simul(order=1);\n @#endfor","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The advantage of this method is that it uses a shorter syntax, since the list of values is directly given in the loop construct. The inconvenience is that you can not reuse the macro array in Julia.","category":"page"},{"location":"macroprocessor/#Verbatim-inclusion","page":"Macroprocessing language","title":"Verbatim inclusion","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Pass everything contained within the verbatim block to the .m file.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Block: verbatim ;","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"By default, whenever Dynare encounters code that is not understood by the parser, it is directly passed to the preprocessor output.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In order to force this behavior you can use the verbatim block. This is useful when the code you want passed to the .m file contains tokens recognized by the Dynare preprocessor.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Example","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":" verbatim;\n % Anything contained in this block will be passed\n % directly to the .m file, including comments\n var = 1;\n end;","category":"page"},{"location":"macroprocessor/#Misc-commands","page":"Macroprocessing language","title":"Misc commands","text":"","category":"section"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Command: `saveparamsandsteadystate (FILENAME); ","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For all parameters, endogenous and exogenous variables, stores their value in a text file, using a simple name/value associative table.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"for parameters, the value is taken from the last parameter initialization.\nfor exogenous, the value is taken from the last initval block.\nfor endogenous, the value is taken from the last steady state computation (or, if no steady state has been computed, from the last initval block).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Note that no variable type is stored in the file, so that the values can be reloaded with load_params_and_steady_state in a setup where the variable types are different.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The typical usage of this function is to compute the steady-state of a model by calibrating the steady-state value of some endogenous variables (which implies that some parameters must be endogeneized during the steady-state computation).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"You would then write a first .mod file which computes the steady state and saves the result of the computation at the end of the file, using save_params_and_steady_state.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"In a second file designed to perform the actual simulations, you would use load_params_and_steady_state just after your variable declarations, in order to load the steady state previously computed (including the parameters which had been endogeneized during the steady state computation).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"The need for two separate .mod files arises from the fact that the variable declarations differ between the files for steady state calibration and for simulation (the set of endogenous and parameters differ between the two); this leads to different var and parameters statements.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"Also note that you can take advantage of the @#include directive to share the model equations between the two files (see macro-proc-lang).","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"load_params_and_steady_state (FILENAME);","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"For all parameters, endogenous and exogenous variables, loads their value from a file created with save_params_and_steady_state.","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"for parameters, their value will be initialized as if they had been calibrated in the .mod file.\nfor endogenous and exogenous variables, their value will be initialized as they would have been from an initval block .","category":"page"},{"location":"macroprocessor/","page":"Macroprocessing language","title":"Macroprocessing language","text":"This function is used in conjunction with save_params_and_steady_state; see the documentation of that function for more information.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"When the framework is deterministic, Dynare can be used for models with the assumption of perfect foresight. The system is supposed to be in a given state before a period 1 (often a steady state) when the news of a contemporaneous or of a future shock is learned by the agents in the model. The purpose of the simulation is to describe the reaction in anticipation of, then in reaction to the shock, until the system returns to equilibrium. This return to equilibrium is only an asymptotic phenomenon, which one must approximate by an horizon of simulation far enough in the future. Another exercise for which Dynare is well suited is to study the transition path to a new equilibrium following a permanent shock. For deterministic simulations, the numerical problem consists of solving a nonlinear system of simultaneous equations in n endogenous variables in T periods. Dynare uses a Newton-type method to solve the simultaneous equation system. Because the resulting Jacobian is in the order of n by T and hence will be very large for long simulations with many variables, Dynare makes use of the sparse matrix code .","category":"page"},{"location":"model-file/deterministic-simulations/#Dynare-commands","page":"Deterministic simulations","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/deterministic-simulations/#perfect_foresight_setup","page":"Deterministic simulations","title":"perfect_foresight_setup","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_setup;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_setup (OPTIONS...);","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Prepares a perfect foresight simulation, by extracting the information in the initval, endval and shocks blocks and converting them into simulation paths for exogenous and endogenous variables.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"This command must always be called before running the simulation with perfect\\_foresight\\_solver.","category":"page"},{"location":"model-file/deterministic-simulations/#Options","page":"Deterministic simulations","title":"Options","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"periods = INTEGER","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Number of periods of the simulation.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"datafile = FILENAME","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Used to specify path for all endogenous and exogenous variables. Strictly equivalent to initval_file.","category":"page"},{"location":"model-file/deterministic-simulations/#Output","page":"Deterministic simulations","title":"Output","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The paths for the exogenous variables are stored into context.results.model_resultst[1].simulations.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The initial and terminal conditions for the endogenous variables and the initial guess for the path of endogenous variables are stored into context.results.model_results[1].simulations.","category":"page"},{"location":"model-file/deterministic-simulations/#perfect_foresight_solver","page":"Deterministic simulations","title":"perfect_foresight_solver","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_solver ;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Command: perfect\\_foresight\\_solver (OPTIONS...);","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Computes the perfect foresight (or deterministic) simulation of the model.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Note that perfect\\_foresight\\_setup must be called before this command, in order to setup the environment for the simulation.","category":"page"},{"location":"model-file/deterministic-simulations/#Options-2","page":"Deterministic simulations","title":"Options","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"maxit = INTEGER","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"tolf = DOUBLE","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Convergence criterion for termination based on the function value. Iteration will cease when it proves impossible to improve the function value by more than tolf. Default: 1e-5","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"tolx = DOUBLE","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Convergence criterion for termination based on the change in the function argument. Iteration will cease when the solver attempts to take a step that is smaller than tolx. Default: 1e-5","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"noprint","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Don't print anything. Useful for loops.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"print","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Print results (opposite of noprint).","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"lmmcp","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Solves mixed complementarity problems (the term refers to the LMMCP solver (Kanzow and Petra, 2004), that is used by DynareMatlab. DynareJulia uses the PATHSovler package)","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"endogenous_terminal_period","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The number of periods is not constant across Newton iterations when solving the perfect foresight model. The size of the nonlinear system of equations is reduced by removing the portion of the paths (and associated equations) for which the solution has already been identified (up to the tolerance parameter). This strategy can be interpreted as a mix of the shooting and relaxation approaches. Note that round off errors are more important with this mixed strategy (user should check the reported value of the maximum absolute error). Only available with option stack_solve_algo==0.","category":"page"},{"location":"model-file/deterministic-simulations/#Remark","page":"Deterministic simulations","title":"Remark","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Be careful when employing auxiliary variables in the context of perfect\nforesight computations. The same model may work for stochastic\nsimulations, but fail for perfect foresight simulations. The issue\narises when an equation suddenly only contains variables dated `t+1` (or\n`t-1` for that matter). In this case, the derivative in the last (first)\nperiod with respect to all variables will be 0, rendering the stacked\nJacobian singular.","category":"page"},{"location":"model-file/deterministic-simulations/#Example","page":"Deterministic simulations","title":"Example","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Consider the following specification of an Euler equation with log utility:","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Lambda = beta*C(-1)/C;\nLambda(+1)*R(+1)= 1;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Clearly, the derivative of the second equation with respect to all endogenous variables at time t is zero, causing perfect_foresight_solver to generally fail. This is due to the use of the Lagrange multiplier Lambda as an auxiliary variable. Instead, employing the identical","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"beta*C/C(+1)*R(+1)= 1;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"will work.","category":"page"},{"location":"model-file/deterministic-simulations/#Julia-function","page":"Deterministic simulations","title":"Julia function","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"perfect_foresight!","category":"page"},{"location":"model-file/deterministic-simulations/#Dynare.perfect_foresight!","page":"Deterministic simulations","title":"Dynare.perfect_foresight!","text":"perfect_foresight!(; periods, context = context, display = true,\n linear_solve_algo=ilu, maxit = 50, mcp = false,\n tolf = 1e-5, tolx = 1e-5)\n\nKeyword arguments\n\nperiods::Int: number of periods in the simulation [required]\ncontext::Context=context: context in which the simulation is computed\ndisplay::Bool=true: whether to display the results\nlinear_solve_algo::LinearSolveAlgo=ilu: algorithm used for the solution of the linear problem. Either ilu or pardiso. ilu is the sparse linear solver used by default in Julia. To use the Pardiso solver, write using Pardiso before running Dynare.\nmaxit::Int=50 maximum number of iterations\nmcp::Bool=falseL whether to solve a mixed complementarity problem with occasionally binding constraints\ntolf::Float64=1e-5: tolerance for the norm of residualts\ntolx::Float64=1e-5: tolerance for the norm of the change in the result\n\n\n\n\n\n","category":"function"},{"location":"model-file/deterministic-simulations/#Output-2","page":"Deterministic simulations","title":"Output","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"The simulated endogenous variables are available in context.results.model_results[1].simulations. This is a vector of AxisArrayTable, one for each simulations stored in context. Each AxisArrayTable contains the trajectories for endogenous and exogenous variables","category":"page"},{"location":"model-file/deterministic-simulations/#Solving-mixed-complementarity-problems","page":"Deterministic simulations","title":"Solving mixed complementarity problems","text":"","category":"section"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"requires a particular model setup as the goal is to get rid of any min/max operators and complementary slackness conditions that might introduce a singularity into the Jacobian. This is done by attaching an equation tag (see model-decl) with the mcp keyword to affected equations. The format of the mcp tag is","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"[mcp = 'VARIABBLENAME OP CONSTANT']","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"where VARIABLENAME is an endogenous variable and OP is either > or <. For complicated occasionally binding constraints, it may be necessary to declare a new endogenous variable.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"This tag states that the equation to which the tag is attached has to hold unless the expression within the tag is binding. For instance, a ZLB on the nominal interest rate would be specified as follows in the model block:","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":" model;\n ...\n [mcp = 'r > -1.94478']\n r = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;\n ...\n end;","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"where r is the nominal interest rate in deviation from the steady state. This construct implies that the Taylor rule is operative, unless the implied interest rate r<=-1.94478, in which case the r is fixed at -1.94478. This is equavalant to","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"(r_t -194478) bot r_t = rho r_t-1 + (1-rho) (g_pi Infl_t+g_y YGap_t) + e_t","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"By restricting the value of r coming out of this equation, the mcp tag also avoids using max(r,-1.94478) for other occurrences of r in the rest of the model. It is important to keep in mind that, because the mcp tag effectively replaces a complementary slackness condition, it cannot be simply attached to any equation.","category":"page"},{"location":"model-file/deterministic-simulations/","page":"Deterministic simulations","title":"Deterministic simulations","text":"Note that in the current implementation, the content of the mcp equation tag is not parsed by the preprocessor. The inequalities must therefore be as simple as possible: an endogenous variable, followed by a relational operator, followed by a number (not a variable, parameter or expression).","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Provided that you have observations on some endogenous variables, it is possible to use Dynare to estimate some or all parameters. Bayesian techniques (as in Fernández-Villaverde and Rubio-Ramírez (2004), Rabanal and Rubio-Ramirez (2003), Schorfheide (2000) or Smets and Wouters (2003)) are available. Using Bayesian methods, it is possible to estimate DSGE models.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Note that in order to avoid stochastic singularity, you must have at least as many shocks or measurement errors in your model as you have observed variables.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Before using the estimation commands described below, you need to define some elements of the state space representation of the model. At the minimum, you need to declare the observed variables with var_obs and, possibly, deterministic trends with observation_trends (see the previous section: State space, filtering and smoothing)","category":"page"},{"location":"model-file/estimation/#Dynare-commands","page":"Estimation","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/estimation/#estimated_params","page":"Estimation","title":"estimated_params","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params (overwrite) ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This block lists all parameters to be estimated and specifies bounds and priors as necessary.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Each line corresponds to an estimated parameter.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In a maximum likelihood or a method of moments estimation, each line follows this syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME\n , INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND ];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In a Bayesian MCMC or a penalized method of moments estimation, each line follows this syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME | DSGE_PRIOR_WEIGHT\n [, INITIAL_VALUE [, LOWER_BOUND, UPPER_BOUND]], PRIOR_SHAPE,\n PRIOR_MEAN, PRIOR_STANDARD_ERROR [, PRIOR_3RD_PARAMETER [,\n PRIOR_4TH_PARAMETER [, SCALE_PARAMETER ] ] ];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The first part of the line consists of one of the four following alternatives:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"stderr VARIABLE_NAME\nIndicates that the standard error of the exogenous variable VARIABLENAME, or of the observation error/measurement errors associated with endogenous observed variable VARIABLENAME, is to be estimated.\ncorr VARIABLE_NAME1, VARIABLE_NAME2\nIndicates that the correlation between the exogenous variables VARIABLENAME1 and VARIABLENAME2, or the correlation of the observation errors/measurement errors associated with endogenous observed variables VARIABLENAME1 and VARIABLENAME2, is to be estimated. Note that correlations set by previous shocks-blocks or estimation-commands are kept at their value set prior to estimation if they are not estimated again subsequently. Thus, the treatment is the same as in the case of deep parameters set during model calibration and not estimated.\nPARAMETER_NAME\nThe name of a model parameter to be estimated\nDSGE_PRIOR_WEIGHT\nSpecial name for the weigh of the DSGE model in DSGE-VAR model.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The rest of the line consists of the following fields, some of them being optional:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"INITIAL_VALUE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Specifies a starting value for the posterior mode optimizer or the maximum likelihood estimation. If unset, defaults to the prior mean.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"LOWER_BOUND","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"UPPER_BOUND","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_SHAPE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"A keyword specifying the shape of the prior density. The possible values are: beta_pdf, gamma_pdf, normal_pdf, uniform_pdf, inv_gamma_pdf, inv_gamma1_pdf, inv_gamma2_pdf and weibull_pdf. Note that inv_gamma_pdf is equivalent to inv_gamma1_pdf.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_MEAN","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The mean of the prior distribution.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_STANDARD_ERROR","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The standard error of the prior distribution.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_3RD_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported except for the Uniform","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"PRIOR_4TH_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Currently not supported","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"SCALE_PARAMETER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"A parameter specific scale parameter for the jumping distribution's covariance matrix of the Metropolis-Hasting algorithm.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Note that INITIALVALUE, LOWERBOUND, UPPERBOUND, PRIORMEAN, PRIORSTANDARDERROR, PRIOR3RDPARAMETER, PRIOR4THPARAMETER and SCALE_PARAMETER can be any valid EXPRESSION. Some of them can be empty, in which Dynare will select a default value depending on the context and the prior shape.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In case of the uniform distribution, it can be specified either by providing an upper and a lower bound using PRIOR_3RD_PARAMETER and PRIOR_4TH_PARAMETER or via mean and standard deviation using PRIOR_MEAN, PRIOR_STANDARD_ERROR. The other two will automatically be filled out. Note that providing both sets of hyperparameters will yield an error message.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"As one uses options more towards the end of the list, all previous options must be filled: for example, if you want to specify SCALEPARAMETER, you must specify `PRIOR3RDPARAMETERandPRIOR4TH_PARAMETER`. Use empty values, if these parameters don't apply.","category":"page"},{"location":"model-file/estimation/#Parameter-transformation","page":"Estimation","title":"Parameter transformation","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Sometimes, it is desirable to estimate a transformation of a parameter appearing in the model, rather than the parameter itself. It is of course possible to replace the original parameter by a function of the estimated parameter everywhere is the model, but it is often unpractical.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"In such a case, it is possible to declare the parameter to be estimated in the parameters statement and to define the transformation, using a pound sign (#) expression.","category":"page"},{"location":"model-file/estimation/#Example","page":"Estimation","title":"Example","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" parameters bet;\n\n model;\n # sig = 1/bet;\n c = sig*c(+1)*mpk;\n end;\n\n estimated_params;\n bet, normal_pdf, 1, 0.05;\n end;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"It is possible to have several estimated_params blocks. By default, subsequent blocks are concatenated with the previous ones; this can be useful when building models in a modular fashion (see also estimated_params_remove for that use case). However, if an estimated_params block has the overwrite option, its contents becomes the new list of estimated parameters, cancelling previous blocks; this can be useful when doing several estimations in a single .mod file.","category":"page"},{"location":"model-file/estimation/#estimated_params_init","page":"Estimation","title":"estimated_params_init","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params_init ;","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Block: estimated_params_init (OPTIONS...);","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This block declares numerical initial values for the optimizer when these ones are different from the prior mean. It should be specified after the estimated_params block as otherwise the specified starting values are overwritten by the latter.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Each line has the following syntax:","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" stderr VARIABLE_NAME | corr VARIABLE_NAME_1, VARIABLE_NAME_2 | PARAMETER_NAME, INITIAL_VALUE;","category":"page"},{"location":"model-file/estimation/#estimation","page":"Estimation","title":"estimation","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Command: estimation [VARIABLE_NAME...];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Command: estimation (OPTIONS...)[VARIABLE_NAME...];","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"This command runs Bayesian estimation.","category":"page"},{"location":"model-file/estimation/#Options","page":"Estimation","title":"Options","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"datafile = FILENAME","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The datafile must be in CSV format","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":" estimation(datafile='../fsdat_simul.csv',...);","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"nobs = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The number of observations following first_obs to be used. Default: all observations in the file after first_obs.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"first_obs = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The number of the first observation to be used. In case of estimating a DSGE-VAR, first_obs needs to be larger than the number of lags. Default: 1.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_priors = INTEGER: Control the plotting of priors, 0, no prior plot, 1, pPrior density for each estimated parameter is plotted. It is important to check that the actual shape of prior densities matches what you have in mind. Ill-chosen values for the prior standard density can result in absurd prior densities (default valueL 1).\nmh_replic = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Number of replications for each chain of the Metropolis-Hastings algorithm. The number of draws should be sufficient to achieve convergence of the MCMC and to meaningfully compute posterior objects. Default: 20000.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mh_nblocks = INTEGER","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"Number of parallel chains for Metropolis-Hastings algorithm. Default: 2.","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mh_jscale = DOUBLE","category":"page"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"The scale parameter of the jumping distribution's covariance matrix. The default value is rarely satisfactory. This option must be tuned to obtain, ideally, an acceptance ratio of 25%-33%. Basically, the idea is to increase the variance of the jumping distribution if the acceptance ratio is too high, and decrease the same variance if the acceptance ratio is too low. In some situations it may help to consider parameter-specific values for this scale parameter. This can be done in the estimated_params block. Default: 0.2.","category":"page"},{"location":"model-file/estimation/#Julia-functions","page":"Estimation","title":"Julia functions","text":"","category":"section"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"covariance","category":"page"},{"location":"model-file/estimation/#Dynare.covariance","page":"Estimation","title":"Dynare.covariance","text":"covariance(chain:Chains)\n\ncomputes the covariance matrix of MCMC chain\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"mode_compute!","category":"page"},{"location":"model-file/estimation/#Dynare.mode_compute!","page":"Estimation","title":"Dynare.mode_compute!","text":" mode_compute!(; \n context=context,\n data = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),\n datafile = \"\",\n diffuse_filter::Bool = false,\n display::Bool = false,\n fast_kalman_filter::Bool = true,\n first_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n initial_values = get_initial_value_or_mean(),\n last_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n mode_check::Bool = false,\n nobs::Int = 0,\n order::Int = 1,\n presample::Int = 0,\n transformed_parameters = true)\n\ncomputes the posterior mode.\n\nKeyword arguments\n\ncontext::Context=context: context of the computation\ndata::AxisArrayTable: AxisArrayTable containing observed variables\ndatafile::String: data filename (can't be used as the same time asdataset`)\nfirst_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)\ninitial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)\nlast_obs::PeriodsSinceEpoch: last period (default: last period of the dataset)\nnobs::Int = 0: number of observations (default: entire dataset)\ntransformed_parameters = true: whether to transform estimated parameter so as they take their value on R\n\nEither data or datafile must be specified.\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_priors ","category":"page"},{"location":"model-file/estimation/#Dynare.plot_priors","page":"Estimation","title":"Dynare.plot_priors","text":"plot_priors(; context::Context = context, n_points::Int = 100)\n\nplots prior density\n\nKeyword arguments\n\ncontext::Context = context: context in which to take the date to be ploted\nn_points::Int = 100: number of points used for a curve\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"plot_prior_posterior ","category":"page"},{"location":"model-file/estimation/#Dynare.plot_prior_posterior","page":"Estimation","title":"Dynare.plot_prior_posterior","text":"plot_prior_posterior(chains; context::Context=context)\n\nplots priors posterios and mode if computed on the same plots\n\nKeyword arguments\n\ncontext::Context=context: context used to get the estimation results\n\nOutput\n\nthe plots are saved in .//Graphs/PriorPosterior_.png\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"prior!","category":"page"},{"location":"model-file/estimation/#Dynare.prior!","page":"Estimation","title":"Dynare.prior!","text":" prior!(s::Symbol; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::stdev; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::variance; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n prior!(s::corr; shape::{<:Distributions}, initialvalue::Union{Real,Missing}=missing, mean::Union{Real,Missing}=missing, stdev::Union{Real,Missing}=missing, domain=[], variance ::Union{Real,Missing}=missing, context::Context=context)\n\ngenerates a prior for a symbol of a parameter, the standard deviation (stdev) or the variance (variance) of an exogenous variable or an endogenous variable (measurement error) or the correlation (corr) between 2 endogenous or exogenous variables\n\nKeywor arguments\n\nshape <: Distributions: the shape of the prior distribution (Beta, InvertedGamma, InvertedGamma1, Gamma, Normal, Uniform, Weibull) [required]\ncontext::Context=context: context in which the prior is declared\ndomain::Vector{<:Real}=Float64[]: domain for a uniform distribution\ninitialvalue::Union{Real,Missing}=missing: initialvalue for mode finding or MCMC iterations\nmean::Union{Real,Missing}=missing: mean of the prior distribution\nstdev::Union{Real,Missing}=missing: stdev of the prior distribution\nvariance::Union{Real,Missing}=missing: variance of the prior distribution\n\n\n\n\n\n","category":"function"},{"location":"model-file/estimation/","page":"Estimation","title":"Estimation","text":"rwmh_compute!","category":"page"},{"location":"model-file/estimation/#Dynare.rwmh_compute!","page":"Estimation","title":"Dynare.rwmh_compute!","text":"rwmh_compute!(;context::Context=context,\n back_transformation::Bool = true,\n datafile::String = \"\",\n data::AxisArrayTable = AxisArrayTable(AxisArrayTables.AxisArray(Matrix(undef, 0, 0))),\n diffuse_filter::Bool = false,\n display::Bool = true,\n fast_kalman_filter::Bool = true,\n first_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n initial_values = prior_mean(context.work.estimated_parameters),\n covariance::AbstractMatrix{Float64} = Matrix(prior_variance(context.work.estimated_parameters)),\n transformed_covariance::Matrix{Float64} = Matrix{Float64}(undef, 0,0),\n last_obs::PeriodsSinceEpoch = Undated(typemin(Int)),\n mcmc_chains::Int = 1,\n mcmc_init_scale::Float64 = 0.0,\n mcmc_jscale::Float64 = 0.0,\n mcmc_replic::Int = 0,\n mode_compute::Bool = true,\n nobs::Int = 0,\n order::Int = 1,\n plot_chain::Bool = true,\n plot_posterior_density::Bool = false, \n presample::Int = 0,\n transformed_parameters::Bool = true\n\n)\n\nruns random walk Monte Carlo simulations of the posterior\n\nKeyword arguments\n\ncontext::Context=context: context of the computation\ncovariance::AbstractMatrix{Float64}: \ndata::AxisArrayTable: AxisArrayTable containing observed variables\ndatafile::String: data filename\nfirst_obs::PeriodsSinceEpoch: first observation (default: first observation in the dataset)\ninitial_values: initival parameter values for optimization algorithm (default: estimated_params_init block if present or prior mean)\nlast_obs::PeriodsSinceEpoch: last period (default: last dataseet in the dataset)\nmcmc_chains::Int number of MCMC chains (default: 1)\nmcmc_jscale::Float64: scale factor of proposal\nmcmc_replic::Int: = 0,\nnobs::Int = 0: number of observations (default: entire dataset)\nplot_chain::Bool: whether to display standard MCMC chain output (default:true)\nplot_posterior_density::Bool: wether to display plots with prior and posterior densities (default: false)\ntransformed_covariance::Matrix{Float64}: covariance of transformed parameters (default: empty)\ntransformed_parameters = true: whether to transform estimated parameter so as they take their value on R\n\nEither data or datafile must be specified.\n\n\n\n\n\n","category":"function"},{"location":"installation-and-configuration/#Installation-and-configuration","page":"Installation and Configuration","title":"Installation and configuration","text":"","category":"section"},{"location":"installation-and-configuration/#Software-requirements","page":"Installation and Configuration","title":"Software requirements","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"Dynare is available for all plateforms supported by the current stable version of Julia (https://julialang.org/downloads/#supported_platforms). It should also work with older versions of Julia starting with version 1.6.3","category":"page"},{"location":"installation-and-configuration/#Installation-of-Dynare","page":"Installation and Configuration","title":"Installation of Dynare","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"In Julia, install the Dynare.jl package:","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using Pkg\npkg\"add Dynare\"","category":"page"},{"location":"installation-and-configuration/#Using-Dynare","page":"Installation and Configuration","title":"Using Dynare","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"In order to start using Dynare in Julia, type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using Dynare","category":"page"},{"location":"installation-and-configuration/#Optional-extensions","page":"Installation and Configuration","title":"Optional extensions","text":"","category":"section"},{"location":"installation-and-configuration/#Pardiso","page":"Installation and Configuration","title":"Pardiso","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"If you want the solution of very large perfect foresight models and reduce the memory consumption, use the Pardiso package (https://github.com/JuliaSparse/Pardiso.jl) and type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using MKL, Pardiso","category":"page"},{"location":"installation-and-configuration/#PATHSolver","page":"Installation and Configuration","title":"PATHSolver","text":"","category":"section"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"If youw want to solve perfect foresight models with occasionally binding constraints use the PATHSolver package (https://github.com/chkwon/PATHSolver.jl) and type","category":"page"},{"location":"installation-and-configuration/","page":"Installation and Configuration","title":"Installation and Configuration","text":"using PATHSolver","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"While Dynare allows the user to choose their own variable names, there are some restrictions to be kept in mind. First, variables and parameters must not have the same name as Dynare commands or built-in functions. In this respect, Dynare is not case-sensitive. For example, do not use Ln or Sigma_e to name your variable. Not conforming to this rule might yield hard-to-debug error messages or crashes. ","category":"page"},{"location":"model-file/variable-declarations/#var","page":"Variables and parameters declaration","title":"var","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRINGNAME=QUOTED_STRING)]...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var (deflator=MODEL_EXPR) VAR_NAME (... same options apply) var(log,deflator=MODEL_EXPR) VAR_NAME (... same options apply)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var (log_deflator=MODEL_EXPR) VAR_NAME (... same options apply)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This required command declares the endogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable or, if it is nonstationary, provide information regarding its deflator. The variables in the list can be separated by spaces or by commas. var commands can appear several times in the file and Dynare will concatenate them. ","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"If the model is nonstationary and is to be written as such in the model block, Dynare will need the trend deflator for the appropriate endogenous variables in order to stationarize the model. The trend deflator must be provided alongside the variables that follow this trend.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"log\nIn addition to the endogenous variable(s) thus declared, this option also triggers the creation of auxiliary variable(s) equal to the log of the corresponding endogenous variable(s). For example, given a var(log) y statement, two endogenous will be created (y and LOG_y), and an auxiliary equation linking the two will also be added (equal to LOG_y = log(y)). Moreover, every occurence of y in the model will be replaced by exp(LOG_y). This option is for example useful when one wants to perform a loglinear approximation of some variable(s) in the context of a first-order stochastic approximation; or when one wants to ensure the variable(s) stay(s) in the definition domain of the function defining the steady state or the dynamic residuals when the nonlinear solver is used.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"deflator = MODEL_EXPR\nThe expression used to detrend an endogenous variable. All trend variables, endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the trend_var, log_trend_var, var and parameters commands. The deflator is assumed to be multiplicative; for an additive deflator, use log_deflator. This option can be used together with the log option (the latter must come first).","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"log_deflator = MODEL_EXPR\nSame as deflator, except that the deflator is assumed to be additive instead of multiplicative (or, to put it otherwise, the declared variable is equal to the log of a variable with a multiplicative trend). This option cannot be used together with the log option, because it would not make much sense from an economic point of view (the corresponding auxiliary variable would correspond to the log taken two times on a variable with a multiplicative trend).","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nThis is the long version of the variable name. Its value is stored in M_.endo_names_long (a column cell array, in the same order as M_.endo_names). In case multiple long_name options are provided, the last one will be used. Default: VAR_NAME.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var c gnp cva \n cca (long_name=`Consumption CA');\nvar(deflator=A) i b;\nvar c $C$ (long_name=`Consumption');","category":"page"},{"location":"model-file/variable-declarations/#varexo","page":"Variables and parameters declaration","title":"varexo","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":" varexo VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares the exogenous variables in the model. Optionally it is possible to give a LaTeX name to the variable. Exogenous variables are required if the user wants to be able to apply shocks to her model. The variables in the list can be separated by spaces or by commas. varexo commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":" varexo m gov;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Remarks","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"An exogenous variable is an innovation, in the sense that this\nvariable cannot be predicted from the knowledge of the current\nstate of the economy. For instance, if logged TFP is a first order\nautoregressive process:\n```math\na_t=ρa_{t−1}+ε_t\n```","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"then logged TFP is an endogenous variable to be declared with var, while the innovation ε_t is to be declared with varexo.","category":"page"},{"location":"model-file/variable-declarations/#varexo_det","page":"Variables and parameters declaration","title":"varexo_det","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"varexo_det VAR_NAME [$TEX_NAME$][(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares exogenous deterministic variables in a stochastic model. Optionally it is possible to give a LaTeX name to the variable. The variables in the list can be separated by spaces or by commas. varexo_det commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"It is possible to mix deterministic and stochastic shocks to build models where agents know from the start of the simulation about future exogenous changes. In that case stoch_simul will compute the rational expectation solution adding future information to the state space (nothing is shown in the output of stoch_simul) and forecast will compute a simulation conditional on initial conditions and future information.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Note that exogenous deterministic variables cannot appear with a lead or a lag in the model.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nNAME = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"varexo m gov;\nvarexo_det tau;","category":"page"},{"location":"model-file/variable-declarations/#parameters","page":"Variables and parameters declaration","title":"parameters","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters PARAM_NAME [$TEX_NAME$] [(long_name=QUOTED_STRING|NAME=QUOTED_STRING)...];","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This command declares parameters used in the model, in variable\ninitialization or in shocks declaration. Optionally it is possible to give a\nLaTeX name to the parameter.\n\nThe parameters must subsequently be assigned values.\n\nThe parameters in the list can be separated by spaces or by commas.\n``parameters`` commands can appear several times in the file and Dynare\nwill concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Options","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"long_name = QUOTED_STRING\nNAME = QUOTED_STRING","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters alpha, bet;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Parameter initialization","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"When using Dynare for computing simulations, it is necessary to calibrate the parameters of the model. This is done through parameter initialization.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The syntax is the following:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"PARAMETER_NAME = EXPRESSION;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Here is an example of calibration:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"parameters alpha, beta;\n\nbeta = 0.99;\nalpha = 0.36;\nA = 1-alpha*beta;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Internally, the parameter values are stored in context.work.params","category":"page"},{"location":"model-file/variable-declarations/#Advanced-commands","page":"Variables and parameters declaration","title":"Advanced commands","text":"","category":"section"},{"location":"model-file/variable-declarations/#change_type","page":"Variables and parameters declaration","title":"change_type","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"change_type (var|varexo|varexo_det|parameters) VAR_NAME | PARAM_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Changes the types of the specified variables/parameters to another type: endogenous, exogenous, exogenous deterministic or parameter. It is important to understand that this command has a global effect on the mod file: the type change is effective after, but also before, the change_type command. This command is typically used when flipping some variables for steady state calibration: typically a separate model file is used for calibration, which includes the list of variable declarations with the macro processor, and flips some variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, w;\nparameters alpha, beta;\n...\nchange_type(var) alpha, beta;\nchange_type(parameters) y, w;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Here, in the whole model file, alpha and beta will be endogenous and y and w will be parameters.","category":"page"},{"location":"model-file/variable-declarations/#var_remove","page":"Variables and parameters declaration","title":"var_remove","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var_remove VAR_NAME | PARAM_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Removes the listed variables (or parameters) from the model. Removing a variable that has already been used in a model equation or elsewhere will lead to an error.","category":"page"},{"location":"model-file/variable-declarations/#predetermined_variables","page":"Variables and parameters declaration","title":"predetermined_variables","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"predetermined_variables VAR_NAME...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"In Dynare, the default convention is that the timing of a variable reflects when this variable is decided. The typical example is for capital stock: since the capital stock used at current period is actually decided at the previous period, then the capital stock entering the production function is k(-1), and the law of motion of capital must be written:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"k = i + (1-delta)*k(-1)","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Put another way, for stock variables, the default in Dynare is to use a \"stock at the end of the period\" concept, instead of a \"stock at the beginning of the period\" convention.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The predetermined_variables is used to change that convention. The endogenous variables declared as predetermined variables are supposed to be decided one period ahead of all other endogenous variables. For stock variables, they are supposed to follow a \"stock at the beginning of the period\" convention.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Note that Dynare internally always uses the \"stock at the end of the period\" concept, even when the model has been entered using the predetermined_variables command. Thus, when plotting, computing or simulating variables, Dynare will follow the convention to use variables that are decided in the current period. For example, when generating impulse response functions for capital, Dynare will plot k, which is the capital stock decided upon by investment today (and which will be used in tomorrow's production function). This is the reason that capital is shown to be moving on impact, because it is k and not the predetermined k(-1) that is displayed. It is important to remember that this also affects simulated time series and output from smoother routines for predetermined variables. Compared to non-predetermined variables they might otherwise appear to be falsely shifted to the future by one period.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The following two program snippets are strictly equivalent.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Using default Dynare timing convention:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, k, i;\n...\nmodel;\ny = k(-1)^alpha;\nk = i + (1-delta)*k(-1);\n...\nend;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Using the alternative timing convention:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var y, k, i;\npredetermined_variables k;\n...\nmodel;\ny = k^alpha;\nk(+1) = i + (1-delta)*k;\n...\nend;","category":"page"},{"location":"model-file/variable-declarations/#trend_var","page":"Variables and parameters declaration","title":"trend_var","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var (growth_factor = MODEL_EXPR) VAR_NAME[$LATEX_NAME$]...;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares the trend variables in the model. See conv for the syntax of MODEL_EXPR and VAR_NAME. Optionally it is possible to give a LaTeX name to the variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The variable is assumed to have a multiplicative growth trend. For an additive growth trend, use log_trend_var instead.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Trend variables are required if the user wants to be able to write a nonstationary model in the model block. The trend_var command must appear before the var command that references the trend variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var commands can appear several times in the file and Dynare will concatenate them.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"If the model is nonstationary and is to be written as such in the model block, Dynare will need the growth factor of every trend variable in order to stationarize the model. The growth factor must be provided within the declaration of the trend variable, using the growth_factor keyword. All endogenous variables and parameters referenced in MODEL_EXPR must already have been declared by the var and parameters commands.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"trend_var (growth_factor=gA) A;","category":"page"},{"location":"model-file/variable-declarations/#make_local_variables","page":"Variables and parameters declaration","title":"make_local_variables","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"command:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model_local_variable VARIABLE_NAME [LATEX_NAME]... ;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"This optional command declares a model local variable. See conv for the syntax of VARIABLE_NAME. As you can create model local variables on the fly in the model block, the interest of this command is primarily to assign a LATEX_NAME to the model local variable.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model_local_variable GDP_US $GDPUS$;","category":"page"},{"location":"model-file/variable-declarations/#On-the-fly-Model-Variable-Declaration","page":"Variables and parameters declaration","title":"On-the-fly Model Variable Declaration","text":"","category":"section"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Endogenous variables, exogenous variables, and parameters can also be declared inside the model block. You can do this in two different ways: either via the equation tag or directly in an equation.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"To declare a variable on-the-fly in an equation tag, simply state the type of variable to be declared (endogenous, exogenous, or parameter followed by an equal sign and the variable name in single quotes. Hence, to declare a variable c as endogenous in an equation tag, you can type [endogenous='c'].","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"To perform on-the-fly variable declaration in an equation, simply follow the symbol name with a vertical line (|, pipe character) and either an e, an x, or a p. For example, to declare a parameter named alphaa in the model block, you could write alphaa|p directly in an equation where it appears. Similarly, to declare an endogenous variable c in the model block you could write c|e. Note that in-equation on-the-fly variable declarations must be made on contemporaneous variables.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"On-the-fly variable declarations do not have to appear in the first place where this variable is encountered.","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"Example","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"The following two snippets are equivalent:","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"model;\n [endogenous='k',name='law of motion of capital']\n k(+1) = i|e + (1-delta|p)*k;\n y|e = k^alpha|p;\n ...\nend;\ndelta = 0.025;\nalpha = 0.36;","category":"page"},{"location":"model-file/variable-declarations/","page":"Variables and parameters declaration","title":"Variables and parameters declaration","text":"var k, i, y;\nparameters delta, alpha;\ndelta = 0.025;\nalpha = 0.36;\n...\nmodel;\n [name='law of motion of capital']\n k(1) = i|e + (1-delta|p)*k;\n y|e = k|e^alpha|p;\n ...\nend;","category":"page"},{"location":"model-file/model-declaration/#Model-declaration","page":"Model declaration","title":"Model declaration","text":"","category":"section"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The model is declared inside a model block:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Block: model ; ","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Block: model (OPTIONS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The equations of the model are written in a block delimited by model and end keywords.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"There must be as many equations as there are endogenous variables in the model, except when computing the unconstrained optimal policy with ramsey_model, ramsey_policy or discretionary_policy.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The syntax of equations must follow the conventions for MODEL_EXPRESSION as described in expr. Each equation must be terminated by a semicolon (';'). A normal equation looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"MODEL_EXPRESSION = MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"When the equations are written in homogenous form, it is possible to omit the '=0' part and write only the left hand side of the equation. A homogenous equation looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Inside the model block, Dynare allows the creation of model-local variables, which constitute a simple way to share a common expression between several equations. The syntax consists of a pound sign (#) followed by the name of the new model local variable (which must not be declared as in var-decl, but may have been declared by model_local_variable), an equal sign, and the expression for which this new variable will stand. Later on, every time this variable appears in the model, Dynare will substitute it by the expression assigned to the variable. Note that the scope of this variable is restricted to the model block; it cannot be used outside. To assign a LaTeX name to the model local variable, use the declaration syntax outlined by model_local_variable. A model local variable declaration looks like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"#VARIABLE_NAME = MODEL_EXPRESSION;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"It is possible to tag equations written in the model block. A tag can serve different purposes by allowing the user to attach arbitrary informations to each equation and to recover them at runtime. For instance, it is possible to name the equations with a name-tag, using a syntax like:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n\n[name = 'Budget constraint'];\nc + k = k^theta*A;\n\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Here, name is the keyword indicating that the tag names the equation. If an equation of the model is tagged with a name, the resid command will display the name of the equations (which may be more informative than the equation numbers) in addition to the equation number. Several tags for one equation can be separated using a comma:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n\n[name='Taylor rule',mcp = 'r > -1.94478']\nr = rho*r(-1) + (1-rho)*(gpi*Infl+gy*YGap) + e;\n\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"More information on tags is available at https://git.dynare.org/Dynare/dynare/-/wikis/Equations-Tags.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"There can be several model blocks, in which case they are simply concatenated. The set of effective options is also the concatenation of the options declared in all the blocks, but in that case you may rather want to use the model_options command.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Options","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"linear","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Declares the model as being linear. It spares oneself from having to declare initial values for computing the steady state of a stationary linear model. This option can't be used with non-linear models, it will NOT trigger linearization of the model.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"no_static","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Don't create the static model file. This can be useful for models which don't have a steady state.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"differentiate_forward_vars differentiate_forward_vars = (VARIABLE_NAME [VARIABLE_NAME ...] )","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Tells Dynare to create a new auxiliary variable for each endogenous variable that appears with a lead, such that the new variable is the time differentiate of the original one. More precisely, if the model contains x(+1), then a variable AUX_DIFF_VAR will be created such that AUX_DIFF_VAR=x-x(-1), and x(+1) will be replaced with x+AUX_DIFF_VAR(+1).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The transformation is applied to all endogenous variables with a lead if the option is given without a list of variables. If there is a list, the transformation is restricted to endogenous with a lead that also appear in the list.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This option can useful for some deterministic simulations where convergence is hard to obtain. Bad values for terminal conditions in the case of very persistent dynamics or permanent shocks can hinder correct solutions or any convergence. The new differentiated variables have obvious zero terminal conditions (if the terminal condition is a steady state) and this in many cases helps convergence of simulations.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"parallel_local_files = ( FILENAME [, FILENAME]... )","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Declares a list of extra files that should be transferred to follower nodes when doing a parallel computation (see paral-conf).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"balanced_growth_test_tol = DOUBLE","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Tolerance used for determining whether cross-derivatives are zero in the test for balanced growth path (the latter is documented on https://archives.dynare.org/DynareWiki/RemovingTrends). Default: 1e-6","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (Elementary RBC model)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k;\nvarexo x;\nparameters aa alph bet delt gam;\n\nmodel;\nc = - k + aa*x*k(-1)^alph + (1-delt)*k(-1);\nc^(-gam) = (aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam)/(1+bet);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (Use of model local variables)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The following program:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\n# gamma = 1 - 1/sigma;\nu1 = c1^gamma/gamma;\nu2 = c2^gamma/gamma;\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"...is formally equivalent to:","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model;\nu1 = c1^(1-1/sigma)/(1-1/sigma);\nu2 = c2^(1-1/sigma)/(1-1/sigma);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example (A linear model)","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model(linear);\nx = a*x(-1)+b*y(+1)+e_x;\ny = d*y(-1)+e_y;\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model_options (OPTIONS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This command accepts the same options as the model block.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The purpose of this statement is to specify the options that apply to the whole model, when there are several model blocks, so as to restore the symmetry between those blocks (since otherwise one model block would typically bear the options, while the other ones would typically have no option).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"model_remove (TAGS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This command removes equations that appeared in a previous model block.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The equations must be specified by a list of tag values, separated by commas. Each element of the list is either a simple quoted string, in which case it designates an equation by its name tag; or a tag name (without quotes), followed by an equal sign, then by the tag value (within quotes).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Each removed equation must either have an endogenous tag, or have a left hand side containing a single endogenous variable. The corresponding endogenous variable will be either turned into an exogenous (if it is still used in somewhere in the model at that point), otherwise it will be removed from the model.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k dummy1 dummy2;\n\nmodel;\n c + k - aa*x*k(-1)^alph - (1-delt)*k(-1) + dummy1;\n c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\n [ name = 'eq:dummy1', endogenous = 'dummy1' ]\n c*k = dummy1;\n [ foo = 'eq:dummy2' ]\n log(dummy2) = k + 2;\nend;\n\n model_remove('eq:dummy1', foo = 'eq:dummy2');","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"In the above example, the last two equations will be removed, dummy1 will be turned into an exogenous, and dummy2 will be removed.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"block: model_replace (TAGS...);","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This block replaces several equations in the model. It removes the equations given by the tags list (with the same syntax as in model_remove), and it adds equations given within the block (with the same syntax as model).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"No variable is removed or has its type changed in the process.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Example","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"var c k;\n\nmodel;\n c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\n [ name = 'dummy' ]\n c*k = 1;\nend;\n\nmodel_replace('dummy');\n c^(-gam) = (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"In the above example, the dummy equation is replaced by a proper Euler equation.","category":"page"},{"location":"model-file/model-declaration/#Auxiliary-variables","page":"Model declaration","title":"Auxiliary variables","text":"","category":"section"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The model which is solved internally by Dynare is not exactly the model declared by the user. In some cases, Dynare will introduce auxiliary endogenous variables–-along with corresponding auxiliary equations–-which will appear in the final output.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The main transformation concerns leads and lags. Dynare will perform a transformation of the model so that there is only one lead and one lag on endogenous variables and no leads/lags on exogenous variables.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"This transformation is achieved by the creation of auxiliary variables and corresponding equations. For example, if x(+2) exists in the model, Dynare will create one auxiliary variable AUX_ENDO_LEAD = x(+1), and replace x(+2) by AUX_ENDO_LEAD(+1).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"A similar transformation is done for lags greater than 2 on endogenous (auxiliary variables will have a name beginning with AUX_ENDO_LAG), and for exogenous with leads and lags (auxiliary variables will have a name beginning with AUX_EXO_LEAD or AUX_EXO_LAG respectively).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Another transformation is done for the EXPECTATION operator. For each occurrence of this operator, Dynare creates an auxiliary variable defined by a new equation, and replaces the expectation operator by a reference to the new auxiliary variable. For example, the expression EXPECTATION(-1)(x(+1)) is replaced by AUX_EXPECT_LAG_1(-1), and the new auxiliary variable is declared as AUX_EXPECT_LAG_1 = x(+2).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Auxiliary variables are also introduced by the preprocessor for the ramsey_model and ramsey_policy commands. In this case, they are used to represent the Lagrange multipliers when first order conditions of the Ramsey problem are computed. The new variables take the form MULT_i, where i represents the constraint with which the multiplier is associated (counted from the order of declaration in the model block).","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Auxiliary variables are also introduced by the differentiate_forward_vars option of the model block. The new variables take the form AUX_DIFF_FWRD_i, and are equal to x-x(-1) for some endogenous variable x.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Finally, auxiliary variables will arise in the context of employing the diff-operator.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"Once created, all auxiliary variables are included in the set of endogenous variables. The output of decision rules (see below) is such that auxiliary variable names are replaced by the original variables they refer to.","category":"page"},{"location":"model-file/model-declaration/","page":"Model declaration","title":"Model declaration","text":"The number of endogenous variables before the creation of auxiliary variables is stored in context.models[1].orig_endo_nbr, and the number of endogenous variables after the creation of auxiliary variables is stored in context.models[1].endogenous_nbr.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"To study the effects of a temporary shock after which the system goes back to the original equilibrium (if the model is stable...) one uses a temporary shock. A temporary shock is a temporary change of value of one or several exogenous variables in the model. Temporary shocks are specified with the command shocks.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In a deterministic context, when one wants to study the transition of one equilibrium position to another, it is equivalent to analyze the consequences of a permanent shock. In Dynare this is done with initval, endval and steady.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In a stochastic framework, the exogenous variables take random values in each period. In Dynare, these random values follow a normal distribution with zero mean, but it belongs to the user to specify the variability of these shocks. The non-zero elements of the matrix of variance-covariance of the shocks can be entered with the shocks command.","category":"page"},{"location":"model-file/shocks/#Dynare-commands","page":"Shocks on exgogenous variables","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/shocks/#shocks","page":"Shocks on exgogenous variables","title":"shocks","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"block: shocks ; \nblock: shocks(overwrite);","category":"page"},{"location":"model-file/shocks/#Options","page":"Shocks on exgogenous variables","title":"Options","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"overwrite: By default, if there are several shocks blocks","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"in the same .mod file, then they are cumulative: all the shocks declared in all the blocks are considered; however, if a shocks block is declared with the overwrite option, then it replaces all the previous shocks blocks.","category":"page"},{"location":"model-file/shocks/#In-a-deterministic-context","page":"Shocks on exgogenous variables","title":"In a deterministic context","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"For deterministic simulations, the shocks block specifies temporary changes in the value of exogenous variables. For permanent shocks, use an endval block.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"The block should contain one or more occurrences of the following group of three lines:","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME;\nperiods INTEGER[:INTEGER] [[,] INTEGER[:INTEGER]]...;\nvalues DOUBLE | (EXPRESSION) [[,] DOUBLE | (EXPRESSION) ]...;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"It is possible to specify shocks which last several periods and which can vary over time. The periods keyword accepts a list of several dates or date ranges, which must be matched by as many shock values in the values keyword. Note that a range in the periods keyword can be matched by only one value in the values keyword. If values represents a scalar, the same value applies to the whole range. If values represents a vector, it must have as many elements as there are periods in the range.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Note that shock values are not restricted to numerical constants: arbitrary expressions are also allowed, but you have to enclose them inside parentheses.","category":"page"},{"location":"model-file/shocks/#Example-1","page":"Shocks on exgogenous variables","title":"Example 1","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\n\nvar e;\nperiods 1;\nvalues 0.5;\nvar u;\nperiods 4:5;\nvalues 0;\nvar v;\nperiods 4:5 6 7:9;\nvalues 1 1.1 0.9;\nvar w;\nperiods 1 2;\nvalues (1+p) (exp(z));\n\nend;","category":"page"},{"location":"model-file/shocks/#Example-2","page":"Shocks on exgogenous variables","title":"Example 2","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"xx = [1.2; 1.3; 1];\n\nshocks;\nvar e;\nperiods 1:3;\nvalues (xx);\nend;","category":"page"},{"location":"model-file/shocks/#In-a-stochastic-context","page":"Shocks on exgogenous variables","title":"In a stochastic context","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"For stochastic simulations, the shocks block specifies the non zero elements of the covariance matrix of the shocks of exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"You can use the following types of entries in the block:","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the standard error of an exogenous variable.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME; \nstderr EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the variance of an exogenous variable.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification the covariance of two exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"var VARIABLE_NAME, VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Specification of the correlation of two exogenous variables.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"corr VARIABLE_NAME, VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In an estimation context, it is also possible to specify variances and covariances on endogenous variables: in that case, these values are interpreted as the calibration of the measurement errors on these variables. This requires the varobs command to be specified before the shocks block.","category":"page"},{"location":"model-file/shocks/#Example","page":"Shocks on exgogenous variables","title":"Example","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\nvar e = 0.000081;\nvar u; stderr 0.009;\ncorr e, u = 0.8;\nvar v, w = 2;\nend;","category":"page"},{"location":"model-file/shocks/#Remark","page":"Shocks on exgogenous variables","title":"Remark","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"If the variance of an exogenous variable is set to zero, this variable will appear in the report on policy and transition functions, but isn't used in the computation of moments and of Impulse Response Functions. Setting a variance to zero is an easy way of removing an exogenous shock.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"In stochastic optimal policy context","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"When computing conditional welfare in a ramsey_model or discretionary_policy context, welfare is conditional on the state values inherited by planner when making choices in the first period. The information set of the first period includes the respective exogenous shock realizations. Thus, their known value can be specified using the perfect foresight syntax. Note that i) all other values specified for periods than period 1 will be ignored and ii) the value of lagged shocks (e.g. in the case of news shocks) is specified with histval.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Example","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"shocks;\nvar u; stderr 0.008;\nvar u;\nperiods 1;\nvalues 1;\nend;","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Mixing deterministic and stochastic shocks","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"It is possible to mix deterministic and stochastic shocks to build models where agents know from the start of the simulation about future exogenous changes. In that case stoch_simul will compute the rational expectation solution adding future information to the state space (nothing is shown in the output of stoch_simul) and forecast will compute a simulation conditional on initial conditions and future information.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Example","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"varexo_det tau;\nvarexo e;\n...\nshocks;\nvar e; stderr 0.01;\nvar tau;\nperiods 1:9;\nvalues -0.15;\nend;\n\nstoch_simul(irf=0);\n\nforecast;","category":"page"},{"location":"model-file/shocks/#Julia-function","page":"Shocks on exgogenous variables","title":"Julia function","text":"","category":"section"},{"location":"model-file/shocks/#scenario!()","page":"Shocks on exgogenous variables","title":"scenario!()","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"The Julia function scenario!() lets you","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"declare shocks on exogenous variables as the shocks block\nset the future value of endogenous variables (for conditional forecasts)\nadd the date at which the above information is made available to the agents in the model","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!","category":"page"},{"location":"model-file/shocks/#Dynare.scenario!","page":"Shocks on exgogenous variables","title":"Dynare.scenario!","text":"scenario!(; name=Symbol, period::PeriodSinceEpoch, value<:Number, context::Context=context,\n exogenous::Symbol=Symbol(), infoperiod::PeriodSinceEpoch=Undated(1))\n\nKeyword arguments\n\nname::Symbol: the name of an endogenous or exogenous variable [required]\nperiod::PeriodSinceEpoch: the period in which the value is set\nvalue<:PeriodSinceEpoch: the value of the endogenous or exogenous variables\ncontext: the context is which the function operates (optional, default = context)\nexogenous: when an endogenous variable is set, the name of the exogenous that must be freed (required when an endogenous variables is set)\ninfoperiod: the period in which the information is learned (optional, default = Undated(1))\n\n\n\n\n\n","category":"function"},{"location":"model-file/shocks/#Examples","page":"Shocks on exgogenous variables","title":"Examples","text":"","category":"section"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(name = :e, value = 0.1, period = 2)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Exogenous variable e, takes value 0.1 in period 2.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(name = :y, value = 0.2, period=2, exogenous = :u)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model know at the beginning of period 1 that this will happen.","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"scenario!(infoperiod = 2, name = :y, value = 0.2, period = 2,\n exogenous = :u)","category":"page"},{"location":"model-file/shocks/","page":"Shocks on exgogenous variables","title":"Shocks on exgogenous variables","text":"Endogenous variable y is set to 0.2 in period 2 and exogenous variable u is treated as endogenous in the same period. Agents in the model only learn at the beginning of period 2 that this will happen.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"In a stochastic context, Dynare computes one or several simulations corresponding to a random draw of the shocks.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The main algorithm for solving stochastic models relies on a Taylor approximation, up to second order, of the solution function (see Judd (1996), Collard and Juillard (2001a, 2001b), and Schmitt-Grohé and Uríbe (2004)). The details of the Dynare implementation of the first order solution are given in Villemot (2011). Such a solution is computed using the stoch_simul command.","category":"page"},{"location":"model-file/local-approxiation/#Dynare-commands","page":"Local approximation","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/local-approxiation/#stoch_simul","page":"Local approximation","title":"stoch_simul","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Command: `stoch_simul;","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Command: `stoch_simul (OPTIONS...);","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Solves a stochastic (i.e. rational expectations) model, using perturbation techniques.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"More precisely, stoch_simul computes a Taylor approximation of the model around the deterministic steady state and solves of the the decision and transition functions for the approximated model. Using this, it computes impulse response functions and various descriptive statistics (moments, variance decomposition, correlation and autocorrelation coefficients). For correlated shocks, the variance decomposition is computed as in the VAR literature through a Cholesky decomposition of the covariance matrix of the exogenous variables. When the shocks are correlated, the variance decomposition depends upon the order of the variables in the varexo command.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The IRFs are computed as the difference between the trajectory of a variable following a shock at the beginning of period 1 and its steady state value. More details on the computation of IRFs can be found at https://archives.dynare.org/DynareWiki/IrFs.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Variance decomposition, correlation, autocorrelation are only displayed for variables with strictly positive variance. Impulse response functions are only plotted for variables with response larger than 10^-10.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Variance decomposition is computed relative to the sum of the contribution of each shock. Normally, this is of course equal to aggregate variance, but if a model generates very large variances, it may happen that, due to numerical error, the two differ by a significant amount. Dynare issues a warning if the maximum relative difference between the sum of the contribution of each shock and aggregate variance is larger than 0.01%.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The covariance matrix of the shocks is specified with the shocks command (see shocks-exo).","category":"page"},{"location":"model-file/local-approxiation/#Options","page":"Local approximation","title":"Options","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"ar = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Order of autocorrelation coefficients to compute. Default: 5","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"irf = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Number of periods on which to compute the IRFs. Setting irf=0 suppresses the plotting of IRFs. Default: 40.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"nonstationary: declares the model as nonstationary.\nnoprint: don't print the results\norder = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Order of Taylor approximation. Note that for third order and above, the k_order_solver option is implied and only empirical moments are available (you must provide a value for periods option). Default: 2","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"periods = INTEGER","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"If different from zero, empirical moments will be computed instead of theoretical moments. The value of the option specifies the number of periods to use in the simulations. Values of the initval block, possibly recomputed by steady, will be used as starting point for the simulation. The simulated endogenous variables are made available to the user in Julia variable context.results.model_results[1].simulation. Default: 0.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"dr = OPTION","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Determines the method used to compute the decision rule. Possible values for OPTION are:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"default","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Uses the default method to compute the decision rule based on the generalized Schur decomposition (see Villemot (2011) for more information).","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"cycle_reduction","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Uses the cycle reduction algorithm to solve the polynomial equation for retrieving the coefficients associated to the endogenous variables in the decision rule. This method is faster than the default one for large scale models.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Default value is default.","category":"page"},{"location":"model-file/local-approxiation/#Output","page":"Local approximation","title":"Output","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The derivatives of the approximated solution function are availabe in the vector of matrices context.results.model_results[1].solution_derivatives. The first element contains the matrix of first order derivatives. The second element, the matrix of second order derivatives.","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The matrix of first order derivatives is a n x (n_s + n_x + 1) matrix where n is the number of endogenous variables, n_s, the number of state variables (variables appearing in the model with a lag), and n_x, the number of exogenous variables. An element of this matrix is","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"beginalign*\nX_ij = fracpartial g_ipartial y_jj=1ldotsn_s\nX_in_s+j = fracpartial g_ipartial x_jj=1ldotsn_x\nX_in_s+n_k+1 = fracpartial g_ipartial sigma = 0\nendalign*","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where g_i is the solution function for variable i, y, the vector of endogenous variables, x, the vector en exogenous variables and sigma the stochastic scale of the model. Note that at first order, this derivative is alwasy equal to zero. ","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The matrix of second order derivatives is n times n^2 matrix where each column contains derivatives with respect to a pair of endogenous variables","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"eigenvalues::Vector{Complex{Float64}}\ng1::Matrix{Float64} # full approximation\ngs1::Matrix{Float64} # state transition matrices: states x states\nhs1::Matrix{Float64} # states x shocks\ngns1::Matrix{Float64} # non states x states\nhns1::Matrix{Float64} # non states x shocsks\ng1_1::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int}}, UnitRange{Int}}, true}\t # solution first order derivatives w.r. to state variables\ng1_2::SubArray{Float64, 2, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int}}, UnitRange{Int}}, true} # solution first order derivatives w.r. to current exogenous variables\nendogenous_variance::Matrix{Float64}\nstationary_variables::Vector{Bool}","category":"page"},{"location":"model-file/local-approxiation/#Example-1","page":"Local approximation","title":"Example 1","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"shocks;\nvar e;\nstderr 0.0348;\nend;\n\nstoch_simul;","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Performs the simulation of the 1st-order approximation of a model with a single stochastic shock e, with a standard error of 0.0348.","category":"page"},{"location":"model-file/local-approxiation/#Example-2","page":"Local approximation","title":"Example 2","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":" stoch_simul(irf=60);","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"Performs the simulation of a model and displays impulse response functions on 60 periods.","category":"page"},{"location":"model-file/local-approxiation/#Julia-function","page":"Local approximation","title":"Julia function","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"localapproximation!","category":"page"},{"location":"model-file/local-approxiation/#Dynare.localapproximation!","page":"Local approximation","title":"Dynare.localapproximation!","text":"localapproximation!(; context::Context=context, display = true,\n dr_algo::String = \"GS\", irf::Int = 40,\n LRE_options = LinearRationalExpectationsOptions(),\n nar::Int = 5, nonstationary::Bool = false,\n order::Int = 1, periods::Int = 0 )\n\ncomputes a local approximation of a model contained in context\n\nKeyword arguments\n\ncontext::Context=context: context in which the simulation is computed\ndisplay::Bool=true: whether to display the results\ndr_algo::String: solution algorithm, either \"GS\" for generalized Schur decomposition (default) or \"CR\" for cyclic reduction\nirf::Int = 40: number of periods for IRFs. Use 0 for no IRF computation\nLRE_options::LinearRationalExpectationsOptions = LinearRationalExpectationsOptions(): options passed to the LinearRationalExpectation package\nnar::Int = 5: numnber of periods for autocorrelations. Use 0 for no autocorrelation computation\nnonstationary::Bool = false: to specify a nonstationary model\nperiods::Int = 0: number of periods for an optional Monte Carlo simulation of the model\n\n\n\n\n\n","category":"function"},{"location":"model-file/local-approxiation/#First-order-approximation","page":"Local approximation","title":"First-order approximation","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The approximation has the stylized form:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"y_t = y^s + A phi(y_t-1) + B u_t","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where y^s is the steady state value of y and phi(y_t-1)=y_t-1-y^s. Matrices of coefficients A and B are computed by Dynare.","category":"page"},{"location":"model-file/local-approxiation/#Second-order-approximation","page":"Local approximation","title":"Second-order approximation","text":"","category":"section"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"The approximation has the form:","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"y_t = y^s + 05 Delta^2 + A phi(y_t-1) + B u_t + 05 C\n(phi(y_t-1)otimes phi(y_t-1)) + 05 D (u_t otimes u_t) + E\n(phi(y_t-1) otimes u_t)","category":"page"},{"location":"model-file/local-approxiation/","page":"Local approximation","title":"Local approximation","text":"where y^s is the steady state value of y, phi(y_t-1)=y_t-1-y^s, and Delta^2 is the shift effect of the variance of future shocks. Matrices of coefficients A, B, C, D and E are computed by Dynare. ","category":"page"},{"location":"model-file/forecasting/#Julia-functions","page":"Forecasting","title":"Julia functions","text":"","category":"section"},{"location":"model-file/forecasting/","page":"Forecasting","title":"Forecasting","text":"forecasting!","category":"page"},{"location":"model-file/forecasting/#Dynare.forecasting!","page":"Forecasting","title":"Dynare.forecasting!","text":"forecasting!(; periods::Integer,\n forecast_mode::ForecastModes,\n context::Context=context,\n datafile::String=\"\",\n first_obs::PeriodsSinceEpoch=Undated(typemin(Int)),\n first_period::PeriodsSinceEpoch=Undated(0),\n last_obs::PeriodsSinceEpoch=Undated(typemin(Int)),\n order::Integer=1)\n\ncomputes an unconditional forecast of the variables of the model\n\nKeyword arguments\n\nperiods::Integer: number of forecasted periods [required]\nforecast_mode::ForecastModes: one of histval or calibsmoother [required]\ndatafile::String: file with the observations for the smoother\nfirst_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file) \nfirst_period::PeriodsSinceEpoch: initial_period for the forecast (default when histval: Undated(0), default when calibsmoother: last period of the smoother)\nlast_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)\norder::Integer: order of local approximation\n\n\n\n\n\n","category":"function"},{"location":"model-file/forecasting/","page":"Forecasting","title":"Forecasting","text":"recursive_forecasting!","category":"page"},{"location":"model-file/forecasting/#Dynare.recursive_forecasting!","page":"Forecasting","title":"Dynare.recursive_forecasting!","text":"function recursiveforecasting!(; Np::Integer, firstperiod::PeriodsSinceEpoch, lastperiod::PeriodsSinceEpoch, context::Context=context, datafile::String=\"\", firstobs::PeriodsSinceEpoch=Undated(1), last_obs::PeriodsSinceEpoch=Undated(0), order::Integer=1) computes an unconditional recursive forecast for one variable by adding one period to the sample used for the smoother before forecasting over Np periods.\n\nKeyword arguments\n\nNp::Integer: number of forecasted periods [required]\nfirst_period::PeriodsSinceEpoch: initial period of first forecast [required]\nlast_period::PeriodsSinceEpoch: initial period of last forecast [required]\ndatafile::String: file with the observations for the smoother\nfirst_obs::PeriodsSinceEpoch: first period used by smoother (default: first observation in the file) \nlast_obs::PeriodsSinceEpoch: last period used by smoother (default: last observation in the file)\norder::Integer: order of local approximation\n\n\n\n\n\n","category":"function"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"From a statistical point of view, DSGE models are unobserved components models: only a few variables are observed. Filtering or smoothing provide estimate of the unobserved variables given the observations.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"The model is put in state space form","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"beginalign*\ny^o_t = M s_t + Nepsilon_t\ns_t = Ts_t-1 + Reta_t\nendalign*","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where y^o_t represents observed variable at period t. The coefficient matrices of the transition equation, T and R are provided by the solution of the linear(-isze) rational expectation model. epsilon_t are possible measurement errors and eta_t the structural shocks. Most often matrix M is a selection matrix.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Filtering provides estimates conditional only on past observations:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"mathbbE(y^no_tY^o_t-1)","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where y^no_t are unobserved variables at period t and Y^o_t-1 represent the set observations until period t-1 included.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Smoothing provides estimates of unobserved variables conditional on the entire sample of observations:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"mathbbE(y^no_tY^o_T)","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"where Y^o_T represents the all observations in the sample.","category":"page"},{"location":"model-file/filtersmoother/#Dynare-command","page":"State space, filtering and smoothing","title":"Dynare command","text":"","category":"section"},{"location":"model-file/filtersmoother/#varobs","page":"State space, filtering and smoothing","title":"varobs","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Observed variables are declared with the varobs command","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: varobs VARIABLE_NAME...;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command lists the name of observed endogenous variables for the estimation procedure. These variables must be available in the data file (see estimation_cmd ).","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Alternatively, this command is also used in conjunction with the partial_information option of stoch_simul, for declaring the set of observed variables when solving the model under partial information.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Only one instance of varobs is allowed in a model file. If one needs to declare observed variables in a loop, the macro processor can be used as shown in the second example below.","category":"page"},{"location":"model-file/filtersmoother/#Example","page":"State space, filtering and smoothing","title":"Example","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" varobs C y rr;","category":"page"},{"location":"model-file/filtersmoother/#observation_trends","page":"State space, filtering and smoothing","title":"observation_trends","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"It is possible to declare a deterministic linear trend that is removed for the computations and added back in the results","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Block: observation_trends ;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This block specifies linear trends for observed variables as functions of model parameters. In case the loglinear option is used, this corresponds to a linear trend in the logged observables, i.e. an exponential trend in the level of the observables.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Each line inside of the block should be of the form:","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" VARIABLE_NAME(EXPRESSION);","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"In most cases, variables shouldn't be centered when observation_trends is used.","category":"page"},{"location":"model-file/filtersmoother/#Example-2","page":"State space, filtering and smoothing","title":"Example","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":" observation_trends;\n Y (eta);\n P (mu/eta);\n end;","category":"page"},{"location":"model-file/filtersmoother/#calib_smoother","page":"State space, filtering and smoothing","title":"calib_smoother","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command triggers the computation of the filter and smoother for calibrated models","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: calib_smoother [VARIABLE_NAME]...; ","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Command: calib_smoother (OPTIONS...)[VARIABLE_NAME]...;","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"This command computes the smoothed variables (and possible the filtered variables) on a calibrated model.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"A datafile must be provided, and the observable variables declared with varobs. The smoother is based on a first-order approximation of the model.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"By default, the command computes the smoothed variables and shocks and stores the results in oo_.SmoothedVariables and oo_.SmoothedShocks. It also fills oo_.UpdatedVariables.","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"Options","category":"page"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"datafile = FILENAME: file containing the observation in CSV format.\nfiltered_vars: triggers the computation of filtered variables.\nfirst_obs = INTEGER: first observation\ndiffuse_filter = INTEGER: use a diffuse filter for nonstationary models.","category":"page"},{"location":"model-file/filtersmoother/#Julia-functions","page":"State space, filtering and smoothing","title":"Julia functions","text":"","category":"section"},{"location":"model-file/filtersmoother/","page":"State space, filtering and smoothing","title":"State space, filtering and smoothing","text":"calibsmoother!","category":"page"},{"location":"model-file/filtersmoother/#Dynare.calibsmoother!","page":"State space, filtering and smoothing","title":"Dynare.calibsmoother!","text":"calibsmoother!(; context::Context=context,\n datafile::String = \"\",\n data::AxisArrayTable = AxisArrayTable(Matrix{Float64}(undef, 0, 0), Undated[], Symbol[]),\n first_obs::PeriodSinceEpoch = Undated(typemin(Int)),\n last_obs::PeriodSinceEpoch = Undated(typemin(Int)),\n nobs::Int = 0\n )\n\nCompute the smoothed values of the variables for an estimated model\n\n#Keyword arguments\n\nperiods::Integer: number of forecasted periods [required]\ndatafile::String: file with the observations for the smoother\ndata::AxisArrayTable: AxisArrayTable containing observed variables (can't be used at the same time as datafile)\nfirst_obs::PeriodSinceEpoch: first period used by smoother (default: first observation in the dataset) \nlast_obs::PeriodSinceEpoch: last period used by smoother (default: last observation in the dataset)\nnobs::Int: number of observations (default: entire dataset)\n\n\n\n\n\n","category":"function"},{"location":"model-file/syntax-elements/#Model-File","page":"Syntax elements","title":"Model File","text":"","category":"section"},{"location":"model-file/syntax-elements/#Syntax-elements","page":"Syntax elements","title":"Syntax elements","text":"","category":"section"},{"location":"model-file/syntax-elements/#Conventions","page":"Syntax elements","title":"Conventions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"A model file contains a list of commands and of blocks. Each command and each element of a block is terminated by a semicolon (;). Blocks are terminated by end;.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"If Dynare encounters an unknown expression at the beginning of a line or after a semicolon, it will parse the rest of that line as native Julia code, even if there are more statements separated by semicolons present. To prevent cryptic error messages, it is strongly recommended to always only put one statement/command into each line and start a new line after each semicolon.[1]","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Lines of codes can be commented out line by line or as a block. Single-line comments begin with // and stop at the end of the line. Multiline comments are introduced by /* and terminated by */.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Examples","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"// This is a single line comment\n\nvar x; // This is a comment about x\n\n/* This is another inline comment about alpha */ alpha = 0.3;\n\n /*\n This comment is spanning\n two lines.\n */","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that these comment marks should not be used in native Julia code regions where the [#] should be preferred instead to introduce a comment. In a verbatim block, see verbatim, this would result in a crash since // is not a valid Julia statement).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Most Dynare commands have arguments and several accept options, indicated in parentheses after the command keyword. Several options are separated by commas.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"In the description of Dynare commands, the following conventions are observed:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Optional arguments or options are indicated between square brackets: '[]';\nRepeated arguments are indicated by ellipses: \"...\";\nMutually exclusive arguments are separated by vertical bars: '|';\nINTEGER indicates an integer number;\nINTEGER_VECTOR indicates a vector of integer numbers separated by spaces, enclosed by square brackets;\nDOUBLE indicates a double precision number. The following syntaxes are valid: 1.1e3, 1.1E3, 1.1d3, 1.1D3. In some places, infinite Values Inf and -Inf are also allowed;\nNUMERICAL_VECTOR indicates a vector of numbers separated by spaces, enclosed by square brackets;\nEXPRESSION indicates a mathematical expression valid outside the model description (see expr);\nMODEL_EXPRESSION (sometimes MODEL_EXP) indicates a mathematical expression valid in the model description (see expr and model-decl);\nMACRO_EXPRESSION designates an expression of the macro processor (see macro-exp);\nVARIABLE_NAME (sometimes VAR_NAME) indicates a variable name starting with an alphabetical character and can't contain: '()+-*/\\^=!;:@#.' or accentuated characters;\nPARAMETER_NAME (sometimes PARAM_NAME) indicates a parameter name starting with an alphabetical character and can't contain: '()+-*/\\^=!;:@#.' or accentuated characters;\nLATEX_NAME (sometimes TEX_NAME) indicates a valid LaTeX expression in math mode (not including the dollar signs);\nFUNCTION_NAME indicates a valid Julia function name;\nFILENAME indicates a filename valid in the underlying operating system; it is necessary to put it between quotes when specifying the extension or if the filename contains a non-alphanumeric character;\nQUOTED_STRING indicates an arbitrary string enclosed between (single) quotes. Note that Dynare commands call for single quotes around a string while in Julia strings are enclosed between double quotes.","category":"page"},{"location":"model-file/syntax-elements/#Expressions","page":"Syntax elements","title":"Expressions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Dynare distinguishes between two types of mathematical expressions: those that are used to describe the model, and those that are used outside the model block (e.g. for initializing parameters or variables, or as command options). In this manual, those two types of expressions are respectively denoted by MODEL_EXPRESSION and EXPRESSION.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Unlike Julia expressions, Dynare expressions are necessarily scalar ones: they cannot contain matrices or evaluate to matrices.[2]","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Expressions can be constructed using integers (INTEGER), floating point numbers (DOUBLE), parameter names (PARAMETER_NAME), variable names (VARIABLE_NAME), operators and functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following special constants are also accepted in some contexts:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Constant: inf","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Represents infinity.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Constant: nan","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"\"Not a number\": represents an undefined or unrepresentable value.","category":"page"},{"location":"model-file/syntax-elements/#Parameters-and-variables","page":"Syntax elements","title":"Parameters and variables","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Parameters and variables can be introduced in expressions by simply typing their names. The semantics of parameters and variables is quite different whether they are used inside or outside the model block.","category":"page"},{"location":"model-file/syntax-elements/#Inside-the-model","page":"Syntax elements","title":"Inside the model","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Parameters used inside the model refer to the value given through parameter initialization (see param-init) or homotopy_setup when doing a simulation, or are the estimated variables when doing an estimation.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Variables used in a MODEL_EXPRESSION denote current period values when neither a lead or a lag is given. A lead or a lag can be given by enclosing an integer between parenthesis just after the variable name: a positive integer means a lead, a negative one means a lag. Leads or lags of more than one period are allowed. For example, if c is an endogenous variable, then c(+1) is the variable one period ahead, and c(-2) is the variable two periods before.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"When specifying the leads and lags of endogenous variables, it is important to respect the following convention: in Dynare, the timing of a variable reflects when that variable is decided. A control variable –- which by definition is decided in the current period –- must have no lead. A predetermined variable –- which by definition has been decided in a previous period –- must have a lag. A consequence of this is that all stock variables must use the \"stock at the end of the period\" convention.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Leads and lags are primarily used for endogenous variables, but can be used for exogenous variables. They have no effect on parameters and are forbidden for local model variables (see Model declaration).","category":"page"},{"location":"model-file/syntax-elements/#Outside-the-model","page":"Syntax elements","title":"Outside the model","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"When used in an expression outside the model block, a parameter or a variable simply refers to the last value given to that variable. More precisely, for a parameter it refers to the value given in the corresponding parameter initialization (see param-init); for an endogenous or exogenous variable, it refers to the value given in the most recent initval or endval block.","category":"page"},{"location":"model-file/syntax-elements/#Operators","page":"Syntax elements","title":"Operators","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following operators are allowed in both MODEL_EXPRESSION and EXPRESSION:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Binary arithmetic operators: +, -, *, /, ^\nUnary arithmetic operators: +, -\nBinary comparison operators (which evaluate to either 0 or 1): <, >, <=, >=, ==, !=","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note the binary comparison operators are differentiable everywhere except on a line of the 2-dimensional real plane. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivatives of these operators with respect to both arguments is equal to 0 (since this is the value of the partial derivatives everywhere else).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following special operators are accepted in MODEL_EXPRESSION (but not in EXPRESSION):","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Operator: STEADYSTATE (MODELEXPRESSION)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"This operator is used to take the value of the enclosed expression at the steady state. A typical usage is in the Taylor rule, where you may want to use the value of GDP at steady state to compute the output gap.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Exogenous and exogenous deterministic variables may not appear in MODEL_EXPRESSION.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"note: Note\nThe concept of a steady state is ambiguous in a perfect foresight context with permament and potentially anticipated shocks occuring. Dynare will use the contents of oo_.steady_state as its reference for calls to the STEADY_STATE()-operator. In the presence of endval, this implies that the terminal state provided by the user is used. This may be a steady state computed by Dynare (if endval is followed by steady) or simply the terminal state provided by the user (if endval is not followed by steady). Put differently, Dynare will not automatically compute the steady state conditional on the specificed value of the exogenous variables in the respective periods.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Operator: EXPECTATION (INTEGER) (MODEL_EXPRESSION","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"This operator is used to take the expectation of some expression using a different information set than the information available at current period. For example, EXPECTATION(-1)(x(+1)) is equal to the expected value of variable x at next period, using the information set available at the previous period. See aux-variables for an explanation of how this operator is handled internally and how this affects the output.","category":"page"},{"location":"model-file/syntax-elements/#Functions","page":"Syntax elements","title":"Functions","text":"","category":"section"},{"location":"model-file/syntax-elements/#Built-in-functions","page":"Syntax elements","title":"Built-in functions","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The following standard functions are supported internally for both MODEL_EXPRESSION and EXPRESSION:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: exp(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Natural exponential.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: log(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: ln(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Natural logarithm.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: log10(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Base 10 logarithm.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sqrt(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Square root.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cbrt(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Cube root.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sign(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Signum function, defined as:","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"beginaligned\n textrmsign(x) =\n begincases\n -1 quadtextif x0\n 0 quadtextif x=0\n 1 quadtextif x0\n endcases\n endaligned","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that this function is not continuous, hence not differentiable, at x=0. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at x=0 is equal to 0. This assumption comes from the observation that both the right- and left-derivatives at this point exist and are equal to 0, so we can remove the singularity by postulating that the derivative at x=0 is 0.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: abs(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Absolute value.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that this continuous function is not differentiable at x=0. However, for facilitating convergence of Newton-type methods, Dynare assumes that the derivative at x=0 is equal to 0 (even if the derivative does not exist). The rational for this mathematically unfounded definition, rely on the observation that the derivative of mathrmabs(x) is equal to mathrmsign(x) for any xneq 0 in mathbb R and from the convention for the value of mathrmsign(x) at x=0).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sin(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cos(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: tan(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: asin(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: acos(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: atan(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Trigonometric functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: sinh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: cosh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: tanh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: asinh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: acosh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: atanh(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Hyperbolic functions.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: max(a, b)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: min(a, b)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Maximum and minimum of two reals.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that these functions are differentiable everywhere except on a line of the 2-dimensional real plane defined by a=b. However for facilitating convergence of Newton-type methods, Dynare assumes that, at the points of non-differentiability, the partial derivative of these functions with respect to the first (resp. the second) argument is equal to 1 (resp. to 0) (i.e. the derivatives at the kink are equal to the derivatives observed on the half-plane where the function is equal to its first argument).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normcdf(x) ","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normcdf(x, mu, sigma)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gaussian cumulative density function, with mean mu and standard deviation sigma. Note that normcdf(x) is equivalent to normcdf(x,0,1).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: normpdf(x) Function: normpdf(x, mu, sigma)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gaussian probability density function, with mean mu and standard deviation sigma. Note that normpdf(x) is equivalent to normpdf(x,0,1).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: erf(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Gauss error function.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Function: erfc(x)","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Complementary error function, i.e. mathrmerfc(x) = 1-mathrmerf(x).","category":"page"},{"location":"model-file/syntax-elements/#A-few-words-of-warning-in-stochastic-context","page":"Syntax elements","title":"A few words of warning in stochastic context","text":"","category":"section"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The use of the following functions and operators is strongly discouraged in a stochastic context: max, min, abs, sign, <, >, <=, >=, ==, !=.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"The reason is that the local approximation used by stoch_simul or estimation will by nature ignore the non-linearities introduced by these functions if the steady state is away from the kink. And, if the steady state is exactly at the kink, then the approximation will be bogus because the derivative of these functions at the kink is bogus (as explained in the respective documentations of these functions and operators).","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Note that extended_path is not affected by this problem, because it does not rely on a local approximation of the mode.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"Footnotes","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"[1]: A .mod file must have lines that end with a line feed character, which is not commonly visible in text editors. Files created on Windows and Unix-based systems have always conformed to this requirement, as have files created on OS X and macOS. Files created on old, pre-OS X Macs used carriage returns as end of line characters. If you get a Dynare parsing error of the form ERROR: <>: line 1, cols 341-347: syntax error,... and there's more than one line in your .mod file, know that it uses the carriage return as an end of line character. To get more helpful error messages, the carriage returns should be changed to line feeds.","category":"page"},{"location":"model-file/syntax-elements/","page":"Syntax elements","title":"Syntax elements","text":"[2]: Note that arbitrary Julia expressions can be put in a .mod file, but those expressions have to be on separate lines, generally at the end of the file for post-processing purposes. They are not interpreted by Dynare, and are simply passed on unmodified to Julia. Those constructions are not addresses in this section.","category":"page"},{"location":"running-dynare/#Running-Dynare","page":"Running Dynare","title":"Running Dynare","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In order to give instructions to Dynare, the user has to write a model file whose filename extension must be .mod. This file contains the description of the model and the computing tasks required by the user. Its contents are described in The model file","category":"page"},{"location":"running-dynare/#Dynare-invocation","page":"Running Dynare","title":"Dynare invocation","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Once the model file is written, Dynare is invoked using the @dynare Julia macro (with the filename of the .mod given as argument).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In practice, the handling of the model file is done in two steps: in the first one, the model and the processing instructions written by the user in a model file are interpreted and the proper Julia instructions are generated; in the second step, the program actually runs the computations. Both steps are triggered automatically by the @dynare macro:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"context = @dynare \"FILENAME [.mod ]\" [OPTIONS... ]\";","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"This command launches Dynare and executes the instructions included in FILENAME.mod. This user-supplied file contains the model and the processing instructions, as described in The model file. The options, listed below, can be passed on the command line, following the name of the .mod file or in the first line of the .mod file itself (see below).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Dynare begins by launching the preprocessor on the .mod file.","category":"page"},{"location":"running-dynare/#Options","page":"Running Dynare","title":"Options","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"debug\nInstructs the preprocessor to write some debugging information about the scanning and parsing of the .mod file.\nnotmpterms\nInstructs the preprocessor to omit temporary terms in the static and dynamic files; this generally decreases performance, but is used for debugging purposes since it makes the static and dynamic files more readable.\nsavemacro\\[=FILENAME\\]\nInstructs Dynare to save the intermediary file which is obtained after macro processing (see (@ref \"Macro processing language\")); the saved output will go in the file specified, or if no file is specified in FILENAME-macroexp.mod. See the (@ref \"note on quotes\") for info on passing a FILENAME argument containing spaces.\nonlymacro\nInstructs the preprocessor to only perform the macro processing step, and stop just after. Useful for debugging purposes or for using the macro processor independently of the rest of Dynare toolbox.\nlinemacro\nInstructs the macro preprocessor include @#line directives specifying the line on which macro directives were encountered and expanded from. Only useful in conjunction with savemacro .\nonlymodel\nInstructs the preprocessor to print only information about the model in the driver file; no Dynare commands (other than the shocks statement and parameter initializations) are printed and hence no computational tasks performed. The same ancillary files are created as would otherwise be created (dynamic, static files, etc.).\nnolog\nInstructs Dynare to no create a logfile of this run in FILENAME.log. The default is to create the logfile.\noutput=second\\|third\nInstructs the preprocessor to output derivatives of the dynamic model at least up to the given order.\nlanguage=matlab\\|julia","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Instructs the preprocessor to write output for MATLAB or Julia. Default: MATLAB","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"params\\_derivs\\_order=0\\|1\\|2\nWhen (@ref \"identification\"), (@ref \"dynaresensitivity\") (with identification), or (@ref \"estimationcmd\") are present, this option is used to limit the order of the derivatives with respect to the parameters that are calculated by the preprocessor. 0 means no derivatives, 1 means first derivatives, and 2 means second derivatives. Default: 2\ntransform\\_unary\\_ops\nTransform the following operators in the model block into auxiliary variables: exp, log, log10, cos, sin, tan, acos, asin, atan, cosh, sinh, tanh, acosh, asinh, atanh, sqrt, cbrt, abs, sign, erf. Default: no obligatory transformation\njson = parse\\|transform\\|compute\nCauses the preprocessor to output a version of the .mod file in JSON format to <>/model/json/. When the JSON output is created depends on the value passed. These values represent various steps of processing in the preprocessor.\nIf parse is passed, the output will be written after the parsing of the .mod file to a file called FILENAME.json but before file has been checked (e.g. if there are unused exogenous in the model block, the JSON output will be created before the preprocessor exits).","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If check is passed, the output will be written to a file called FILENAME.json after the model has been checked.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If transform is passed, the JSON output of the transformed model (maximum lead of 1, minimum lag of -1, expectation operators substituted, etc.) will be written to a file called FILENAME.json and the original, untransformed model will be written in FILENAME_original.json.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"And if compute is passed, the output is written after the computing pass. In this case, the transformed model is written to FILENAME.json, the original model is written to FILENAME_original.json, and the dynamic and static files are written to FILENAME_dynamic.json and FILENAME_static.json.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"jsonstdout\nInstead of writing output requested by json to files, write to standard out, i.e. to the Julia command window (and the log-file).\nonlyjson\nQuit processing once the output requested by json has been written.\njsonderivsimple\nPrint a simplified version (excluding variable name(s) and lag information) of the static and dynamic files in FILENAME_static.json and FILENAME_dynamic..\nwarn\\_uninit","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Display a warning for each variable or parameter which is not initialized. See (@ref \"Parameter initialization\"), or (@ref \"loadparamsandsteadystate\") for initialization of parameters. See (@ref \"Initial and Terminal conditions\"), or (@ref \"loadparamsandsteadystate\") for initialization of endogenous and exogenous variables.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"nopreprocessoroutput\nPrevent Dynare from printing the output of the steps leading up to the preprocessor as well as the preprocessor output itself.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"-DMACRO\\_VARIABLE\\[=MACRO\\_EXPRESSION\\]\nDefines a macro-variable from the command line (the same effect as using the Macro directive @#define in a model file, see (@ref \"Macro processing language\")). See the (@ref \"note on quotes\") for info on passing a MACRO_EXPRESSION argument containing spaces. Note that an expression passed on the command line can reference variables defined before it. If MACRO_EXPRESSION is omitted, the variable is assigned the true logical value.\nExample\nCall dynare with command line defines\njulia julia> @dynare <> -DA=true '-DB=\"A string with space\"' -DC=[1,2,3] '-DD=[ i in C when i > 1 ]' -DE;\n-I\\<\\\\>\nDefines a path to search for files to be included by the macro processor (using the @#include command). Multiple -I flags can be passed on the command line. The paths will be searched in the order that the -I flags are passed and the first matching file will be used. The flags passed here take priority over those passed to @#includepath. See the (@ref \"note on quotes\") for info on passing a <> argument containing spaces.\nnostrict\nAllows Dynare to issue a warning and continue processing when","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"there are more endogenous variables than equations.\nan undeclared symbol is assigned in initval or endval.\nan undeclared symbol is found in the model block in this case, it is automatically declared exogenous.\nexogenous variables were declared but not used in the model block.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"stochastic\nTells Dynare that the model to be solved is stochastic. If no Dynare commands related to stochastic models (stoch_simul, estimation, ...) are present in the .mod file, Dynare understands by default that the model to be solved is deterministic.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"exclude\\_eqs=\\<\\\\>\nTells Dynare to exclude all equations specified by the argument. As a .mod file must have the same number of endogenous variables as equations, when ***exclude_eqs*** is passed, certain rules are followed for excluding endogenous variables. If the endogenous tag has been set for the excluded equation, the variable it specifies is excluded. Otherwise, if the left hand side of the excluded equation is an expression that contains only one endogenous variable, that variable is excluded. If neither of these conditions hold, processing stops with an error. If an endogenous variable has been excluded by the ***exclude_eqs*** option and it exists in an equation that has not been excluded, it is transformed into an exogenous variable.\nTo specify which equations to exclude, you must pass the argument <>. This argument takes either a list of equation tags specifying the equations to be excluded or a filename that contains those tags.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If <> is a list of equation tags, it can take one of the following forms:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Given a single argument, e.g. exclude_eqs=eq1, the equation with the tag [name='eq1'] will be excluded. Note that if there is a file called eq1 in the current directory, Dynare will instead try to open this and read equations to exclude from it (see info on filename argument to exclude_eqs below). Further note that if the tag value contains a space, you must use the variant specified in 2 below, i.e. exclude_eqs=[eq 1].\nGiven two or more arguments, e.g. exclude_eqs=[eq1, eq 2], the equations with the tags [name='eq1'] and [name='eq 2'] will be excluded.\nIf you\\'d like to exclude equations based on another tag name (as opposed to the default name), you can pass the argument as either e.g. exclude_eqs=[tagname=a tag] if a single equation with tag [tagname='a tag'] is to be excluded or as e.g. exclude_eqs=[tagname=(a tag, 'a tag with a, comma')] if more than one equation with tags [tagname='a tag'] and [tagname='a tag with a, comma'] will be excluded (note the parenthesis, which are required when more than one equation is specified). Note that if the value of a tag contains a comma, it must be included inside single quotes.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If <> is a filename, the file can take one of the following forms:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"One equation per line of the file, where every line represents the value passed to the name tag. e.g., a file such as: julia eq1 eq 2 would exclude equations with tags [name='eq1'] and [name='eq 2'].\nOne equation per line of the file, where every line after the first line represents the value passed to the tag specified by the first line. e.g., a file such as: julia tagname= a tag a tag with a, comma would exclude equations with tags [tagname='a tag'] and [tagname='a tag with a, comma']. Here note that the first line must end in an equal sign.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"include\\_eqs=\\<\\\\>\nTells Dynare to run with only those equations specified by the argument; in other words, Dynare will exclude all equations not specified by the argument. The argument <> is specified in the same way as the argument to exclude_eqs . The functionality of include_eqs is to find which equations to exclude then take actions in accord with (@ref \"exclude_eqs\").\nnocommutativity","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"This option tells the preprocessor not to use the commutativity of addition and multiplication when looking for common subexpressions. As a consequence, when using this option, equations in various outputs (LaTeX, JSON...) will appear as the user entered them (without terms or factors swapped). Note that using this option may have a performance impact on the preprocessing stage, though it is likely to be small.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"These options can be passed to the preprocessor by listing them after the name of the .mod file. They can alternatively be defined in the first line of the .mod file, this avoids typing them on the command line each time a .mod file is to be run. This line must be a Dynare one-line comment (i.e. must begin with //) and the options must be whitespace separated between --+ options: and +--. Note that any text after the +-- will be discarded. As in the command line, if an option admits a value the equal symbol must not be surrounded by spaces. For instance json = compute is not correct, and should be written json=compute. The nopathchange option cannot be specified in this way, it must be passed on the command-line.","category":"page"},{"location":"running-dynare/#Understanding-Preprocessor-Error-Messages","page":"Running Dynare","title":"Understanding Preprocessor Error Messages","text":"","category":"section"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"If the preprocessor runs into an error while processing your .mod file, it will issue an error. Due to the way that a parser works, sometimes these errors can be misleading. Here, we aim to demystify these error messages.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"The preprocessor issues error messages of the form:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"ERROR: <>: line A, col B: <>\nERROR: <>: line A, cols B-C: <>\nERROR: <>: line A, col B - line C, col D: <>","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"The first two errors occur on a single line, with error two spanning multiple columns. Error three spans multiple rows.","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"Often, the line and column numbers are precise, leading you directly to the offending syntax. Infrequently however, because of the way the parser works, this is not the case. The most common example of misleading line and column numbers (and error message for that matter) is the case of a missing semicolon, as seen in the following example:","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"varexo a, b\nparameters c, ...;","category":"page"},{"location":"running-dynare/","page":"Running Dynare","title":"Running Dynare","text":"In this case, the parser doesn't know a semicolon is missing at the end of the varexo command until it begins parsing the second line and bumps into the parameters command. This is because we allow commands to span multiple lines and, hence, the parser cannot know that the second line will not have a semicolon on it until it gets there. Once the parser begins parsing the second line, it realizes that it has encountered a keyword, parameters, which it did not expect. Hence, it throws an error of the form: ERROR: <>: line 2, cols 0-9: syntax error, unexpected PARAMETERS. In this case, you would simply place a semicolon at the end of line one and the parser would continue processing.","category":"page"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"Dynare can generate PDF reports using \\LaTeX","category":"page"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"A report is made of\na title\na subtitle (optional)\npages\nA page is made of sections\nA section can be\na text paragraph\na listing of the model\na table\na graphic","category":"page"},{"location":"model-file/reporting/#Julia-functions","page":"Reporting","title":"Julia functions","text":"","category":"section"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"Report","category":"page"},{"location":"model-file/reporting/#Dynare.Report","page":"Reporting","title":"Dynare.Report","text":"Report(title::String; subtitle::String = \"\")\n\ninitialize empty report\n\nKeyword arguments\n\ntitle::String: Report title [required]\nsubtitle::String: Report subtitle\n\n\n\n\n\n","category":"type"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"add_page!","category":"page"},{"location":"model-file/reporting/#Dynare.add_page!","page":"Reporting","title":"Dynare.add_page!","text":"add_page!(report::Report, page::Page)\n\nadds a page to a report\n\nKeyword arguments\n\nreport::Report: report\npage::Page: page to be added\n\n\n\n\n\n","category":"function"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"add_graph!","category":"page"},{"location":"model-file/reporting/#Dynare.add_graph!","page":"Reporting","title":"Dynare.add_graph!","text":"add_graph!(page::Page, graph::Graph)\n\nadds a graph to a page\n\nKeyword arguments\n\npage::Page: page\ngraph::Graph: graph to be added\n\n\n\n\n\n","category":"function"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"add_model!","category":"page"},{"location":"model-file/reporting/#Dynare.add_model!","page":"Reporting","title":"Dynare.add_model!","text":"add_model!(page::Page; context::Context = context, lastline::Int = 0, format = 1) adds the lines of a *.mod file to pages\n\nKeyword arguments\n\npage::Page: page [required]\ncontext::Context: context corresponding to the *.mod file (default: context)\nlastline::Int: last line to be printed\nformat::Int: how to display parameter values 1: value is written after the parameter name 2: value is written below the parameter name\n\n\n\n\n\n","category":"function"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"add_paragraph!\n","category":"page"},{"location":"model-file/reporting/#Dynare.add_paragraph!","page":"Reporting","title":"Dynare.add_paragraph!","text":"add_paragraph!(page::Page, paragraph::String)\n\nadds a graph to a page\n\nKeyword arguments\n\npage::Page: page\nparagraph::String: paragraph to be added\n\n\n\n\n\n","category":"function"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"@docs add_table! ````","category":"page"},{"location":"model-file/reporting/","page":"Reporting","title":"Reporting","text":"`docs print","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"There are three ways of computing the steady state (i.e. the static equilibrium) of a model. The first way is to provide the equations of the steady state in a steady_state_model block. When it is possible to derive the steady state by hand, this is the recommended way as it faster and more accurate.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The second way is to provide only a partial solution in the steady_state_model block and to compute the solution for the other variables numerically. Guess values for these other variables must be declared in a initval block. The less variables the better.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The third way is to compute the steady state value of all variables numerically. There is no steady_state_model block and a guess value must be declared for all variables. A guess value of 0 can be omitted, but be careful with variables appearing at the denominator of a fraction. ","category":"page"},{"location":"model-file/steady-state/#Providing-the-steady-state-to-Dynare","page":"Steady state","title":"Providing the steady state to Dynare","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"If you know how to compute the steady state for your model, you can provide a steady_state_model block, which is described below in more details. The steady state file generated by Dynare will be called +FILENAME/output/julia/FILENAME_steadystate2.jl.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Note that this block allows for updating the parameters in each call of the function. This allows for example to calibrate a model to a labor supply of 0.2 in steady state by setting the labor disutility parameter to a corresponding value. They can also be used in estimation where some parameter may be a function of an estimated parameter and needs to be updated for every parameter draw. For example, one might want to set the capital utilization cost parameter as a function of the discount rate to ensure that capacity utilization is 1 in steady state. Treating both parameters as independent or not updating one as a function of the other would lead to wrong results. But this also means that care is required. Do not accidentally overwrite your parameters with new values as it will lead to wrong results.","category":"page"},{"location":"model-file/steady-state/#Steady_state_model","page":"Steady state","title":"Steady_state_model","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: steady\\_state\\_model ;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"When the analytical solution of the model is known, this command can be used to help Dynare find the steady state in a more efficient and reliable way, especially during estimation where the steady state has to be recomputed for every point in the parameter space.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Each line of this block consists of a variable (either an endogenous, a temporary variable or a parameter) which is assigned an expression (which can contain parameters, exogenous at the steady state, or any endogenous or temporary variable already declared above). Each line therefore looks like:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Note that it is also possible to assign several variables at the same time, if the main function in the right hand side is a MATLAB/Octave function returning several arguments:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"[ VARIABLE_NAME, VARIABLE_NAME... ] = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The steady_state_model block also works with deterministic models. An initval block and, when necessary, an endval block, is used to set the value of the exogenous variables. Each initval or endval block must be followed by steady to execute the function created by steady_state_model and set the initial, respectively terminal, steady state.","category":"page"},{"location":"model-file/steady-state/#Example","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var m P c e W R k d n l gy_obs gp_obs y dA;\nvarexo e_a e_m;\n\nparameters alp bet gam mst rho psi del;\n\n...\n// parameter calibration, (dynamic) model declaration, shock calibration...\n...\n\nsteady_state_model;\ndA = exp(gam);\ngst = 1/dA; // A temporary variable\nm = mst;\n\n// Three other temporary variables\nkhst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));\nxist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/mst )^(-1);\nnust = psi*mst^2/( (1-alp)*(1-psi)*bet*gst^alp*khst^alp );\n\nn = xist/(nust+xist);\nP = xist + nust;\nk = khst*n;\n\nl = psi*mst*n/( (1-psi)*(1-n) );\nc = mst/P;\nd = l - mst + 1;\ny = k^alp*n^(1-alp)*gst^alp;\nR = mst/bet;\n\n// You can use MATLAB functions which return several arguments\n[W, e] = my_function(l, n);\n\ngp_obs = m/dA;\ngy_obs = dA;\nend;\n\nsteady;","category":"page"},{"location":"model-file/steady-state/#Finding-the-steady-state-with-Dynare-nonlinear-solver","page":"Steady state","title":"Finding the steady state with Dynare nonlinear solver","text":"","category":"section"},{"location":"model-file/steady-state/#Dynare-commands","page":"Steady state","title":"Dynare commands","text":"","category":"section"},{"location":"model-file/steady-state/#initval","page":"Steady state","title":"initval","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: initval ; ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The initval block provides guess values for steady state computations. ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The initval block is terminated by end; and contains lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/#endval","page":"Steady state","title":"endval","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: endval ; ","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The endval block can be used in a deterministic model to provide the guess values for computing a terminal steady state that is different from the initial steady state","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This block is terminated by end; and contains lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME = EXPRESSION;","category":"page"},{"location":"model-file/steady-state/#steady","page":"Steady state","title":"steady","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Command: steady ; \nCommand: steady (OPTIONS...);","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This command computes the steady state of a model using a nonlinear Newton-type solver and displays it.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"More precisely, it computes the equilibrium value of the endogenous variables for the value of the exogenous variables specified in the previous initval or endval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"steady uses an iterative procedure and takes as initial guess the value of the endogenous variables set in the previous initval or endval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"For complicated models, finding good numerical initial values for the endogenous variables is the trickiest part of finding the equilibrium of that model. Often, it is better to start with a smaller model and add new variables one by one.","category":"page"},{"location":"model-file/steady-state/#Options","page":"Steady state","title":"Options","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"maxit = INTEGER","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Determines the maximum number of iterations used in the non-linear solver. The default value of maxit is 50.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"tolf = DOUBLE","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Convergence criterion for termination based on the function value. Iteration will cease when the residuals are smaller than tolf. Default: eps^(1/3)","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"tolx = DOUBLE","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Convergence criterion for termination based on the step tolerance along. Iteration will cease when the attempted step size is smaller than tolx. Default: eps^(2/3)","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"homotopy_steps = INTEGER","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Defines the number of steps when performing a homotopy. See homotopy_mode option for more details.","category":"page"},{"location":"model-file/steady-state/#Output","page":"Steady state","title":"Output","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"After computation, the steady state is available in the following variables:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Julia variable: context.results.model_results[1].trends.endogenous_steady_state","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Contains the computed steady state. Endogenous variables are ordered in the order of declaration used in the var command,","category":"page"},{"location":"model-file/steady-state/#Example-2","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\nc^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;\n\ninitval;\nc = 1.2;\nk = 12;\nx = 1;\nend;\n\nsteady;\n\nendval;\nc = 2;\nk = 20;\nx = 2;\nend;\n\nsteady;\n","category":"page"},{"location":"model-file/steady-state/#Homotopy-setup","page":"Steady state","title":"Homotopy setup","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Block: homotopy_setup ;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This block is used to declare initial and final values for the parameters and exogenous variables when using a homotopy method. It is used in conjunction with the option homotopy_mode of the steady command.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The idea of homotopy is to subdivide the problem of finding the steady state into smaller problems. It assumes that you know how to compute the steady state for a given set of parameters, and it helps you finding the steady state for another set of parameters, by incrementally moving from one to another set of parameters.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"The purpose of the homotopy_setup block is to declare the final (and possibly also the initial) values for the parameters or exogenous that will be changed during the homotopy. It should contain lines of the form:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME, EXPRESSION, EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This syntax specifies the initial and final values of a given parameter/exogenous.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"There is an alternative syntax:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"VARIABLE_NAME, EXPRESSION;","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"Here only the final value is specified for a given parameter/exogenous; the initial value is taken from the preceeding initval block.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"A necessary condition for a successful homotopy is that Dynare must be able to solve the steady state for the initial parameters/exogenous without additional help (using the guess values given in the initval block).","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"If the homotopy fails, a possible solution is to increase the number of steps (given in homotopy_steps option of steady).","category":"page"},{"location":"model-file/steady-state/#Example-3","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"In the following example, Dynare will first compute the steady state for the initial values (gam=0.5 and x=1), and then subdivide the problem into 50 smaller problems to find the steady state for the final values (gam=2 and x=2):","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n\nparameters alph gam delt bet aa;\nalph=0.5;\ndelt=0.02;\naa=0.5;\nbet=0.05;\n\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\nc^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\nend;\n\ninitval;\nx = 1;\nk = ((delt+bet)/(aa*x*alph))^(1/(alph-1));\nc = aa*x*k^alph-delt*k;\nend;\n\nhomotopy_setup;\ngam, 0.5, 2;\nx, 2;\nend;\n\nsteady(homotopy_mode = 1, homotopy_steps = 50);","category":"page"},{"location":"model-file/steady-state/#Julia-function","page":"Steady state","title":"Julia function","text":"","category":"section"},{"location":"model-file/steady-state/#steadystate!","page":"Steady state","title":"steadystate!","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"steadystate!","category":"page"},{"location":"model-file/steady-state/#Dynare.steadystate!","page":"Steady state","title":"Dynare.steadystate!","text":"steadystate!(; context::Context=context, display::Bool = true,\n maxit::Int = 50, nocheck::Bool = false, tolf::Float64 = cbrt(eps()),\n tolx::Float64 = 0.0)\n\nKeyword arguments\n\ncontext::Context=context: context in which the simulation is computed\nhomotopy_steps::Int=0: number of homotopy steps\ndisplay::Bool=true: whether to display the results\nmaxit::Int=50 maximum number of iterations\nnocheck::Bool=false: don't check the steady state\ntolf::Float64=cbrt(eps()): tolerance for the norm of residualts\ntolx::Float64=0: tolerance for the norm of the change in the result\n\n\n\n\n\n","category":"function"},{"location":"model-file/steady-state/#Replace-some-equations-during-steady-state-computations","page":"Steady state","title":"Replace some equations during steady state computations","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"When there is no steady state file, Dynare computes the steady state by solving the static model, i.e. the model from the .mod file from which leads and lags have been removed.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"In some specific cases, one may want to have more control over the way this static model is created. Dynare therefore offers the possibility to explicitly give the form of equations that should be in the static model.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"More precisely, if an equation is prepended by a [static] tag, then it will appear in the static model used for steady state computation, but that equation will not be used for other computations. For every equation tagged in this way, you must tag another equation with [dynamic]: that equation will not be used for steady state computation, but will be used for other computations.","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This functionality can be useful on models with a unit root, where there is an infinity of steady states. An equation (tagged [dynamic]) would give the law of motion of the nonstationary variable (like a random walk). To pin down one specific steady state, an equation tagged [static] would affect a constant value to the nonstationary variable. Another situation where the [static] tag can be useful is when one has only a partial closed form solution for the steady state.","category":"page"},{"location":"model-file/steady-state/#Example-4","page":"Steady state","title":"Example","text":"","category":"section"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"This is a trivial example with two endogenous variables. The second equation takes a different form in the static model:","category":"page"},{"location":"model-file/steady-state/","page":"Steady state","title":"Steady state","text":"var c k;\nvarexo x;\n...\nmodel;\nc + k - aa*x*k(-1)^alph - (1-delt)*k(-1);\n[dynamic] c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);\n[static] k = ((delt+bet)/(x*aa*alph))^(1/(alph-1));\nend;","category":"page"},{"location":"#The-Dynare-Julia-Reference-Manual","page":"Home","title":"The Dynare Julia Reference Manual","text":"","category":"section"},{"location":"#Introduction","page":"Home","title":"Introduction","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"DynareJulia is a rewriting of Dynare (https://www.dynare.org) that was initially written in Gauss in 1994 and rewritten in Matlab around 2000.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Dynare provides several algorithms to work with Dynamic Stochastic General Equilibrium (DSGE) models often used in macroeconomics. Among other features, it helps","category":"page"},{"location":"","page":"Home","title":"Home","text":"solving such models,\nsimulating them,\nestimating the parameters,\nmaking forecasts.","category":"page"},{"location":"","page":"Home","title":"Home","text":"The user of the package writes a text file, usually with an .mod extension, that contains the equations of the model and the computation tasks. Then, DynareJulia compiles the model and runs the computations.","category":"page"},{"location":"","page":"Home","title":"Home","text":"DynareJulia honors a subset of commands valid in DynareMatlab. Tell us if one of your favorite command or option is missing.","category":"page"},{"location":"","page":"Home","title":"Home","text":"For many computing tasks, DynareJulia provides also Julia functions that can be used in the *.mod file or issued interactively after having run the *.mod file. These Julia functions use keyword arguments for the options and you need only to enter them if you want to change the default value. The keyword arguments without a default value are required arguments. In the sections of this documentation, the Dynare Commands are presented first, then the Julia functions.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Dynare has benefited from many contributions over the years. Here is a list of the contributors:","category":"page"},{"location":"#The-Dynare-Team","page":"Home","title":"The Dynare Team","text":"","category":"section"},{"location":"","page":"Home","title":"Home","text":"Currently the development team of Dynare is composed of:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Stéphane Adjemian (Le Mans Université, Gains)\nMichel Juillard (Banque de France)\nSumudu Kankanamge (Toulouse School of Economics and CEPREMAP)\nFrédéric Karamé (Le Mans Université, Gains and CEPREMAP)\nJunior Maih (Norges Bank)\nWilli Mutschler (University of Tübingen)\nJohannes Pfeifer (Universität der Bundeswehr München)\nMarco Ratto (European Commission, Joint Research Centre - JRC)\nNormann Rion (CY Cergy Paris Université and CEPREMAP)\nSébastien Villemot (CEPREMAP)","category":"page"},{"location":"","page":"Home","title":"Home","text":"The following people contribute or have contributed to DynareJulia","category":"page"},{"location":"","page":"Home","title":"Home","text":"Satyanarayana Bade\nPetre Caraiani\nLilith Hafner\nMichel Juillard\nFélix Ordoñez\nLouis Ponet\nRohit Singh Rathaur\nDawie van Lill","category":"page"},{"location":"","page":"Home","title":"Home","text":"The following people used to be members of the Dynare team:","category":"page"},{"location":"","page":"Home","title":"Home","text":"Houtan Bastani\nAbdeljabar Benzougar\nAlejandro Buesa\nFabrice Collard\nAssia Ezzeroug\nDóra Kocsis\nStéphane Lhuissier\nFerhat Mihoubi\nGeorge Perendia","category":"page"},{"location":"","page":"Home","title":"Home","text":"Copyright © 1996-2023, Dynare Team.","category":"page"},{"location":"","page":"Home","title":"Home","text":"Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.","category":"page"},{"location":"","page":"Home","title":"Home","text":"A copy of the license can be found at https://www.gnu.org/licenses/fdl.txt.","category":"page"}] }