Looping over parameters

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.

Looping over parameters

Postby mkulish » Tue Aug 25, 2009 5:03 am

Hi All,

I am trying to see how the correlations between some variables change as some parameters change. I've been able to loop with no problems over most parameters following the suggestion in http://www.dynare.org/DynareWiki/HowtoLoops

The same loop, however, does not seem to work over standard deviation parameters. Below is an example. sigeas is the standard deviation of the shock eas.

sigeas_values = 0:.005:.01;
T1 = length(sigeas_values);

corrR1s = zeros(T1,1);

for i1 = 1:T1
sigeas = sigeas_values(i1);
stoch_simul(irf=12,nograph) r r8 r20 r40 rs r8s r20s r40s;
corrR1s(i1,1) = oo_.var(1,5) / (sqrt(oo_.var(1,1))*sqrt(oo_.var(5,5)));
end

The code does not crash, in fact it runs but reports unchanged values for the correlations which should definitely change. Is there any difference in Dynare between looping over the standard deviation parameters as opposed to any other parameters?

Many thanks,
Mariano
mkulish
 
Posts: 10
Joined: Sat Aug 11, 2007 7:23 am

Re: Looping over parameters

Postby StephaneAdjemian » Tue Aug 25, 2009 1:22 pm

Hi,

Here is an example. Suppose we have three shocks:

Code: Select all

varexo epsilon_a, epsilon_b, epsilon_c;



initialized as follows:

Code: Select all

shocks;
  var epsilon_a  = 0.1 ;
  var epsilon_b  = 0.1 ;
  var epsilon_c  = 0.1 ;
end;



Dynare saves this information (the covariance matrix of the three shocks) in the global structure M_ (in the field called Sigma_e). In our example we have:

Code: Select all

M_.Sigma_e =

   0.1   0.0   0.0 
   0.0   0.2   0.0
   0.0   0.0   0.3



So if we want to change the variance of the second shock inside a loop, we just need to change the second element on the diagonal of M_.Sigma_e (the rows and columns of M_.Sigma_e are organized consistently with the order of declaration in the varexo statement).

In your example we would have something like:

Code: Select all

for i1 = 1:T1
    M_.Sigma_e(idx,idx) = sigeas_values(i1);
    stoch_simul(irf=12,nograph) r r8 r20 r40 rs r8s r20s r40s;
    corrR1s(i1,1) = oo_.var(1,5) / (sqrt(oo_.var(1,1))*sqrt(oo_.var(5,5)));
end



where the integer idx is the position of the shock sigeas (so idx=1 if sigeas is the first declared shock, idx=2 if sigeas is second declared shock, etc.).

Best, Stéphane.
Stéphane Adjemian
Université du Maine, GAINS and DynareTeam
https://stepan.adjemian.eu
StephaneAdjemian
 
Posts: 429
Joined: Wed Jan 05, 2005 4:24 pm
Location: Paris, France.

Re: Looping over parameters

Postby mkulish » Tue Aug 25, 2009 9:17 pm

Thank you Stephane for your quick and helpful reply!

Best,
Mariano
mkulish
 
Posts: 10
Joined: Sat Aug 11, 2007 7:23 am


Return to Dynare help

Who is online

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