Skip to content

Instantly share code, notes, and snippets.

@trialsolution
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trialsolution/cd2ac7fae9d4ede70aec to your computer and use it in GitHub Desktop.
Save trialsolution/cd2ac7fae9d4ede70aec to your computer and use it in GitHub Desktop.
Howto draw a PPF using the GUSS solver option in GAMS
*
* Howto draw a PPF using the GUSS solver option in GAMS
*
* This file is an extension of
* the long-run production problem, as described in Chapter 5 of
* Gilbert and Tower: Introduction to Numerical Simulation for Trade Theory and Policy.
*
* for download of the original model go to
* http://ideas.repec.org/c/uth/gt2013/2012-03.html
*
$offlisting
SET I Goods /1,2/;
SET J Factors /K,L/;
ALIAS (J, JJ);
PARAMETERS
GAMMA(I) Shift parameters in production
DELTA(J,I) Share parameters in production
RHO(I) Elasticity parameters in production
P(I) Output prices
FBAR(J) Endowments
QO(I) Initial output levels
RO(J) Initial factor prices
FO(J,I) Initial factor use levels
GDPO Initial gross domestic product;
* starting values and calibration
P(I)=1;
RO(J)=1;
QO(I)=100;
FO('L','1')=20;
FO('L','2')=80;
FO('K',I)=(QO(I)*P(I)-FO('L',I)*RO('L'))/RO('K');
FBAR(J)=SUM(I, FO(J,I));
GDPO=SUM(I, P(I)*QO(I));
RHO(I)=0.1;
DELTA(J,I)=(RO(J)/FO(J,I)**(RHO(I)-1))/(SUM(JJ, RO(JJ)/FO(JJ,I)**(RHO(I)-1)));
GAMMA(I)=QO(I)/(SUM(J, DELTA(J,I)*FO(J,I)**RHO(I)))**(1/RHO(I));
* Create names for variables
VARIABLES
Q(I) Output levels
R(J) Factor prices
F(J,I) Factor use levels
GDP Gross domestic product;
* Assign initial values to variables, and set lower bounds
Q.L(I)=QO(I);
R.L(J)=RO(J);
F.L(J,I)=FO(J,I);
GDP.L=GDPO;
Q.LO(I)=0;
R.LO(J)=0;
F.LO(J,I)=0;
* Create names for equations
EQUATIONS
PRODUCTION(I) Production functions
RESOURCE(J) Resource constraints
FDEMAND(J,I) Factor demand functions
INCOME Gross domestic product;
* Assign the expressions to the equation names
PRODUCTION(I) .. Q(I)=E=GAMMA(I)*SUM(J, DELTA(J,I)*F(J,I)**RHO(I))**(1/RHO(I));
RESOURCE(J).. FBAR(J)=E=SUM(I, F(J,I));
FDEMAND(J,I).. R(J)=E=P(I)*Q(I)*SUM(JJ, DELTA(JJ,I)*F(JJ,I)**RHO(I))**(-1)*DELTA(J,I)*F(J,I)**(RHO(I)-1);
INCOME.. GDP=E=SUM(I, P(I)*Q(I));
* models for optimal producer behaviour
MODEL HOS /ALL/;
*SOLVE HOS USING NLP MAXIMIZING GDP;
model hos_mcp / production.q, resource.r, fdemand.f/;
solve hos_mcp using MCP;
*
* --- Draw the PPF
*
* find max. attainable q's
* by allocating all factors to one single industry
parameter q_max(i) 'max feasible production of the different goods';
q_max(i) = gamma(i) * sum(j, delta(j,i) * fbar(j)**rho(i)) ** (1/rho(i));
*
* --- Set up a model to draw PPF
*
variable output;
equation
tot_output "CES production function"
;
tot_output .. output =e= sum(i, q(i));
model ppf /production, resource, tot_output/;
*
* --- test the model in one of the corner solutions
*
q.fx("1") = q_max("1");
solve ppf using nlp maximizing output;
*
* --- Draw the PPF by varying the level of production for good 1
*
* number of trials
$setlocal n 100
set scen 'scenarios' /s1*s%n%/;
parameter
ps_q_lo(scen,i) "lower bounds for production in the SA"
ps_q_up(scen,i) "upper bounds for production in the SA"
ps_result_q(scen,i) "optimal q's"
;
set scen_dict "scenario dictionary for the GUSS solver option"
/
scen. scenario. ''
q . lower . ps_q_lo
q . upper . ps_q_up
q . level . ps_result_q
/;
ps_q_lo(scen,i) = 0;
ps_q_up(scen,i) = +inf;
* production of good 1 must be fixed in the SA
ps_q_lo(scen,"1") = [1/(%n% - 1) * (ord(scen) - 1)] * q_max('1');
ps_q_up(scen,"1") = [1/(%n% - 1) * (ord(scen) - 1)] * q_max('1');
ps_q_lo("s1","1") = eps;
ps_q_up("s1","1") = eps;
solve ppf using NLP maxizing output scenario scen_dict;
display ps_result_q;
*
* --- Prepare plot with GNUPLOT
*
*
* --- Put data points in a .dat file
*
file datafile /PPF.dat/;
put datafile;
loop(scen,
put ps_result_q(scen, "1"):10:2;
put ' ',ps_result_q(scen, "2"):10:2
put /;
);
putclose;
*
* --- Prepare GNUPLOT script
*
file pltfile /ppf.plt/;
put pltfile;
putclose
'set xlabel "q1"'/
'set ylabel "q2"'/
'set title "Production Possibilities Frontier"'/
'set key off'/
'set term png font arial 13'/
'set output "ppf.png"'/
'set arrow from ',gdp.l,',0 to 0,',gdp.l,' nohead'/
'plot "ppf.dat" using 1:2 with lines'
;
* sets and parameters for gnuplotxyz
$setlocal gnuplot_path 'S:\util\gnuplot\bin\'
* Use Gnuplot to generate picture
execute 'call %gnuplot_path%gnuplot ppf.plt';
* Use mspaint(Windows) to open image file
execute 'mspaint ppf.png';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment