how to use a loop statement into dynamic recursive model?

Problems with modeling
Post Reply
Rodrigue
User
User
Posts: 6
Joined: 7 months ago

how to use a loop statement into dynamic recursive model?

Post by Rodrigue » 4 months ago

Hello all

My problem is to use the loop statement in a dynamic recursive CGE model.
What I learnt from such a model is that it consists of building a dynamic model by looping over the same static model two things over two periods. That is saving firstly the benchmark data after each loop statement which should be used for simulation whose results are store for the next period and so on.

Now, how to program a time-loop is not a matter. What I don’t know is how to get GAMS to save the data results from the previous loop in order to use them for the next loop. (In my looping attempts I had the impression that GAMS uses the original benchmark data as starting point in each loop. consequently, the variation results at each period are the same).

This is an illustration of what I have done.

Set t time / 2016*2040 /
*some variables are
C(Tr,H), CI(J), D(TR), DI(TR, J), DIT(TR), EX(TR), INV(TR)
*parameters linked to those variables for storing the results are
C1(Tr, H, t), CI1(J,t), D1(TR, t), DI1(TR, J, t), DIT1(TR, t), EX(1TR, t), INV1(TR, t)
*in the model and solve statement i made this
Model megcdycam /all/;
Solve megcdycam using mcp;
*For dynamic recursive simulations I made this after the previous solve statement

Loop (t,
Solve megcdycam using mcp;

CI1(J,t) = CI.L(J) *(1 + pop)**(ord(t) - 1);
D1(TR,t) = D.L(TR) *(1 + pop)**(ord(t) - 1);
DIT1(TR,t) = DIT.L(TR) *(1 + pop)**(ord(t) - 1);
EX1(TR,t) = EX.L(TR) *(1 + pop)**(ord(t) - 1);
INV1(TR,t) = INV.L(TR) *(1 + pop)**(ord(t) - 1);
) ;

Can someone gives me a good way to overcome that?

Thank you in advance

Rodrigue

GabrielYin
User
User
Posts: 54
Joined: 9 months ago
Location: Dallas, TX, USA

Re: how to use a loop statement into dynamic recursive model?

Post by GabrielYin » 4 months ago

Hi Rodrigue,

To store/use values in each loop, I recommend two alternatives.

1. Define a global parameter to store the value and update it in each iteration. An illustrative example is shown below.

Code: Select all

Set    k  /1*100/;
Parameter    store(n);
store(n) = *something initial*;

loop(k,
  param(n) = store(n);
* param(n) is a parameter used in the model
  solve Model use ... min Obj;
* then use the solution in the next iteration, update it
  store(n) = x.l(n);
);
2. If you want to check all values in each iteration, you can still use the iteration index as an additional index of the parameter. I create a special sample for you, which has different action in first iteration and all hereafter iterations.

Code: Select all

Set    k  /1*100/;
Parameter    store(n, k);
store(n, '1') = *something initial*;

loop(k,
	if(ord(k)=1,
    	...
  	);
  	if(ord(k)>1,
    		param(n) = store(n, k-1);
    		solve Model use ... min Obj;
    		store(n, k) = x.l(n);
  	);
);
Hope it helps!

Cheers.
Gabriel

Rodrigue
User
User
Posts: 6
Joined: 7 months ago

Re: how to use a loop statement into dynamic recursive model?

Post by Rodrigue » 4 months ago

Thank you Gabriel for your reply. It's very interesting. I'm just going to apply it hoping the solution wil be found. Thanks again

Best regards
Rodrigue

Post Reply