EXIT CODE =3 , the equation is infes

Problems with syntax of GAMS
douglaskuo
User
User
Posts: 21
Joined: 2 months ago

EXIT CODE =3 , the equation is infes

Post by douglaskuo » 4 weeks ago

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*E-5. 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
HSRTWN20201211.gms
(25.07 KiB) Downloaded 12 times
samjuly20201211.xlsx
(44.94 KiB) Downloaded 14 times

User avatar
Renger
Posts: 633
Joined: 4 years ago

Re: EXIT CODE =3 , the equation is infes

Post by Renger » 4 weeks ago

Hi
As you don't seem to scale the model 1E-5 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 time-consuming 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

douglaskuo
User
User
Posts: 21
Joined: 2 months ago

Re: EXIT CODE =3 , the equation is infes

Post by douglaskuo » 4 weeks ago

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

User avatar
Renger
Posts: 633
Joined: 4 years ago

Re: EXIT CODE =3 , the equation is infes

Post by Renger » 3 weeks ago

Hi Douglas

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)
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;

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.
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.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

douglaskuo
User
User
Posts: 21
Joined: 2 months ago

Re: EXIT CODE =3 , the equation is infes

Post by douglaskuo » 3 weeks ago

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

douglaskuo
User
User
Posts: 21
Joined: 2 months ago

Re: EXIT CODE =3 , the equation is infes

Post by douglaskuo » 3 weeks ago

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?

HSRTWN20201222.gms
(25.12 KiB) Downloaded 11 times

User avatar
Renger
Posts: 633
Joined: 4 years ago

Re: EXIT CODE =3 , the equation is infes

Post by Renger » 3 weeks ago

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
intro.pdf
(589.2 KiB) Downloaded 14 times
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

douglaskuo
User
User
Posts: 21
Joined: 2 months ago

Re: EXIT CODE =3 , the equation is infes

Post by douglaskuo » 3 weeks ago

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

douglaskuo
User
User
Posts: 21
Joined: 2 months ago

Re: EXIT CODE =3 , the equation is infes

Post by douglaskuo » 3 weeks ago

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);
HSRTWN20201226.gms
(24.58 KiB) Downloaded 7 times
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
samjuly20201226R2.xlsx
(44.95 KiB) Downloaded 11 times

User avatar
Renger
Posts: 633
Joined: 4 years ago

Re: EXIT CODE =3 , the equation is infes

Post by Renger » 3 weeks ago

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 zero-profit 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

Post Reply