MANUAL creation of IRF function

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

MANUAL creation of IRF function

Postby marlenemaya » Mon Nov 21, 2016 4:07 pm

Hi,
this is my code. In the first part is requested to solve a partial equilibrium model. The model works, but in the second part of the exercise is required to create our own impulse response graphs and to compare them with the ones created authomatically by the software. I don't know exactly how to do it: i've part of the code to use but i'm not able to use the data from the policy function to generate matrices in which taking values to plot. the problem is probably more theoretical than a codes' problem.
Can someone help me?
Thank you

Code: Select all
// MARKET FOR ENGINEERS
 
/********
*Model in levels*
********/
 
 
 
 
var s w N P ;
 
 
varexo e u;          // e=epsilon s u=epsilon d
 
 
parameters a0 a1 d0 d1 beta delta ;
 
a0 = 10;
a1 = 1;
d0 = 1000;
d1 = 1;
beta = 0.99;
delta = 0.02;
 
 
 
 
 
 
model(linear);
 
 
P=(1-delta)*beta*P(+1)+(1-delta)^(5)*beta^(5)*w(+5);
s=a0+a1*P+e;
N=(1-delta)*N(-1)+s(-5);
N=d0-d1*w+u;
 

end;
 
//steady_state_model;
// the model is already loglinearized so there is no need of writing the initial values of steady state.
 

steady;
check;
 
 
shocks;
var e; stderr 1;
var u; stderr 1;

end;

 
stoch_simul(periods=500 ,order=1);

//ordering variables s w N P

p_s = 1;
p_w = 2;
p_N = 3;
p_P = 4;

//

     % state space representation: S(t) = A*S(t-1) + B*e(t),
     % X(t) = C*S(t-1) + D*e(t);


     C = [oo_.dr.ghx(oo_.dr.inv_order_var(p_s),:);
         oo_.dr.ghx(oo_.dr.inv_order_var(p_w),:);
         oo_.dr.ghx(oo_.dr.inv_order_var(p_N),:);
         oo_.dr.ghx(oo_.dr.inv_order_var(p_P),:)];
     D = [oo_.dr.ghu(oo_.dr.inv_order_var(p_s),:);
         oo_.dr.ghu(oo_.dr.inv_order_var(p_w),:);
         oo_.dr.ghu(oo_.dr.inv_order_var(p_N),:);
         oo_.dr.ghu(oo_.dr.inv_order_var(p_P),:)];
H = 500;

Xirf = zeros(4,H);

Xirf(:,1) = D;
for j = 2:H
   
    Xirf(:,j) = C;
end;
marlenemaya
 
Posts: 19
Joined: Mon Nov 21, 2016 3:56 pm

Re: MANUAL creation of IRF function

Postby jpfeifer » Tue Nov 22, 2016 2:20 pm

You need to identify the states in Dynare's decision rule matrices and then simulate forward. Dynare does this in it's
Code: Select all
simult_.m

function. If you do not want to use the function directly, you need the respective part of it:
Code: Select all
        k2 = dr.kstate(find(dr.kstate(:,2) <= M_.maximum_lag+1),[1 2]);
        k2 = k2(:,1)+(M_.maximum_lag+1-k2(:,2))*endo_nbr;
        order_var = dr.order_var;
        epsilon = dr.ghu*transpose(ex_);
        for i = 2:iter+M_.maximum_lag
            yhat = y_(order_var(k2),i-1);
            y_(order_var,i) = dr.ghx*yhat + epsilon(:,i-1);
        end
        y_ = bsxfun(@plus,y_,dr.ys);
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: MANUAL creation of IRF function

Postby marlenemaya » Thu Nov 24, 2016 11:03 am

Thank you a lot for your answer.
Is it better for use to use another code used during lessons.
we should in practice first order our variables
Code: Select all
p_s=1
p_w=2
p_N=3
p_P=4

then we should create our matrices A, B,C,D based on the state space representation
Code: Select all
A = [oo_.dr.ghx(oo_.dr.inv_order_var(p_s),:);
    oo_.dr.ghx(oo_.dr.inv_order_var(p_N),:)];

   
B =[oo_.dr.ghu(oo_.dr.inv_order_var(p_s),:);
    oo_.dr.ghu(oo_.dr.inv_order_var(p_N),:)];

      C =[oo_.dr.ghx(oo_.dr.inv_order_var(p_w),:);
    oo_.dr.ghx(oo_.dr.inv_order_var(p_P),:)];

Nb this is just an example...
and then we should use the matrices to create the series to plot
Code: Select all
Sirf = zeros(2,H);
4 Xirf = zeros(6,H);
5
6 Sirf(:,1) = B*sigmae;
7 Xirf(:,1) = D*sigmae;
8
9 for j = 2:H
10 Sirf(:,j) = A*Sirf(:,j−1);

Is always an example...
The problem is that, given the model, we should have 12 variables, 6 states and 6 controls;
the states are s(-1)...s(-5) and N(-1), since we have fixed K=5, and the same for the controls( w(+1), etc). How can we say to dynare to use these variable?
Should we order all the 12 variables even if declared just four?
And then, in the matrixes, dynare "reads" s(-1) as a function or an an element of a vector, that for this reason cannot be negative.
During the construction of Xirf and Sirf it complaints about problems with matrixes dimension, and we think it's because of the wrong construction of A B, C D.
We are not able to find example with variables indexed at times following t+1 or previous to t-1. Probably is not such a big problem but we don't know how to proceed.
Thank you
marlenemaya
 
Posts: 19
Joined: Mon Nov 21, 2016 3:56 pm

Re: MANUAL creation of IRF function

Postby jpfeifer » Thu Nov 24, 2016 1:56 pm

In that case you need to introduce auxiliary variables for lag bigger than 1 (essentially a companion form). That way, Dynare will not introduce auxiliary variables itself, which can be hard to access.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests