Page 1 of 1

Q: combining IRFs into subplotted figures & iterating?

PostPosted: Wed Jan 08, 2014 1:21 pm
by GOODLUCK
Hi all,

I am really frustrated by the following issue but didn't find answers in the forum, so I'm afraid I had to raise the frequently asked problem again. The setup is that I have two models, and want to compare the IRFs of each endogenous variables due to exo shocks. Say, model 1 and 2, both have endo variables y and c, exo shocks ea and em. So, the names of two models' variables are totally the same. Now, I want to plot two IRF figures, one for response of shock ea, another em.Each figure has two subfigures,one for response of y,another c.And each subfigure has two curves, one stands for IRF of model 1, another model 2. By learning from related posts in this forum, I just write the following code, but failed to run it out.
Code: Select all
dynare model1.mod
load('model1_results.mat', 'oo_')
irf1=oo_.irfs;
save irf1
load irf1

dynare model2.mod
load('model2_results.mat', 'oo_')
irf2=oo_.irfs;
save irf2
load irf2

ending_cell={'_ea','_em'};

for ii=1:length(ending_cell)
HOR=1:1:40;
var={'y','c'};
figure
for jj=1:length(var)
subplot(1,2,jj)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'LineWidth',1,'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'LineWidth',1,'--r')
title([var{1,jj}] )
end
end


Matlab just stopped by warning"Undefined variable "irf1" or class "irf1.y_ea"."I guess the contents of irf1 are just overlapped by irf2, because all the variable names are the same among the two models. But I don't know how to get rid of the problem.Could anyone kindly give me another hand please?

Many thanks indeed.

GOODLUCK

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Wed Jan 08, 2014 4:11 pm
by GOODLUCK
I've tried dealing with this problem by reinstalling DYNARE4.40 exclusively in my personal computer under path C:, but with things unchanged. The error just displays as :

Undefined variable "irf1." or class "irf1.y_epsilon_A".

Error in plotting (line 37)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);

I am wondering whether things could be improved or fixed. I have no idea how to figure out the wrongs since I am also quite new to Matlab. So sorry that I have so many questions, yet I have to ask anyone has any idea?

Best,

GOODLUCK

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Fri Jan 10, 2014 5:35 pm
by jpfeifer
You either need to load irf1 after the last call to Dynare or use the noclearall option.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Sun Jan 12, 2014 1:03 pm
by GOODLUCK
Thank you very much, jpfeifer. I've done it.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Mon Apr 14, 2014 11:57 am
by yufeng
GOODLUCK wrote:Thank you very much, jpfeifer. I've done it.



Hi,GOODLUCK,

I meet the same question as you, but I still don't know how to plot them? Can you tell me how you do it? Thank you!

yufeng

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Sun May 25, 2014 5:31 pm
by lah89
I d like to see an example solution as well :)
In particular I want to combine 2 irf-outputs from stoch_simul showing the IRFs for certain endogenous variables, for the same model (same endogenous variables, same shock, but different shocksizes) in one picture.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Thu Apr 02, 2015 3:02 am
by Mylene
Hello!

I am very new to Matlab. I've spent so many days searching for the correct codes in combining plots. I tried also this code, but yes, it is with error. How to remove the error? Jpfeifer suggested to use a noclearall option or load irf1. How exactly to do the suggestion?

Thanks so much for the help in advance.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Thu Apr 02, 2015 9:34 am
by jpfeifer
Please provide more information. Provide both the files and precise instructions on what you are trying to plot from the two mod-files.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Tue Jun 02, 2015 6:04 pm
by Zeinab
Code: Select all
dynare Flexible_1.mod
load('Flexible_1_results.mat', 'oo_')
irf1=oo_.irfs;
save irf_1
load irf_1

dynare Flexible_2.mod
load('Flexible_2_results.mat', 'oo_')
irf2=oo_.irfs;
save irf_2
load irf_2

ending_cell={'_eps_A'};

for ii=1:length(ending_cell)
HOR=1:1:20;
var={'Welf'};
figure
for jj=1:length(var)
subplot(1,2,jj)
eval(['IRF_1.' var{1,jj},ending_cell{1,ii}]);
eval(['IRF_2.' var{1,jj},ending_cell{1,ii}]);
load IRF_2
end
end

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Tue Jun 02, 2015 6:04 pm
by Zeinab
he doen't work with me at all ! could you help me please

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Wed Jun 03, 2015 11:21 am
by jpfeifer
You must either load the first mat-file after the second call to Dynare or invoke the second call to Dynare with the
Code: Select all
noclearall

option. Otherwise, everything you do before
Code: Select all
dynare Flexible_2.mod

will be deleted.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Fri Jul 24, 2015 5:37 am
by medad
Hi all

Please hint me in this code:
Code: Select all
    dynare dr.mod
    load('dr_results.mat', 'oo_')
    irf1=oo_.irfs;
    save irf_1
    load irf_1


    dynare rd.mod noclearall
    load('rd_results.mat', 'oo_')
    irf2=oo_.irfs;
    save irf_2
    load irf_2
   
    ending_cell={'_epsr'};

    for ii=1:length(ending_cell)
HOR=1:1:40;
var={'y','paii','gam'};
figure

for jj=1:length(var)
subplot(1,2,jj)
eval(['irf1.' var{1,jj},ending_cell{1,ii}]);
eval(['irf2.' var{1,jj},ending_cell{1,ii}]);
hold on
plot(HOR,[eval(['irf1.' var{1,jj},ending_cell{1,ii}])],'LineWidth',1,'-k',HOR,[eval(['irf2.' var{1,jj},ending_cell{1,ii}])],'LineWidth',1,'--r')
title([var{1,jj}] )
end
end


with this Error:
Code: Select all
ERROR: Untitled.mod: line 18, col 4: syntax error, unexpected EQUAL


Thank you!
Best wishes...

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Fri Jul 24, 2015 8:02 am
by jpfeifer
This is a problem with the mod-file Untitled.mod. The code you pasted is Matlab code and not Dynare code. Run this directly from Matlab.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Fri Jul 24, 2015 9:09 am
by medad
Thank you very much, jpfeifer.
But after ruining all irf1 and irf2 separately, this error occurred again:

Code: Select all
Undefined variable "irf_1" or class "irf_1.y_epsr".


Thank you for your kindly reply.

Re: Q: combining IRFs into subplotted figures & iterating?

PostPosted: Fri Jul 24, 2015 12:08 pm
by jpfeifer
Be more careful. If you define
Code: Select all
irf1

you cannot save
Code: Select all
irf_1

Also, you need to load the files after the last call to Dynare, not after you saved them.