Dear all,
I am working on the CGE model. I don't finish the whole model yet. Up to this stage, I have written the equations and I fix all the variables to check all the equations. I encounter two questions:
(1) some equation showed "infes", but the value is very small. For example, 0.002 or 1*E5. Can I ignore it? The model will work?
(2) All the equations seem okay, except for the yield of government. I am trying to solve the problem, but in vain.:
YG=e=sum[a,rateindir(a)*PVA(a)*QVA(a)+PINTA(a)*QINTA(a))]+sum(c,tm(c)*pwm(c)*QM(c)*EXR)+tih*YH+tiEnt*YENT+transfrGRow0*EXR;
the result is:
...... 872*YENT + YG =E= 0 ;
(LHS = 116770.535426369, INFES = 116770.535426369 ****)
On the equation above, I set:
QVA(a): value added , such as labor
QINTA(a): intermediate input
rateindir(a): is indirect tax, I assume it is some percentage of value added plus intermediate.
second term is importing tax: sum(c,tm(c)*pwm(c)*QM(c)*EXR)
third term is direct tax of household
forth term is direct tax of enterprise
fifth term is transfer form Rest of World
I try to replace the different expression way of each term many days, but the problem is still existing.
I appreciate any help.
Thanks and regards,
Douglas
EXIT CODE =3 , the equation is infes
Re: EXIT CODE =3 , the equation is infes
Hi
As you don't seem to scale the model 1E5 is negligible. However, not that convergence will probably only to this level.
Some notes to your model:
 You don't have to fix the variables to check the model. The better and more efficient way is to set the iteration limit to zero (cge.iterlim = 0) and check the infeasibilitites. If you calibrated correctly, the solver finds the solution before it starts running and there will be no (or very, very small) infeasibilities.
 If you do this, you will get a message that many variables aren't matched by equations. I had a quick look and the model looks a little bit like the ifpri model (you will find the documentation and the model here. Take a good look at the IFPRI model. The model definition does nicely map equations to variables. This is something you should do too to get more information on what is going wrong. (prices <=> market clearing, quantities zero <=> profit conditions, definitions <=> variable that is defined).
 Make your model more readable. You haven't added descriptions to variables and equations, so it is hard to easily read your code (e.g. PA(a) Armingtion Price, PD(a) Domestic price).
 Add CheckDate at the end to your gdxxrw command. gdx will then check if the excel file changed. If not, it will leave out the timeconsuming import and use the already existing gdx file.
Cheers
Renger
PS. Please do not double post.
As you don't seem to scale the model 1E5 is negligible. However, not that convergence will probably only to this level.
Some notes to your model:
 You don't have to fix the variables to check the model. The better and more efficient way is to set the iteration limit to zero (cge.iterlim = 0) and check the infeasibilitites. If you calibrated correctly, the solver finds the solution before it starts running and there will be no (or very, very small) infeasibilities.
 If you do this, you will get a message that many variables aren't matched by equations. I had a quick look and the model looks a little bit like the ifpri model (you will find the documentation and the model here. Take a good look at the IFPRI model. The model definition does nicely map equations to variables. This is something you should do too to get more information on what is going wrong. (prices <=> market clearing, quantities zero <=> profit conditions, definitions <=> variable that is defined).
 Make your model more readable. You haven't added descriptions to variables and equations, so it is hard to easily read your code (e.g. PA(a) Armingtion Price, PD(a) Domestic price).
 Add CheckDate at the end to your gdxxrw command. gdx will then check if the excel file changed. If not, it will leave out the timeconsuming import and use the already existing gdx file.
Cheers
Renger
PS. Please do not double post.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: EXIT CODE =3 , the equation is infes
Dear Renger,
I use the command cge.iterlim you suggested to check the Infeasible.
The equation changed from no problem to Infeasible, but I think the equation is simple and shouldn't have the problem. Could you please help with thanks.
(page 26, the ifpri model you mentioned, intermediate demand for commodity C from activity A)
QINTfn(c,a)..
QINT(c,a)=e=ica(c,a)*QINTA(a);
QINTfn(comagr,secagr)..  0.404883820662826*QINTA(secagr) + QINT(comagr,secagr)
=E= 0 ; (LHS = 14656.9114743557, INFES = 14656.9114743557 ****)
Regards,
Douglas
I use the command cge.iterlim you suggested to check the Infeasible.
The equation changed from no problem to Infeasible, but I think the equation is simple and shouldn't have the problem. Could you please help with thanks.
(page 26, the ifpri model you mentioned, intermediate demand for commodity C from activity A)
QINTfn(c,a)..
QINT(c,a)=e=ica(c,a)*QINTA(a);
QINTfn(comagr,secagr)..  0.404883820662826*QINTA(secagr) + QINT(comagr,secagr)
=E= 0 ; (LHS = 14656.9114743557, INFES = 14656.9114743557 ****)
Regards,
Douglas
Re: EXIT CODE =3 , the equation is infes
Hi Douglas
If I run your model, I get:
so no infeasibilities here. The first infeasibility is in Ygeq. Here you should check the values against your SAM, e.g. define a parameter to see which values go into the equation like this:
sum[a,rateindir(a)*(PVA(a)*QVA(a)+PINTA(a)*QINTA(a))]+sum(c,tm(c)*pwm(c)*QM(c)*EXR)+tih*YH+tiEnt*YENT+transfrGRow0*EXR;
You will then probably find that you have forgotten to initialize a variable, or used wrong values.
The trick to use iterlim = 0 and a correct formulation of your model (with the linked variables as I wrote) makes it easy to spot the infeasibilities as it shows this in the listing as the marginals of the variables. At the moment, even if you solve the infeasibility, you still have the problem of unmatched variables. Try to see how this works, if you run the IFPRI model and add an infeasibility by just adding a number to one of the equations.
If I run your model, I get:
Code: Select all
 QINTfn =E=
