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)+tihYH+tiEntYENT+transfrGRow0EXR;
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.1 KB) samjuly20201211.xlsx (44.9 KB)
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.
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);
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)+tihYH+tiEntYENT+transfrGRow0EXR;
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.
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
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.404883820662826QINTA(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?
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.
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
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.6 KB)
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)
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;)
Your first question is basically, “Why do I have to match variables and equations in MCP?” Essentially, the bounds you set on the variables and the matching you choose between variables and equations influences the set of solutions for the MCP model. If you choose one matching, you get one solution. If you choose a different matching, you may get a different solution. These choices are one part of the model-building process.
A quick example is this: assume you have a production level x and a marginal revenue function f(*) (f depends on x and perhaps several other variables). You want to match f and x in the model statement:
model m / f.x, blah.u, blahblah.v, … /;
If f is zero, you satisfy the solution criteria for the pair f.x. But what if you have a contractual obligation to run at a nonzero production level, say L? Then you set x.lo = L. If the optimal production level (marginal revenue equals 0) occurs with x > L, this is still a solution. But what if the optimal production level is less than L? If we use the negative of the marginal revenue function for f, then our pair f.x will push the value of x at a solution up to L, where f will be positive (assuming some nice things about the marginal revenue function).
The interaction of matched variables and equations, and the bounds on these variables (zero or nonzero) are at the heart of MCP modeling. This is what makes the MCP framework powerfully useful.
For a full description of what a solution to an MCP model is and how variable bounds and equ/var matching influence this see the GAMS User Guide:
Dear Steve,
Thank you for your explaination. I really appreciate it. I had download the gms program and I will study the MCP and NLP portion in the User Guide .
Thanks a lot.
Regards,
Douglas