Q: combining IRFs into subplotted figures & iterating?

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.

Q: combining IRFs into subplotted figures & iterating?

Postby GOODLUCK » Wed Jan 08, 2014 1:21 pm

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
GOODLUCK
 
Posts: 16
Joined: Mon Dec 30, 2013 7:40 pm

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

Postby GOODLUCK » Wed Jan 08, 2014 4:11 pm

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
GOODLUCK
 
Posts: 16
Joined: Mon Dec 30, 2013 7:40 pm

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

Postby jpfeifer » Fri Jan 10, 2014 5:35 pm

You either need to load irf1 after the last call to Dynare or use the noclearall option.
------------
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: Q: combining IRFs into subplotted figures & iterating?

Postby GOODLUCK » Sun Jan 12, 2014 1:03 pm

Thank you very much, jpfeifer. I've done it.
GOODLUCK
 
Posts: 16
Joined: Mon Dec 30, 2013 7:40 pm

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

Postby yufeng » Mon Apr 14, 2014 11:57 am

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
yufeng
 
Posts: 9
Joined: Fri Nov 29, 2013 1:46 am

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

Postby lah89 » Sun May 25, 2014 5:31 pm

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.
lah89
 
Posts: 31
Joined: Tue Jan 28, 2014 1:54 pm

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

Postby Mylene » Thu Apr 02, 2015 3:02 am

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.
Mylene
 
Posts: 1
Joined: Thu Apr 02, 2015 2:31 am

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

Postby jpfeifer » Thu Apr 02, 2015 9:34 am

Please provide more information. Provide both the files and precise instructions on what you are trying to plot from the two mod-files.
------------
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: Q: combining IRFs into subplotted figures & iterating?

Postby Zeinab » Tue Jun 02, 2015 6:04 pm

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
Zeinab
 
Posts: 20
Joined: Sun Apr 26, 2015 8:05 am

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

Postby Zeinab » Tue Jun 02, 2015 6:04 pm

he doen't work with me at all ! could you help me please
Zeinab
 
Posts: 20
Joined: Sun Apr 26, 2015 8:05 am

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

Postby jpfeifer » Wed Jun 03, 2015 11:21 am

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.
------------
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: Q: combining IRFs into subplotted figures & iterating?

Postby medad » Fri Jul 24, 2015 5:37 am

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...
medad
 
Posts: 2
Joined: Mon Nov 24, 2014 8:22 am

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

Postby jpfeifer » Fri Jul 24, 2015 8:02 am

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.
------------
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: Q: combining IRFs into subplotted figures & iterating?

Postby medad » Fri Jul 24, 2015 9:09 am

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.
medad
 
Posts: 2
Joined: Mon Nov 24, 2014 8:22 am

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

Postby jpfeifer » Fri Jul 24, 2015 12:08 pm

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.
------------
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: No registered users and 4 guests

cron