QINTfn(comagr,secagr)..  0.404883820662826*QINTA(secagr) + QINT(comagr,secagr) =E= 0 ;
(LHS = 0)
QINTfn(comagr,seccoa).. QINT(comagr,seccoa) =E= 0 ; (LHS = 0)
QINTfn(comagr,secfoo)..  0.462571849766541*QINTA(secfoo) + QINT(comagr,secfoo) =E= 0 ;
(LHS = 0)
sum[a,rateindir(a)*(PVA(a)*QVA(a)+PINTA(a)*QINTA(a))]+sum(c,tm(c)*pwm(c)*QM(c)*EXR)+tih*YH+tiEnt*YENT+transfrGRow0*EXR;
Code: Select all
parameter check_eq(*);
check_eq("rateinindir") = sum[a,rateindir(a)*(PVA.L(a)*QVA.L(a)+PINTA.L(a)*QINTA.L(a))];
check_eq("tarifs") = sum(c,tm(c)*pwm(c)*QM.L(c)*EXR.L);
etc.
The trick to use iterlim = 0 and a correct formulation of your model (with the linked variables as I wrote) makes it easy to spot the infeasibilities as it shows this in the listing as the marginals of the variables. At the moment, even if you solve the infeasibility, you still have the problem of unmatched variables. Try to see how this works, if you run the IFPRI model and add an infeasibility by just adding a number to one of the equations.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: EXIT CODE =3 , the equation is infes
Dear Renger,
Thanks for the reply. I will try it. I will be very happy if I can solve the infeasible problem even though another problem will be encountered soon.
Thanks.
Douglas
Thanks for the reply. I will try it. I will be very happy if I can solve the infeasible problem even though another problem will be encountered soon.
Thanks.
Douglas

 User
 Posts: 21
 Joined: 2 months ago
Re: EXIT CODE =3 , the equation is infes
Dear Renger,
I am sorry to ask the same question again.
Please find the file which named *1212.gms attached. In this file, I add the cge.iterlim=0 and find:
 QINTfn =E=
QINTfn(comagr,secagr)..  0.404883820662826*QINTA(secagr) + QINT(comagr,secagr)
=E= 0 ; (LHS = 14656.9114743557, INFES = 14656.9114743557 ****)
As mentioned on last post, there is no infeasible problem, if I set all the variable *.fx to find the benchmark. I don't know what happened.
The second question is can I find more examples of using linked variables you mentioned in your last post in some other places, like user guide? As a beginner, it is hard to catch it.
Thank you very much.
Douglas
PS. Do you have any lesson on Udemy or Open Courses?
I am sorry to ask the same question again.
Please find the file which named *1212.gms attached. In this file, I add the cge.iterlim=0 and find:
 QINTfn =E=
QINTfn(comagr,secagr)..  0.404883820662826*QINTA(secagr) + QINT(comagr,secagr)
=E= 0 ; (LHS = 14656.9114743557, INFES = 14656.9114743557 ****)
As mentioned on last post, there is no infeasible problem, if I set all the variable *.fx to find the benchmark. I don't know what happened.
The second question is can I find more examples of using linked variables you mentioned in your last post in some other places, like user guide? As a beginner, it is hard to catch it.
Thank you very much.
Douglas
PS. Do you have any lesson on Udemy or Open Courses?
Re: EXIT CODE =3 , the equation is infes
Hi Douglas
If you don't have an infeasible problem when you fix all variables, then there is a mismatch between your initializated (.L) and your fixed values (.fx). You probably forgot to initialize some of the variables. (if you replace the .fx in your code by .l, you will see that the only infeasibility left is the government equation.
For this equation, you should try to find out, if you initialized all the variables correctly as I described in my previous post.
You could have a look a the following:
 Path solver guide (in the Gams documentation),
 The documentation of the IFPRI model
 The book on CGE model by Hosoe.
 Attached is an essay I wrote as part of my thesis with an introduction into MCP.
