Matching observables from data into measurement equation

Hi everyone,

I am currently going through the codes of Benedikt Kolb, where he shows us how to maximise the likelihood of a New Keynesian model with a financial accelerator over one parameter. He uses Uhlig’s toolbox to solve the model but before he does that he matches the observables from the data into the measurement equation:

% H, matching observables from dy into measurement equation
ns = 16; % # states in model
H = zeros(nd,ns); %nd is the number of observables which is equal 6
H(1,5) = 1; % Y = y(t)
H(2,6) = 1; % C = c(t)
H(3,7) = 1; % I = i(t)
H(4,8) = 1; % P = pi(t)
H(5,9) = 1; % R = rn(t)
H(6,10) = 1; % S = cs(t)

H is 6 by 16 matrix, where the rows represent the number of observables and the columns the number of state variables. Does anyone know why output Y takes the position 5 in row 1 and so on? My plan was to understand the codes and link them back to Dynare’s output after the model has been solved. All codes are attached - the lines of code above can be found in example1.m. (481.2 KB)

Thanks Rob

Hi Rob,

this really just depends on the way the vector of endogenous variables is set up, ie in what order he put the variables. The way he did it is that Y is the fifth one, c number 6 etc. When he sets up the model in the large matrices, this is the order in which he types in the equations. I am sure that he explains this order somewhere, otherwise you can extract it by going through the equations and the matrices of the solution method.

1 Like

Thanks @DoubleBass!

This is a quick follow up question with regard to @DoubleBass’ answer. Is there a way to set up the same H matrix with the help of the output of Dynare? In other words, once we have the solution of the model is it possible to link my endogenous variables to the observables using the M matrix approach as shown above? I have been looking into the oo\_ and M\_ structures, but my feeling is that this won’t be possible, correct me if I am wrong. Thanks!

Have a look at


Thanks Johannes!

Sorry @jpfeifer, one last question regarding this. In the link you posted, the corresponding matrix to H is C in Dynare, which we get using the kalman transition matrix file given the oo\_dr.ghx. In the ABCD test, you get the position of the observables using

%get observable position in decision rules

Therefore, all elements of the C matrix are filled. In contrast, the H matrix above is a matrix with ones on the diagonal that corresponds to the order of the endogenous variables. As I am following Benedikt Kolb’s codes above, Is there a way to map from C over to H? Or can I just use C, sorry can’t get my head around this at the moment…

The part

% declare pseudo-states
% 10) 0 = p_y(t)  - y(t)
% 11) 0 = p_c(t)  - c(t)
% 12) 0 = p_i(t)  - i(t)
% 13) 0 = p_pi(t) - pi(t)
% 14) 0 = p_rn(t) - rn(t)
% 15) 0 = cs(t) - (rk(t) - r(t))

in uhligsolve.m suggests that a trick was used to have the observables in the state matrix. It’s tough to replicate that.

Thanks @jpfeifer, that’s what I thought that it won’t be that easy.

If I were in your place, I would not aim at replicating the approach one for one, but rather to get a consistent state space representation for each approach and work with those.

Thanks @jpfeifer, annoyingly I thought I almost had it but then the H matrix seems to make things difficult. I will try what you said. I came across this post

Would you say this is a good starting point? Also, I have seen that you replicated Dynare’s Kalman results with the internal MATLAB implementation. Do you remember whether you have used the

likelihood( )


Did you see the that I have Kalman filter codes that replicate Dynare’s results at Johannes Pfeifer - Teaching

1 Like

Thanks Johannes, I will give it a go!