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 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,

Hi,

Here is an example. Suppose we have three shocks:

```
varexo epsilon_a, epsilon_b, epsilon_c;
```

initialized as follows:

```
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:

```
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:

```
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.

Thank you Stephane for your quick and helpful reply!

Best,