Removed tabs and fixed indentation up to section 4.2.

time-shift
Stéphane Adjemia (Scylla) 2018-12-02 17:39:07 +01:00
parent b6c97b179b
commit 788f7633ba
Signed by untrusted user who does not match committer: stepan
GPG Key ID: A6D44CB9C64CE77B
1 changed files with 1498 additions and 1357 deletions

View File

@ -1,5 +1,9 @@
.. default-domain:: dynare
.. |br| raw:: html
<br>
.. _model-file:
##############
@ -11,28 +15,48 @@ The model file
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;``.
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;``.
Most Dynare commands have arguments and several accept options, indicated in parentheses after the command keyword. Several options are separated by commas.
Most Dynare commands have arguments and several accept options,
indicated in parentheses after the command keyword. Several options
are separated by commas.
In the description of Dynare commands, the following conventions are observed:
In the description of Dynare commands, the following conventions are
observed:
* Optional arguments or options are indicated between square brackets: [];
* Optional arguments or options are indicated between square brackets:
[];
* Repeated arguments are indicated by ellipses: “...”;
* Mutually exclusive arguments are separated by vertical bars: |;
* INTEGER indicates an integer number;
* INTEGER_VECTOR indicates a vector of integer numbers separated by spaces, enclosed by square brackets;
* DOUBLE indicates a double precision number. The following syntaxes are valid: ``1.1e3, 1.1E3, 1.1d3, 1.1D3``. In some places, infinite
* INTEGER_VECTOR indicates a vector of integer numbers separated by
spaces, enclosed by square brackets;
* DOUBLE 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;
* NUMERICAL_VECTOR indicates a vector of numbers separated by spaces, enclosed by square brackets;
* EXPRESSION indicates a mathematical expression valid outside the model description (see :ref:`expr`);
* MODEL_EXPRESSION (sometimes MODEL_EXP) indicates a mathematical expression valid in the model description (see :ref:`expr` and :ref:`model-decl`);
* MACRO_EXPRESSION designates an expression of the macro-processor (see :ref:`macro-exp`);
* VARIABLE_NAME (sometimes VAR_NAME) indicates a variable name starting with an alphabetical character and cant contain: ()+-\*/^=!;:@#. or accentuated characters;
* PARAMETER_NAME (sometimes PARAM_NAME) indicates a parameter name starting with an alphabetical character and cant contain: ()+-\*/^=!;:@#. or accentuated characters;
* LATEX_NAME (sometimes TEX_NAME) indicates a valid LaTeX expression in math mode (not including the dollar signs);
* NUMERICAL_VECTOR indicates a vector of numbers separated by spaces,
enclosed by square brackets;
* EXPRESSION indicates a mathematical expression valid outside the
model description (see :ref:`expr`);
* MODEL_EXPRESSION (sometimes MODEL_EXP) indicates a mathematical
expression valid in the model description (see :ref:`expr` and
:ref:`model-decl`);
* MACRO_EXPRESSION designates an expression of the macro-processor
(see :ref:`macro-exp`);
* VARIABLE_NAME (sometimes VAR_NAME) indicates a variable name
starting with an alphabetical character and cant contain:
()+-\*/^=!;:@#. or accentuated characters;
* PARAMETER_NAME (sometimes PARAM_NAME) indicates a parameter name
starting with an alphabetical character and cant contain:
()+-\*/^=!;:@#. or accentuated characters;
* LATEX_NAME (sometimes TEX_NAME) indicates a valid LaTeX expression
in math mode (not including the dollar signs);
* FUNCTION_NAME indicates a valid MATLAB function name;
* FILENAME 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;
* FILENAME 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;
.. _var-decl:
@ -40,44 +64,81 @@ In the description of Dynare commands, the following conventions are observed:
Variable declarations
=====================
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. Second, to minimize interference with MATLAB or Octave functions that may be called by Dynare or user-defined steady state files, it is recommended to avoid using the name of MATLAB functions. In particular when working with steady state files, do not use correctly-spelled greek names like `alpha`, because there are Matlab functions of the same name. Rather go for ``alppha`` or ``alph``. Lastly, please do not name a variable or parameter ``i``. This may interfere with the imaginary number i and the index in many loops. Rather, name investment ``invest``. Using ``inv`` is also not recommended as it already denotes the inverse operator.
Declarations of variables and parameters are made with the following commands:
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. Second, to minimize interference with MATLAB or Octave
functions that may be called by Dynare or user-defined steady state
files, it is recommended to avoid using the name of MATLAB
functions. In particular when working with steady state files, do not
use correctly-spelled greek names like `alpha`, because there are
Matlab functions of the same name. Rather go for ``alppha`` or
``alph``. Lastly, please do not name a variable or parameter
``i``. This may interfere with the imaginary number i and the index in
many loops. Rather, name investment ``invest``. Using ``inv`` is also
not recommended as it already denotes the inverse operator. Commands
for declaring variables and parameters are described below.
.. command:: var VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STR|NAME=QUOTED_STR)]...;
var(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. See :ref:`conv` for the syntax of *VAR_NAME* and *MODEL_EXPR*. Optionally it is possible to give a LaTeX name to the variable or, if it is nonstationary, provide information regarding its deflator.
``var`` commands can appear several times in the file and Dynare will concatenate them.
|br| This required command declares the endogenous variables in the
model. See :ref:`conv` for the syntax of *VAR_NAME* and
*MODEL_EXPR*. Optionally it is possible to give a LaTeX name to the
variable or, if it is nonstationary, provide information regarding
its deflator. ``var`` commands can appear several times in the file
and Dynare will concatenate them. Dynare stores the list of
declared parameters, in the order of declaration, in a column cell
array ``M_.endo_names``.
*Options*
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.
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.
.. option:: 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``.
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``.
.. option:: 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).
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).
.. _long-name:
.. option:: long_name = QUOTED_STR
This is the long version of the variable name. Its value is stored in ``M_.endo_names_long``. In case multiple ``long_name`` options are provided, the last one will be used. Default: ``VAR_NAME``.
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``.
.. _partitioning:
.. option:: NAME = QUOTED_STR
This is used to create a partitioning of variables. It results in the direct output in the ``.m`` file analogous to: ``M_.endo_partitions.NAME = QUOTED_STR``;.
This is used to create a partitioning of variables. It results
in the direct output in the ``.m`` file analogous to:
``M_.endo_partitions.NAME = QUOTED_STR``;.
:ex:
*Example (variable partitioning)*
::
@ -86,13 +147,15 @@ Declarations of variables and parameters are made with the following commands:
var(deflator=A) i b;
var c $C$ (long_name=`Consumption');
.. command :: varexo VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STR|NAME=QUOTED_STR)...];
This optional command declares the exogenous variables in the model. See :ref:`conv` for the syntax of ``VAR_NAME``. 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.
``varexo`` commands can appear several times in the file and Dynare will concatenate them.
|br| This optional command declares the exogenous variables in the
model. See :ref:`conv` for the syntax of ``VAR_NAME``. 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. ``varexo`` commands can appear several times
in the file and Dynare will concatenate them.
*Options*
@ -102,34 +165,63 @@ Declarations of variables and parameters are made with the following commands:
.. option:: NAME = QUOTED_STRING
Like :ref:`partitioning <partitioning>` but QUOTED_STRING stored in ``M_.exo_partitions.NAME``.
Like :ref:`partitioning <partitioning>` but QUOTED_STRING
stored in ``M_.exo_partitions.NAME``.
:ex:
*Example*
::
varexo m gov;
*Remarks*
An exogenous variable is an innovation, in the sense
that this variable cannot be predicted from the knowledge of the
current state of the economy. For instance, if logged TFP is a first
order autoregressive process:
.. math::
a_t = \rho a_{t-1} + \varepsilon_t
then logged TFP :math:`a_t` is an endogenous variable to be
declared with ``var``, its best prediction is :math:`\rho
a_{t-1}`, while the innovation :math:`\varepsilon_t` is to be
declared with ``varexo``.
.. command:: varexo_det VAR_NAME [$TEX_NAME$] [(long_name=QUOTED_STR|NAME=QUOTED_STR)...];
This optional command declares exogenous deterministic variables in a stochastic model. See :ref:`conv` for the syntax of VARIABLE_NAME. Optionally it is possible to give a LaTeX name to the variable.
|br| This optional command declares exogenous deterministic
variables in a stochastic model. See :ref:`conv` for the syntax of
VARIABLE_NAME. Optionally it is possible to give a :math:`\LaTeX`
name to the variable. ``varexo_det`` commands can appear several
times in the file and Dynare will concatenate them.
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.
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.
``varexo_det`` commands can appear several times in the file and Dynare will concatenate them.
*Options*
.. option:: long_name = QUOTED_STRING
Like :ref:`long_name <long-name>` but value stored in ``M_.exo_det_names_long``.
Like :ref:`long_name <long-name>` but value stored in
``M_.exo_det_names_long``.
.. option:: NAME = QUOTED_STRING
Like :ref:`partitioning <partitioning>` but QUOTED_STRING stored in ``M_.exo_det_partitions.NAME``.
Like :ref:`partitioning <partitioning>` but QUOTED_STRING stored
in ``M_.exo_det_partitions.NAME``.
:ex:
*Example*
::
@ -139,7 +231,10 @@ Declarations of variables and parameters are made with the following commands:
.. command :: parameters PARAM_NAME [$TEX_NAME$] [(long_name=QUOTED_STR|NAME=QUOTED_STR)...];
This command declares parameters used in the model, in variable initialization or in shocks declarations. See ref:`conv` for the syntax of ``PARAM_NAME``. Optionally it is possible to give a LaTeX name to the parameter.
|br| This command declares parameters used in the model, in variable
initialization or in shocks declarations. See :ref:`conv` for the
syntax of ``PARAM_NAME``. Optionally it is possible to give a
:math:`LaTeX` name to the parameter.
The parameters must subsequently be assigned values (see :ref:`param-init`).
@ -155,7 +250,7 @@ Declarations of variables and parameters are made with the following commands:
Like :ref:`partitioning <partitioning>` but QUOTED_STRING stored in ``M_.param_partitions.NAME``.
:ex:
*Example*
::
@ -164,11 +259,17 @@ Declarations of variables and parameters are made with the following commands:
.. command :: change_type (var|varexo|varexo_det|parameters) VAR_NAME | PARAM_NAME...;
Changes the types of the specified variables/parameters to another type: endogenous, exogenous, exogenous deterministic or parameter.
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.
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.
:ex:
*Example*
::
@ -178,22 +279,48 @@ Declarations of variables and parameters are made with the following commands:
change_type(var) alpha, beta;
change_type(parameters) y, w;
Here, in the whole model file, ``alpha`` and ``beta`` will be endogenous and ``y`` and ``w`` will be parameters.
Here, in the whole model file, ``alpha`` and ``beta`` will be
endogenous and ``y`` and ``w`` will be parameters.
.. command:: predetermined_variables VAR_NAME...;
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::
|br| 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::
k = i + (1-delta)*k(-1)
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.
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.
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.
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.
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 tomorrows 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.
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
tomorrows 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.
:ex:
*Example*
The following two program snippets are strictly equivalent.
@ -221,26 +348,40 @@ Declarations of variables and parameters are made with the following commands:
.. command:: trend_var (growth_factor = MODEL_EXPR) VAR_NAME [$LATEX_NAME$]...;
This optional command declares the trend variables in the model. See ref:`conv` for the syntax of MODEL_EXPR and VAR_NAME. Optionally it is possible to give a LaTeX name to the variable.
|br| This optional command declares the trend variables in the
model. See ref:`conv` for the syntax of MODEL_EXPR and
VAR_NAME. Optionally it is possible to give a LaTeX name to the
variable.
The variable is assumed to have a multiplicative growth trend. For an additive growth trend, use ``log_trend_var`` instead.
The variable is assumed to have a multiplicative growth trend. For
an additive growth trend, use ``log_trend_var`` instead.
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.
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.
``trend_var`` commands can appear several times in the file and Dynare will concatenate them.
``trend_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 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.
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.
:ex:
::
*Example*
trend_var (growth_factor=gA) A;
.. command :: log_trend_var (log_growth_factor = MODEL_EXPR) VAR_NAME [$LATEX_NAME$]...;
Same as ``trend_var``, except that the variable is supposed to have an additive trend (or, to put it otherwise, to be equal to the log of a variable with a multiplicative trend).
|br| Same as ``trend_var``, except that the variable is supposed to
have an additive trend (or, to put it otherwise, to be equal to
the log of a variable with a multiplicative trend).
.. _expr: