Differences between revisions 6 and 10 (spanning 4 versions)
Revision 6 as of 2010-11-25 14:56:47
Size: 3084
Editor: PabloWinant
Comment:
Revision 10 as of 2010-11-25 15:25:34
Size: 2842
Editor: PabloWinant
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The feature was introduced in Dynare v.4.1. It allows user to attach arbitrary informations to each equation and to recover them at runtime. It is particularly useful to specify names of equations but can also be used to introduce other informations in the model.
Tags are stored in a special structure M_.equations_tags.
Currently, equations tags are not used by any Dynare code from the portfolio module but they can be very useful for handwritten code.
The feature was introduced in Dynare v.4.1. It allows user to attach arbitrary informations to each equation and to recover them at runtime.

It is particularly useful to specify names of equations but can also be used to introduce other informations in the model.

Tags are stored in a special structure {{{M_.equations_tags}}}.

Currently, equations tags are not used by any Dynare code from the portfolio module but they can be very useful for custom algorithms.
Line 9: Line 13:
Before each equation in the modfile, the user can specify a list pairs (key,values) were key is any identifier and value a single-quoted string. This is demonstrated by the following example : Before each equation in the modfile, the user can specify a list pairs (key,values) were key is any identifier and value a single-quoted string.

This is demonstrated by the following example :
Line 19: Line 25:
[name = 'Euler condition', euler_var='k'] [name = 'Euler condition', euler_var='k', type='expectation']
Line 29: Line 35:
In this simple example, we have given a name to each equation. We have also added the
name of the variable used to derive the Euler equation and have specified that last equation is exogenous.
In this simple example, we have given a name to each equation. We have also added the name of the variable used to derive the Euler equation and have specified that last equation is exogenous.
Line 34: Line 39:
The tags are stored in a 3-column cell. Each line correspond to a tag (n,key,value) where n is the number of the equation.

The table is stored in {{{M_.equations_tags}}}. It can be queryied directly or using one of the helper functions.

Here are some examples.
Line 36: Line 47:
It is common to be looking for the steady state of a given set of equations. The command 'resid' included in Dynare, can be used to print the residuals and see which equations are met at the steady-state.  When the number of equations is big, it is easier to use the command resid_with_names [[attachment:resid_with_names.m]] , which will also print the value of a specific key for all the equations, making it much easier to recover the faulty equation. It is common to be looking for the steady state of a given set of equations. The command 'resid' included in Dynare, can be used to print the residuals and see which equations are met at the steady-state.

When the number of equations is big, it is easier to use the command resid_with_names [[attachment:resid_with_names.m]] , which will also print the value of a specific key for all the equations, making it much easier to recover the faulty equation.

Line 38: Line 53:
Line 44: Line 60:
=== Find the equation having a given key or a given value for a given key ===
Line 45: Line 62:
== Details about the implementation == Function {{{select_from_table}}} [[attachment:select_from_table.m]] can be used to find equations satisfying given properties.
Line 47: Line 64:
 * Add general labels to equations. In the current prototype a list of key-values pair can be written in brackets before each equation : For the same model {{{select_from_table('type')}}} will return the indices of equations for which a key 'type' has been specified :
Line 49: Line 67:
[key='value',key='value',...] y = y + 1; ans =

     2
     3
Line 51: Line 72:
One may want to attach values of any type to an equation. Currently, only strings of characters are recognized but we ask the user to specify users to enter quoted strings nevertheless. Type of keys should also be restricted so that they can be used as fields in matlab structures if needed, i.e. no numeric character, no space,...
Line 53: Line 73:
 * Structure in the preprocessor is the same as in Matlab and mimics a database table : an array with 3 columns. It is stored in M_.equations_tags as in : By contrast {{{select_from_table('type','expectation')}}} will return the list of equations which have the type expectation :
Line 55: Line 76:
M_.equations_tags = {
    1 'name' 'First equation';
    2 'name' 'Second equation';
    2 'portfolio' 'true';
};
ans =

     2
     3
Line 61: Line 81:
 * It is easy to query this table in matlab as follows
{{{
tags = M_.equations_tags;
tags(cell2mat(tags(:,1))==2,2:3) % all tags for equation 2
tags(strmatch('name',tags(:,2)),[1 3]) % a vector with equations numbers and associated names
}}}

Equations tags

The feature was introduced in Dynare v.4.1. It allows user to attach arbitrary informations to each equation and to recover them at runtime.

It is particularly useful to specify names of equations but can also be used to introduce other informations in the model.

Tags are stored in a special structure M_.equations_tags.

Currently, equations tags are not used by any Dynare code from the portfolio module but they can be very useful for custom algorithms.

Flagging equations with tags

Before each equation in the modfile, the user can specify a list pairs (key,values) were key is any identifier and value a single-quoted string.

This is demonstrated by the following example :

...preamble

model;

[name = 'Budget constraint']
c + k = k^theta*A;

[name = 'Euler condition', euler_var='k', type='expectation']
beta*(c(1)/c)^(-sigma)*theta*k^(theta-1)*A(1) = 1;

[name = 'Specification of shocks', type='exogenous']
log(A) = rho*log(A(-1))  + epsilon;

end;
...conclusion

In this simple example, we have given a name to each equation. We have also added the name of the variable used to derive the Euler equation and have specified that last equation is exogenous.

Usecases

The tags are stored in a 3-column cell. Each line correspond to a tag (n,key,value) where n is the number of the equation.

The table is stored in M_.equations_tags. It can be queryied directly or using one of the helper functions.

Here are some examples.

Find the equation corresponding to nonzero residuals

It is common to be looking for the steady state of a given set of equations. The command 'resid' included in Dynare, can be used to print the residuals and see which equations are met at the steady-state.

When the number of equations is big, it is easier to use the command resid_with_names resid_with_names.m , which will also print the value of a specific key for all the equations, making it much easier to recover the faulty equation.

For instance, calling resid_with_names('name') for the (fictive) previous model will output something like

Eq (1) : 0 : Budget constraint
Eq (2) : 0.1 : Euler condition
Eq (3) : 0 : Specification of shocks

Find the equation having a given key or a given value for a given key

Function select_from_table select_from_table.m can be used to find equations satisfying given properties.

For the same model select_from_table('type') will return the indices of equations for which a key 'type' has been specified :

ans =

     2
     3

By contrast select_from_table('type','expectation') will return the list of equations which have the type expectation :

ans =

     2
     3

DynareWiki: EquationsTags (last edited 2010-11-25 15:25:34 by PabloWinant)