The Dynare preprocessor modifies the model given by the user, under certain circumstances, by adding auxiliary variables to it. The aim is to bring the model into a canonical form and to simplify computations,
The Dynare preprocessor modifies the model given by the user, under certain circumstances, by adding auxiliary variables to it. The aim is to bring the model into a canonical form and to simplify computations,
Auxiliary variables are created in the following cases:
Auxiliary variables are created in the following cases:
- for endogenous variables with a lag or a lead of two or more (only in stochastic contexts in Dynare 4.1, in all cases in Dynare ≥ 4.2)
- for endogenous variables with a lag or a lead of two or more (only in stochastic contexts in Dynare 4.1, in all cases in Dynare ≥ 4.2)
- for exogenous variables with a lag or a lead (only in stochastic contexts in Dynare ≤ 4.6, in all cases in Dynare ≥ 5)
- for exogenous variables with a lag or a lead (only in stochastic contexts in Dynare ≤ 4.6, in all cases in Dynare ≥ 5)
- when the `EXPECTATION()` operator is used
- when the `EXPECTATION()` operator is used
- when the `ramsey_model` statement is used
- when the `ramsey_model` statement is used
- if the `diff`-operator is used.
- if the `diff`-operator is used.
- when a `var(log)` declaration is used (Dynare ≥6)
- when a `var(log)` declaration is used (Dynare ≥6)
- when a `pac_expectation` operator is used (Dynare ≥5)
- when a `pac_expectation` operator is used (Dynare ≥5)
Auxiliary variables are always endogenous variables. Internally, the indices of the original endogenous (as declared by the user) are in the range `1:M_.orig_endo_nbr`. Auxiliary variables have indices in the range `M_.orig_endo_nbr+1:M_.endo_nbr`.
Auxiliary variables are always endogenous variables. Internally, the indices of the original endogenous (as declared by the user) are in the range `1:M_.orig_endo_nbr`. Auxiliary variables have indices in the range `M_.orig_endo_nbr+1:M_.endo_nbr`.
In most cases, auxiliary equations are appended along with auxiliary variables, so that the number of equations and endogenous variables stays constant.
In most cases, auxiliary equations are appended along with auxiliary variables, so that the number of equations and endogenous variables stays constant.
In order to get information about auxiliary variables and equations added by the preprocessor, the `write_latex_dynamic_model` and `write_latex_static_model` commands can be useful tools.
In order to get information about auxiliary variables and equations added by the preprocessor, the `write_latex_dynamic_model` and `write_latex_static_model` commands can be useful tools.
# The `M_.aux_vars`-structure
# The `M_.aux_vars`-structure
The matrix structure `M_.aux_vars` also contains information about auxiliary variables. For each auxiliary variable, the following fields are declared:
The matrix structure `M_.aux_vars` also contains information about auxiliary variables. For each auxiliary variable, the following fields are declared:
-`M_.aux_vars(i).endo_index`: the index of the auxiliary variable, in the range `M_.orig_endo_nbr+1:M_.endo_nbr`
-`M_.aux_vars(i).endo_index`: the index of the auxiliary variable, in the range `M_.orig_endo_nbr+1:M_.endo_nbr`
-`M_.aux_vars(i).type`: an integer representing the type of the auxiliary variable (see below for the list of types).
-`M_.aux_vars(i).type`: an integer representing the type of the auxiliary variable (see below for the list of types).
The structure can also contain other information, depending on the type of the aux var:
The structure can also contain other information, depending on the type of the aux var:
-`M_.aux_vars(i).orig_index` contains the index of the endogenous or exogenous variable for whose leads/lags the auxiliary variables is a substitute
-`M_.aux_vars(i).orig_index` contains the index of the endogenous or exogenous variable for whose leads/lags the auxiliary variables is a substitute
-`M_.aux_vars(i).orig_lead_lag` contains the lag or lead number of the original variable (as a negative value for lags and a positive one for leads; it will be empty for no lag).
-`M_.aux_vars(i).orig_lead_lag` contains the lag or lead number of the original variable (as a negative value for lags and a positive one for leads; it will be empty for no lag).
-`M_.aux_vars(i).eq_nbr` contains the associated equation in case of Lagrange multipliers
-`M_.aux_vars(i).eq_nbr` contains the associated equation in case of Lagrange multipliers
-`M_.aux_vars(i).orig_expr` contains the original expression to which the auxiliary variable is attached, for example in case of a lead of two on a Lagrange multiplier, there will be an auxiliary variable of type `0` for the lead on an auxiliary variable of type `6` (the multiplier). In this case, `orig_expr` may contain `MULT_1(1)` to indicate that the auxiliary variable for the lead refers to that leaded multiplier.
-`M_.aux_vars(i).orig_expr` contains the original expression to which the auxiliary variable is attached, for example in case of a lead of two on a Lagrange multiplier, there will be an auxiliary variable of type `0` for the lead on an auxiliary variable of type `6` (the multiplier). In this case, `orig_expr` may contain `MULT_1(1)` to indicate that the auxiliary variable for the lead refers to that leaded multiplier.
# Types of auxiliary variables
# Types of auxiliary variables
## Type 0: Leads of endogenous >=2
## Type 0: Leads of endogenous >=2
This kind of aux var has `M_.aux_vars(i).type = 0` and substitutes for an expression in the original model where a lead of 2 or more appears on an endogenous variable.
This kind of aux var has `M_.aux_vars(i).type = 0` and substitutes for an expression in the original model where a lead of 2 or more appears on an endogenous variable.
The name of such an aux var begins with `AUX_ENDO_LEAD_`.
The name of such an aux var begins with `AUX_ENDO_LEAD_`.
## Type 1: Lags of endogenous >=2
## Type 1: Lags of endogenous >=2
This kind of aux var has `M_.aux_vars(i).type = 1` and substitutes for an expression in the original model where a lag of 2 or more appears on an endogenous variable.
This kind of aux var has `M_.aux_vars(i).type = 1` and substitutes for an expression in the original model where a lag of 2 or more appears on an endogenous variable.
The name of such an aux var begins with `AUX_ENDO_LAG_`.
The name of such an aux var begins with `AUX_ENDO_LAG_`.
## Type 2: Lead of exogenous
## Type 2: Lead of exogenous
This kind of aux var has `M_.aux_vars(i).type = 2` and substitutes for an expression in the original model where a lead on an exogenous variable appears. The name of such an aux var begins with `AUX_EXO_LEAD_`.
This kind of aux var has `M_.aux_vars(i).type = 2` and substitutes for an expression in the original model where a lead on an exogenous variable appears. The name of such an aux var begins with `AUX_EXO_LEAD_`.
## Type 3: Lag of exogenous
## Type 3: Lag of exogenous
This kind of aux var has `M_.aux_vars(i).type = 3` and substitutes for an expression in the original model where a lag on an exogenous variable appears. The name of such an aux var begins with `AUX_EXO_LAG_`.
This kind of aux var has `M_.aux_vars(i).type = 3` and substitutes for an expression in the original model where a lag on an exogenous variable appears. The name of such an aux var begins with `AUX_EXO_LAG_`.
## Type 4: `EXPECTATION()`-operator
## Type 4: `EXPECTATION()`-operator
This kind of aux var has `M_.aux_vars(i).type = 4` and results from the `EXPECTATION()`-operator employing the (full) information set of another period. It substitutes for an expression like `EXPECTATION(-1)(...)`. The name of such an aux var begins with `AUX_EXPECT_LEAD_` or `AUX_EXPECT_LAG_`.
This kind of aux var has `M_.aux_vars(i).type = 4` and results from the `EXPECTATION()`-operator employing the (full) information set of another period. It substitutes for an expression like `EXPECTATION(-1)(...)`. The name of such an aux var begins with `AUX_EXPECT_LEAD_` or `AUX_EXPECT_LAG_`.
## Type 5: `differentiate_forward_vars`-option (since Dynare 4.4)
## Type 5: `differentiate_forward_vars`-option (since Dynare 4.4)
This kind of aux var has `M_.aux_vars(i).type = 5` and results from `differentiate_forward_vars`-option of `model`. In this case, forward variables are differentiated and and the difference replaced by an aux var, whose name begins with `AUX_DIFF_FWRD_`.
This kind of aux var has `M_.aux_vars(i).type = 5` and results from `differentiate_forward_vars`-option of `model`. In this case, forward variables are differentiated and and the difference replaced by an aux var, whose name begins with `AUX_DIFF_FWRD_`.
`M_.aux_vars(i).orig_index` contains the index of the endogenous variable of which it is the differentiate.
`M_.aux_vars(i).orig_index` contains the index of the endogenous variable of which it is the differentiate.
## Type 6: Lagrange multipliers of the `ramsey_model` (since Dynare 4.3)
## Type 6: Lagrange multipliers of the `ramsey_model` (since Dynare 4.3)
This kind of aux var has `M_.aux_vars(i).type = 6` and corresponds to the Lagrange multipliers attached to the first order conditions of the Ramsey problem. They will appear whenever `ramsey_model` is used. Their name begins is `MULT_i`, where `i` is the equation number with which the multiplier is associated.
This kind of aux var has `M_.aux_vars(i).type = 6` and corresponds to the Lagrange multipliers attached to the first order conditions of the Ramsey problem. They will appear whenever `ramsey_model` is used. Their name begins is `MULT_i`, where `i` is the equation number with which the multiplier is associated.
`M_.aux_vars(i).eq_nbr` contains the number of the equation (constraint) with which the multiplier is associated.
`M_.aux_vars(i).eq_nbr` contains the number of the equation (constraint) with which the multiplier is associated.
## Type 7: `var(log)` declaration (since Dynare 6.0)
## Type 7: `var(log)` declaration (since Dynare 6.0)
This kind of aux var has `M_.aux_vars(i).type = 7` and is created when declaring an endogenous variable with `var(log)`, e.g. `var(log) y`. The auxiliary will be named `LOG_y` and every occurrence of `y(±l)` within the model will be replaced by `exp(LOG_y(±l))`.
This kind of aux var has `M_.aux_vars(i).type = 7` and is created when declaring an endogenous variable with `var(log)`, e.g. `var(log) y`. The auxiliary will be named `LOG_y` and every occurrence of `y(±l)` within the model will be replaced by `exp(LOG_y(±l))`.
## Type 8: `diff` operator (since Dynare 4.6)
## Type 8: `diff` operator (since Dynare 4.6)
This kind of aux var has `M_.aux_vars(i).type = 8` and substitutes for the `diff` operator. The name of such an auxiliary variable begins with `AUX_DIFF_`.
This kind of aux var has `M_.aux_vars(i).type = 8` and substitutes for the `diff` operator. The name of such an auxiliary variable begins with `AUX_DIFF_`.
The substitution will only happen if there is no lead in the argument to the `diff` operator.
The substitution will only happen if there is no lead in the argument to the `diff` operator.
-`M_.aux_vars(i).orig_index` contains the index of the variable contained in the `diff` operator. This field exists if the `diff` was taken of a variable, not of an expression.
-`M_.aux_vars(i).orig_index` contains the index of the variable contained in the `diff` operator. This field exists if the `diff` was taken of a variable, not of an expression.
-`M_.aux_vars(i).orig_lead_lag` contains the lag of the variable contained in the `diff` operator. This field exists if the `diff` was taken of a variable, not of an expression.
-`M_.aux_vars(i).orig_lead_lag` contains the lag of the variable contained in the `diff` operator. This field exists if the `diff` was taken of a variable, not of an expression.
## Type 9: lag within `diff` operator (since Dynare 4.6)
## Type 9: lag within `diff` operator (since Dynare 4.6)
This kind of aux var has `M_.aux_vars(i).type = 9` and accounts for applying the difference operator to a lag. If a `diff` operator is applied to a variable with lagged values (e.g. `diff(x(-3)`), and if there is also a `diff` operator with the same arguments shifted in the future (e.g. `diff(x)`), then a diff auxiliary variable (of type 8) is created for the `diff` operator applied to the variable with lag equal to zero (e.g. `diff(x)`) and auxiliary variables (of type 9) are created for the following sequence `diff(x(-1)`, `diff(x(-2))`, and `diff(x(-3)`). The name of such auxiliary variables begins with `AUX_DIFF_LAG_`.
This kind of aux var has `M_.aux_vars(i).type = 9` and accounts for applying the difference operator to a lag. If a `diff` operator is applied to a variable with lagged values (e.g. `diff(x(-3)`), and if there is also a `diff` operator with the same arguments shifted in the future (e.g. `diff(x)`), then a diff auxiliary variable (of type 8) is created for the `diff` operator applied to the variable with lag equal to zero (e.g. `diff(x)`) and auxiliary variables (of type 9) are created for the following sequence `diff(x(-1)`, `diff(x(-2))`, and `diff(x(-3)`). The name of such auxiliary variables begins with `AUX_DIFF_LAG_`.
-`M_.aux_vars(i).orig_index` contains the index of the preceding auxiliary variable for diff lag or of the auxiliary variable for diff itself (types 9 or 8)
-`M_.aux_vars(i).orig_index` contains the index of the preceding auxiliary variable for diff lag or of the auxiliary variable for diff itself (types 9 or 8)
-`M_.aux_vars(i).orig_lead_lag` contains `0` (not needed because we know the lag is equal to 1 compared to the previous aux variable in the sequence)
-`M_.aux_vars(i).orig_lead_lag` contains `0` (not needed because we know the lag is equal to 1 compared to the previous aux variable in the sequence)
## Type 10: unary operators (since Dynare 5)
## Type 10: unary operators (since Dynare 5)
This kind of aux var has `M_.aux_vars(i).type = 10` is substituted for an expression consisting of a unary operator (namely `exp`, `log`, `log10`, `cos`, `sin`, `tan`, `acos`, `asin`, `atan`, `cosh`, `sinh`, `tanh`, `acosh`, `asinh`, `atanh`, `sqrt`, `cbrt`, `abs`, `sign` and `erf`). Such an auxiliary variable is typically created for an expression of the form `log(x)` in the context of a `var_model` or a `trend_component_model`. The name of such an auxiliary variable begins with `AUX_UOP_`.
This kind of aux var has `M_.aux_vars(i).type = 10` is substituted for an expression consisting of a unary operator (namely `exp`, `log`, `log10`, `cos`, `sin`, `tan`, `acos`, `asin`, `atan`, `cosh`, `sinh`, `tanh`, `acosh`, `asinh`, `atanh`, `sqrt`, `cbrt`, `abs`, `sign` and `erf`). Such an auxiliary variable is typically created for an expression of the form `log(x)` in the context of a `var_model` or a `trend_component_model`. The name of such an auxiliary variable begins with `AUX_UOP_`.
If the `transform_unary_ops` option has been passed to `dynare`, then the substitution is done everywhere in the model. Otherwise, by default, it is only performed in the equations appearing in a `var_model` or a `trend_component_model`.
If the `transform_unary_ops` option has been passed to `dynare`, then the substitution is done everywhere in the model. Otherwise, by default, it is only performed in the equations appearing in a `var_model` or a `trend_component_model`.
## Type 11: lead within `diff` operator (since Dynare 5)
## Type 11: lead within `diff` operator (since Dynare 5)
This kind of aux var has `M_.aux_vars(i).type = 11` and accounts for applying the difference operator to a lead. Similarly to Type 9, it will create a sequence of auxiliary variables, but for leads.
This kind of aux var has `M_.aux_vars(i).type = 11` and accounts for applying the difference operator to a lead. Similarly to Type 9, it will create a sequence of auxiliary variables, but for leads.
Such aux vars only appear in the context of PAC models with model-consistent expectations (when constructing the expectation term).
Such aux vars only appear in the context of PAC models with model-consistent expectations (when constructing the expectation term).
-`M_.aux_vars(i).orig_index` contains the index of the preceding auxiliary variable for diff lead or of the auxiliary variable for diff itself (types 11 or 8)
-`M_.aux_vars(i).orig_index` contains the index of the preceding auxiliary variable for diff lead or of the auxiliary variable for diff itself (types 11 or 8)
-`M_.aux_vars(i).orig_lead_lag` contains `0` (not needed because we know the lead is equal to 1 compared to the previous aux var in the sequence)
-`M_.aux_vars(i).orig_lead_lag` contains `0` (not needed because we know the lead is equal to 1 compared to the previous aux var in the sequence)
## Type 12: `pac_expectation` operator (since Dynare 5)
## Type 12: `pac_expectation` operator (since Dynare 5)
This kind of aux var has `M_.aux_vars(i).type = 12` accounts for applying the `pac_expectation`-operator to a `pac_model`.
This kind of aux var has `M_.aux_vars(i).type = 12` accounts for applying the `pac_expectation`-operator to a `pac_model`.
## Type 13: `pac_target_nonstationary` operator (since Dynare 5)
## Type 13: `pac_target_nonstationary` operator (since Dynare 5)
This kind of aux var has `M_.aux_vars(i).type = 13` accounts for applying the `pac_target_nonstationary`-operator to a `pac_model`.
This kind of aux var has `M_.aux_vars(i).type = 13` accounts for applying the `pac_target_nonstationary`-operator to a `pac_model`.