Estimation
Data and parameters
Constraining parameters
Q: I'd like to constrain my parameter values either to be positive, or to be related to other parameters by an explicit function.
If you want to restrict a parameter to positive numbers, use a prior such as "gamma_pdf" or "inv_gamma_pdf".
Note that "estimated_params_bounds" is only used as a help for computing the posterior mode, it isn't used during MH iterations. It is only for avoiding that the optimizer gets itself lost in regions where the mode can't reasonably be. It isn't a device to do constrained estimation.
To relate two parameters with a function, it is easiet to take an example: let d=h(e, f), where e and f are estimated while d is constant and h(.) is a known and possibly nonlinear function of its arguments. Then write: # sign at the beginning of the line (in order to differenciate this definition from a model equation and specify it as a Matlab function), and # f = h_1(d,e) where h_1() is the inverse function, expressing f as a function of d and e. Again, you estimate e, but not f.
More simply, if you wanted to constain, for example, a+b+c=0, you would simple write #c = -a-b.
[for more information, see post in forum by: jmaih - Feb 11, 06, or twlxv - May 11, 2006]Dealing with non stationary data
Q: I have non-stationarity issues in my data, what shall I do?
Dynare is set up to deal with either a unit root, or linear drift (deterministic trend).
In the latter case, use the command "observation_trends" to specify trends for observed variables as functions of model parameters. In most cases, variables shouldn't be centered when "observation_trends" is used.
For example:
observation_trends; Y (eta); P (mu/eta); end;
In the former case, use "unit_root_vars" to declare unit-root variables of a model so that a diffuse prior can be used in the initialization of the Kalman filter for these variables only.
Note, though, that when there are nonstationary variables in a model, there is no unique deterministic steady state. You must supply a Matlab function that computes the steady state values of the stationary variables in the model and returns dummy values for the nonstationary ones. The function should be called with the name of the .mod file followed by _steadystate. See fs2000a_steadystate.m in the examples/fs2000 directory of your Dynare folder.
Note finally that the nonstationary variables in the model must be integrated processes (ie, their first difference or k-difference must be stationary).
For more information on the difference between deterministic and stochastic trends, see the post on the forum by: iacoviel - 1 Feb, 2006.
Positive var-cov matrix
Q: How do I specify that all the values in my var-cov matrix are positive?
You actually do not need to do this, as Dynare checks that the matrix is positive definite and rejects all other parameter values.
[for more information, see post in forum by: twlxv, Jan 22, 2006]Your output
Retrieving shocks
Q: I would like to retrieve the estimated shocks from my estimated model to use for further work, for example, to feed them back into a model and run counterfactuals or historical decompositions.
After estimation, the smoothed shocks are available in dr_.posteriorSmoothedShocks.
Note that smoothed shocks are a reconstruction of the values of unobserved shocks over the sample, using all the information contained in the sample of observation. They are computed via the Kalman smoother. Contrarily to OLS regression, there is no built in requirement that the sum of the shocks be zero. However the assumption of the model is that they are zero mean. If you obtain smoothed shocks that are systematically away from zero, there is a problem in your model, either missing constants or a mismatch between the meaning of the variables in your model and in your data.
[for more information, see post in forum by: iacoviel - Feb 1, 2006 or by siwage - Aug 14, 2006]
Working with an estimated model
Trouble with forecasting
Q: I don't seem to be able to do forecasting with my estimated model. What could the problem be?
An often encountered problem has to do with a limitation of Dynare. Indeed, Dynare cannot forecast out of the posterior mode. You need to run Metropolis iterations before being able to run forecasts on an estimated model (by adding "forecast" to the estimation command line)
For example:
estimation (datafile = datapull, first_obs=50, mh_nblocks = 1, nobs=200, mode_compute=4, mh_replic=0, mode_check, forecast=40)
[for more information, see the post in the forum by: jdavis - July 19, 2006]
Comparing models
Q: I have two models that I would like to compare in terms of their accuracy at capturing the data. How do I do this?
There is an explicit command in Dynare to do this: use "model_comparison" which must be followed by the name of two *.mod files you want to compare. By default, the comparison is done on the basis of the Laplace approximation of log data density and therefor this can be used just after finding the posterior modes.
Note that in the option, you can either specify the laplace or modifiedharmonicmean (the latter requires metropolis iterations) approximations.
The syntax to use for the option is:
model_comparison(model_comparison_approximation=laplace) name1.mod, name2.mod;
[for more information, see post in forum by: tanya, Sept 12, 2006]
Calculating prediction errors
Q: How do I calculate prediction errors on the basis of my estimated model?
You can request the option "filtered_vars" to make the filtered variables available in oo_ . You can then compute the one period ahead prediction error as observation minus filtered variable
[for more information, see post in forum by: iacoviel - May 12, 2006]
Simulations with an estimated model
Q: How do I run simulations - impulse response functions - from my estimated model?
Some users prefer the manual approach. They usually:
- Estimate the model to obtain the parameters and exogenous shocks. The exogenous shocks are saved in the oo_ file.
- Save the shocks in a file called datafile.mat.
- Simulate a deterministic model with the shocks saved from the estimation in the oo_ file, by specifying the source file for the shocks, using the "shocks(shocks_file = datafile.mat)" command.
[for more information, see post in forum by: adamshap - Aug 1, 2006]
But you can also use built in commands:
- If you have done Metropolis iterations, you should use the option "bayesian_irf" in the estimation command.
- If
you have only computed the posterior mode, you should do "stoch_simul"
to have the IRFs when the parameters are set at the posterior mode.
[for more information, see post in forum by: bamba - Apr 18, 2006]
Miscellaneous
Doing Metropolis estimations takes forever
Q: When I estimate my model using Metropolis-Hastings iterations, the computer takes forever. Is it that my computer is just too slow?
Most likely not!
- An estimation with Metropolis iterations is by an large a night job. Plan your work accordingly.
- Quite often, what takes the most time is to compute the steady state of a nonlinear model where the estimated parameters affect the steady state. If you have an analytical solution for the steady state, write a *_steadystate.m function.
- The computation time increase in the number of variables and the number of estimated parameters. Eliminate from your model all nonessential variables that you may be tempted to include just for reporting purpose (various interesting ratios) .
[for more information, see the post in the forum by: twlxv - Feb 5, 06]