Help with loop

Problems with syntax of GAMS
Post Reply
frds17
User
User
Posts: 22
Joined: 4 years ago

Help with loop

Post by frds17 »

Hi all,

I need to write a loop to solve the equations below.

Code: Select all

utility(ii,t)$(ord(t) le card(a)-1).. u=e=(1/(1-1/gamma))*sum(a,ss(a)*((1+beta(ii))**(1-ord(a)))*(1-1/gamma)*log((c(ii,a,t)**(1-1/rho)+alpha*l(ii,a,t)**(1-1/rho))**(1/(1-1/rho))));

asset(ii,a,t).. as(ii,a,t)=e=(1+r)*as(ii,a-1,t-1)+w(t)*e(ii,a)*(1-l(ii,a,t))+AP(ii,a,t)+NSB(ii,a,t)+SP(ii,a,t)-Tax(ii,a,t)-(1+tau_c)*c(ii,a,t);

income_test(ii,a,t).. API(ii,a,t)=e=max{min{p,p-theta*(inc(iii,a,t)-IT)},0}$(ord(a) ge 45);

solve model /all/;
solve model using dnlp maximizing u;
I am able to loop ii by creating a dynamic set

Code: Select all

iii(ii) /1*3/ *dynamic set for ii,
 iii(ii)=no; 
 loop(ii,
 iii(ii)=yes;
 *solve statement
 );
However, as set t and a have orders and lags I am getting errors if I try to write a dynamic set and to turn it off by tt(t)=no;

I need to solve the model by

Code: Select all

loop(t,
loop(ii,
);
);
Thanks for all the support you can give me.
Fabio
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Help with loop

Post by Renger »

Hi Fabio
If you use t as a loop you run into problems as you have t-1. In that case, you should remove this variable with index t-1 and replace it by a parameter that is given a value after the solve of the previous loop:
Here a small example:

Code: Select all

 K(t) =E= K(t-1) + I(t);
becomes

Code: Select all

* Start value for kprev in year 0
kprev = 10;
equations..
...
	K(t) =E= kprev + I(t);
loop(t, 
     solve mymodel;
     kprev = K.L(t);        
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
frds17
User
User
Posts: 22
Joined: 4 years ago

Re: Help with loop

Post by frds17 »

Hi Renger,

Thanks for your reply.

Fabio
Post Reply