loop starting from a specific time
Show older comments
I first had to calculate two time paths y_permanent and y_temporary, the codes are the following ones:
y_temporary=zeros(101,1);
psi=0.0001*randn(101,1);
y_temporary(1)=100;
for t=1:29
y_temporary(t+1)=y_temporary(t)*(a+0.0001*psi(t,1));
end
for t=30:32
y_temporary(t+1)=y_temporary(t)*(a-0.2);
end
for t=33:100
y_temporary(t+1)=y_temporary(t)*(a+0.0001*psi(t,1));
end
The path for the permanent change was:
y_permanent=zeros(100,1);
y_permanent(1)=100;
for t=1:100;
y_permanent(t+1)=y_permanent(t)*(1.01+0.0001*psi(t,1)); %alpha is now 1.01
end;
Now, my problem is, that I have to figure out a loop wich starts at time t=33 and stops, when the temporary shocks value is twice as high as the value of the permanent shock, counting the number of periods it needs to do so.
I tried several for loops, while loops and combination of a while and if loop but with no success.
If someone could give me a hint how to easily create such a loop, I would be so glad! I'm desperately looking for an answer.
Best Rico
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!