* This file contains the autarky version of the specific factors model, as described in Chapter 9 of Gilbert and Tower (2009).
* Contact: jgilbert@usu.edu or tower@econ.duke.edu.

* Define the indexes for the problem

SET I Goods /1,2/;
SET J Factors /K,L,N/;
ALIAS (J, JJ);

* Create names for parameters

PARAMETERS
ALPHA 		Shift parameter in utility
BETA(I) 	Share parameter in utility
PO(I) 		Prices
UO 		Initial utility level
CO(I) 		Initial consumption levels
GAMMA(I) 	Shift parameter in production
DELTA(J,I) 	Share parameter in production
RHO(I) 		Elasticity parameter in production
FBAR(J) 	Endowments
QO(I) 		Output level
RO(J) 		Factor prices
FO(J,I) 	Initial factor use levels
GDPO 		Initial gross domestic product;

* Assign values to the parameters

PO(I)=1;
RO(J)=1;
QO(I)=100;
CO(I)=QO(I);
FO('L','1')=20;
FO('L','2')=80;
FO('K','1')=(QO('1')*P('1')-FO('L','1')*RO('L'))/RO('K');
FO('N','2')=(QO('2')*P('2')-FO('L','2')*RO('L'))/RO('N');
FBAR(J)=SUM(I, FO(J,I));
GDPO=SUM(I, PO(I)*QO(I));
RHO(I)=0.1;
DELTA(J,I)$FO(J,I)=(RO(J)/FO(J,I)**(RHO(I)-1))/(SUM(JJ$FO(JJ,I), RO(JJ)/FO(JJ,I)**(RHO(I)-1)));
GAMMA(I)=QO(I)/(SUM(J$FO(J,I), DELTA(J,I)*FO(J,I)**RHO(I)))**(1/RHO(I));
UO=GDPO;
BETA(I)=CO(I)/GDPO;
ALPHA=UO/PROD(I, CO(I)**BETA(I));

* Create names for variables

VARIABLES
U		Utility index
P(I) 		Prices
C(I) 		Consumption
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

U.L=UO;
P.L(I)=PO(I);
C.L(I)=CO(I);
Q.L(I)=QO(I);
R.L(J)=RO(J);
F.L(J,I)=FO(J,I);
GDP.L=GDPO;
P.LO(I)=0;
C.LO(I)=0;
Q.LO(I)=0;
R.LO(J)=0;
F.LO(J,I)=0;
GDP.LO=0;

* Fix the value of one price to serve as a numeraire

P.FX('1')=1;

* Create names for equations

EQUATIONS
UTILITY 	Utility function
DEMAND(I) 	Demand functions
MAT_BAL(I)	Market closure
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

UTILITY..U=E=ALPHA*PROD(I, C(I)**BETA(I));
DEMAND(I)..C(I)=E=BETA(I)*GDP/P(I);
MAT_BAL(I)..C(I)=E=Q(I);
PRODUCTION(I)..Q(I)=E=GAMMA(I)*SUM(J$FO(J,I), DELTA(J,I)*F(J,I)**RHO(I))**(1/RHO(I));
RESOURCE(J)..FBAR(J)=E=SUM(I, F(J,I));
FDEMAND(J,I)$FO(J,I)..R(J)=E=P(I)*Q(I)*SUM(JJ$FO(JJ,I), 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));

* Define the equations that make the model, and solve

MODEL AUTARKY /ALL/;
SOLVE AUTARKY USING NLP MAXIMIZING U;
