Evaluate likelihood at single parameter vector

Hi all,

I was wondering if there is a way to have Dynare evaluate the likelihood and/or posterior density at a single parameter guess? I’m trying to build the likelihood and posterior density for the Smets Wouters 07 model but without the use of Dynare.

I’ve managed to solve the model (which I checked by comparing the second-moments of the endogenous variables in my hand-written code against dynare) but given the problems I’ve encountered, I’m a lot less certain that I haven’t screwed up my computation of posterior likelihood

The easiest way is to set

options_.debug=1

You will then have a field

oo_.likelihood_at_initial_parameters;

which stores the posterior (likelihood if you use ML).

Okay, I’ve managed to solve out the model moments in dynare and in my home-built code and they both match. However, the likelihood at the initial parameter guess is very slightly different between dynare and my own code:

Dynare reports a log likelihood of -2136.3977 while my own code gives a log likelihood of -2136.10010115258.

Is there anything special about how Dynare computes the model likelihood? Does it drop the first observation or perhaps initialize the prediction-variance matrix? Should I even be worried about such a seemingly small difference in likelihood?

The prediction variance matrix is initialized at the unconditional variance. Usually, such small differences are not a reason to worry. But when you are checking consistency, you usually want to be sure.

I have figured out why my likelihood was slightly different: the parameter vector in the dynare file was very slightly different from the parameter I asked my home-built code to evaluate. After fixing the dynare file, the likelihood was exactly the same between my own code and dynare’s code. Therefore I am more than confident that my likelihood function is correct, or at least consistent with Smets Wouters!

Having computed the likelihood function, I am now trying to compute the posterior by combining the prior and likelihood. I am now, however, getting somewhat larger discrepancies.

To diagnose the error, I changed all of the prior distributions in both my code and the Dynare code to normal densities. This resulted in identical posterior densities between the two programs. However, when I changed the prior on any one parameter in both programs to a beta pdf, inverse gamma pdf, or gamma pdf, then I got different values for the log posterior.

To obtain the beta and gamma pdfs I just use the betapdf(x,a,b) and gamma(x,a,b) matlab functions. To obtain the log of the inverse gamma function I use

y = log(2) - gammaln(b/2) + (b/2)log(ba^2/2) - ( (b+1)/2 )log(x^2) - ba^2/(2*x^2);

It’s always tricky to get the right mapping into a and b. See Chapter 4 and the associated codes in my Kobe lecture at https://sites.google.com/site/pfeiferecon/teaching

1 Like