Cheers
Renger
If you don't have an infeasible problem when you fix all variables, then there is a mismatch between your initializated (.L) and your fixed values (.fx). You probably forgot to initialize some of the variables. (if you replace the .fx in your code by .l, you will see that the only infeasibility left is the government equation.
For this equation, you should try to find out, if you initialized all the variables correctly as I described in my previous post.
You could have a look a the following:
 Path solver guide (in the Gams documentation),
 The documentation of the IFPRI model
 The book on CGE model by Hosoe.
 Attached is an essay I wrote as part of my thesis with an introduction into MCP.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist

 User
 Posts: 21
 Joined: 2 months ago
Re: EXIT CODE =3 , the equation is infes
Dear Renger,
Thank you for your patience. Fixing the variable to check the feasibility is the method in the Appendix in Horse's book.
I will study the materials you provide.
Thanks again.
Regards,
Douglas
Thank you for your patience. Fixing the variable to check the feasibility is the method in the Appendix in Horse's book.
I will study the materials you provide.
Thanks again.
Regards,
Douglas

 User
 Posts: 21
 Joined: 2 months ago
Re: EXIT CODE =3 , the equation is infes
Dear Renger,
My problems were solved! Thanks for all your help!
I still have two questions:
(1) After removing the lower bound, the problem solved. The unmatched variables disappeared. I really wondering why? It took very a lot of time.
In order to avoid dividing by zero, I followed the instruction in Hosoe's book and set all the variables bigger than zero:
PA.lo(a)=0.00001;
The program did not work. (all the variables unmatched!) I check the input initial value you mentioned again and again, but in vain. I almost gave up. This morning, I did my last try and delete all the lower bound. It is amazing. The program work.
My question is: I think the "lower bound" set is reasonable. Why did it cause unmatched problems? I think it is important for many users.
(2) How to simulate the "investment"?
In my original setting, the investment is fixed (exogeneous):
Quantities for each commodity "c" is: (the original value is from SAM)
QINV(c) = sam (c, 'invsav')/PQ0(c);
equation:
EINVeq..
EINV=e=sum(c,PQ(c)*QINV0(c));

I want to change each commodity "c" in the QINV0(C). How can I do? (I changed the data in the sam. Of course, It came back the original value)
My original closure conditions are:
WL.fx=1; ( Wage fixed)
QLSAGG.fx=QLSAGG0; (Total labor supply)
QKSAGG.fx=QKSAGG0; (Total Capital supply)
RowInv.fx=RowInv0; (Investment from overseas)

Question #2 is very important to me.
Thank you very much.
Regards,
Douglas
My problems were solved! Thanks for all your help!
I still have two questions:
(1) After removing the lower bound, the problem solved. The unmatched variables disappeared. I really wondering why? It took very a lot of time.
In order to avoid dividing by zero, I followed the instruction in Hosoe's book and set all the variables bigger than zero:
PA.lo(a)=0.00001;
The program did not work. (all the variables unmatched!) I check the input initial value you mentioned again and again, but in vain. I almost gave up. This morning, I did my last try and delete all the lower bound. It is amazing. The program work.
My question is: I think the "lower bound" set is reasonable. Why did it cause unmatched problems? I think it is important for many users.
(2) How to simulate the "investment"?
In my original setting, the investment is fixed (exogeneous):
Quantities for each commodity "c" is: (the original value is from SAM)
QINV(c) = sam (c, 'invsav')/PQ0(c);
equation:
EINVeq..
EINV=e=sum(c,PQ(c)*QINV0(c));

I want to change each commodity "c" in the QINV0(C). How can I do? (I changed the data in the sam. Of course, It came back the original value)
My original closure conditions are:
WL.fx=1; ( Wage fixed)
QLSAGG.fx=QLSAGG0; (Total labor supply)
QKSAGG.fx=QKSAGG0; (Total Capital supply)
RowInv.fx=RowInv0; (Investment from overseas)

Question #2 is very important to me.
Thank you very much.
Regards,
Douglas
Re: EXIT CODE =3 , the equation is infes
Hi Douglas
An MCP model assumes that either the equation binds (is zero) or if this is not the case the complementary variable should be zero. (if the zeroprofit condition is not met and there is a negative profit, the quantity produced should be zero).
If you bound a variable away from zero, the variable can't become zero anymore and the MCP condition is not possible.
With regard to your second question:
 For this you need to define the investment production function (investment goods from your SAM (QINV(c)) produce an investment good QINVT, which is demanded by the households.
 The utility function will now have an additional component QINVT as the household increases its utility if it invests. This means you need a market clearing function for your investment (something like QINVT=E= alpha * INC;)
Cheers
Renger
An MCP model assumes that either the equation binds (is zero) or if this is not the case the complementary variable should be zero. (if the zeroprofit condition is not met and there is a negative profit, the quantity produced should be zero).
If you bound a variable away from zero, the variable can't become zero anymore and the MCP condition is not possible.
With regard to your second question:
 For this you need to define the investment production function (investment goods from your SAM (QINV(c)) produce an investment good QINVT, which is demanded by the households.
 The utility function will now have an additional component QINVT as the household increases its utility if it invests. This means you need a market clearing function for your investment (something like QINVT=E= alpha * INC;)
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist