Skip to content

Instantly share code, notes, and snippets.

@trialsolution
Created June 3, 2014 10:18
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/a5515ce2faf92debf0e8 to your computer and use it in GitHub Desktop.
Save trialsolution/a5515ce2faf92debf0e8 to your computer and use it in GitHub Desktop.
Calibrate the small country HOS model to nonzero trade (Chapter 12, exercise 3 in Gilbert-Tower book)
*
* --- Small country trading equilibrium
*
* Reasons for trade in the single country HO model
* Differences in good and factor prices and factor intensities
*
*
* --- The code builds on the small country example of Gilbert and Tower, link:
* http://ideas.repec.org/c/uth/gt2013/2012-14.html
*
$offlisting
* Define the indexes for the problem
SET I Goods /1,2/;
alias(i,ii);
SET J Factors /K,L/;
ALIAS (J, JJ);
* Create names for parameters
PARAMETERS
ALPHA Shift parameters in utility
BETA(I) Share parameters in utility
P(I) Prices
UO Initial utility level
CO(I) Initial consumption levels
XO(I) Initial trade levels
GAMMA(I) Shift parameters in production
DELTA(J,I) Share parameters in production
RHO(I) Elasticity parameters in production
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;
* Assign values to the parameters
* output prices
P(I)=1;
* factor prices
RO(J)=1;
* quantity balances
QO(I)=100;
* no trade in benchmark
CO(I)=QO(I);
XO(I)=QO(I)-CO(I);
* factor use in benchmark
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));
display "factor use and endowmnets in the benchmark", fo, fbar;
* value of domestic output
GDPO=SUM(I, P(I)*QO(I));
* calibration of the supply function
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));
* budget constraint for the consumers (= tot. output)
UO=GDPO;
* calibration of the demand function
BETA(I)=CO(I)/GDPO;
ALPHA=UO/PROD(I, CO(I)**BETA(I));
* Create names for variables
VARIABLES
u Utility index
x(I) Trade levels
c(I) Consumption levels
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;
X.L(I)=XO(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;
C.LO(I)=0;
Q.LO(I)=0;
R.LO(J)=0;
F.LO(J,I)=0;
GDP.LO=0;
* 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
* Cobb-Douglas utility function
UTILITY..U=E=ALPHA*PROD(I, C(I)**BETA(I));
* FOC of utility max. (consumer demand)
DEMAND(I)..C(I)=E=BETA(I)*GDP/P(I);
* market clearing for open economy (X is net trade)
MAT_BAL(I)..X(I)=E=Q(I)-C(I);
* FOC for the profit maximization (supply)
PRODUCTION(I)..Q(I)=E=GAMMA(I)*SUM(J, DELTA(J,I)*F(J,I)**RHO(I))**(1/RHO(I));
* simple resource constraint
RESOURCE(J)..FBAR(J)=E=SUM(I, F(J,I));
* FOC for the factor demands (underlying is a CES production function)
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);
* budget constraint defined by optimal output (q)
INCOME..GDP=E=SUM(I, P(I)*Q(I));
model HOS "small country trading equilibirium HOS" /
* "supply function"
production.q
* "factor demand"
fdemand.f
* "resource constraint --> factor prices"
resource.r
* "market clearing --> net trade"
mat_bal.x
* "demand equation (utility maximizing agent)"
demand.c
* "max. attainable GDP", links the profit max. problem to the consumers' decision problem
income.gdp
* "consumers' utility" (in the MCP formulation it becomes a reporting equation, i.e. could be left out of the model)
utility.u
/;
*===================================================================================
* CALIBRATION TEST, i.e. solve the calibrated model on the benchmark data set
*===================================================================================
* HOS.solprint = 0;
solve HOS using MCP
*
* --- Check benchmark
*
parameter FACTOR_INTENSITY(j,i) "factor intensities";
FACTOR_INTENSITY("K",i) = f.l("K",i) / f.l("L",i);
FACTOR_INTENSITY("L",i) = f.l("L",i) / f.l("K",i);
display FACTOR_INTENSITY;
$ontext
---- 193 PARAMETER FACTOR_INTENSITY factor intensities
1 2
K 4.000 0.250
L 0.250 4.000
* good 1 is more capital intensive while good 2 is more labour intensive
$offtext
*
* --- General definition of factor abundancy:
* "Country A is labour-abundant relative to
* country B if the wage to interest ratio in country A
* is lower than in country B"
*
* In our benchmark the factor prices are set to be equal (=> a factor price ratio of one)
* The factor abundance defines the shape of the PPF. In our case it's symmetric.
parameter FACTOR_PRICE_RATIO(*);
FACTOR_PRICE_RATIO("K/L") = r.l("K") / r.l("L");
display FACTOR_PRICE_RATIO;
*
* --- Let's see if we can calibrate the model to an equilibrium
* where trade is already happening
*
* introduce price difference
p("1") = 1.1;
* according to Stolper-Samuelson, as good 1 is captial intensive, the price of capital goes up...
ro("K") = 1.1;
* ... the country will specialize in producing good 1 ...
*qo("1") = 105;
* ... and the consumption shifts toward the relatively cheaper good 2
co("1") = 95;
co("2") = 105;
* net exports close the material balances
XO(I)=QO(I)-CO(I);
* recalculate factor use based on the above relative prices and output:
FO('K',I)=(QO(I)*P(I)-FO('L',I)*RO('L'))/RO('K');
FBAR(J)=SUM(I, FO(J,I));
display "factor use and endowmnets in the benchmark", fo, fbar;
* re-calculate GDP
GDPO=SUM(I, P(I)*QO(I));
* now let's recalibrate supply and demand:
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));
* budget constraint for the consumers (= tot. output)
UO=GDPO;
* calibration of the demand function
BETA(I)=CO(I) * p(i) / GDPO;
U.L=UO;
X.L(I)=XO(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;
C.LO(I)=0;
Q.LO(I)=0;
R.LO(J)=0;
F.LO(J,I)=0;
GDP.LO=0;
* calibration test:
solve HOS using MCP
$exit
*
* --- The resulting model is calibrated to non-zero initial trade levels (exporting good1, importing good2)
* Exogenous relative prices (both goods and factor prices) are preserved
* Factor use adjust to current relative prices
UTILITY Utility function
LOWER LEVEL UPPER MARGINAL
---- VAR u -INF 197.5957 +INF .
u Utility index
---- VAR x Trade levels
LOWER LEVEL UPPER MARGINAL
1 -INF 5.0000 +INF .
2 -INF -5.0000 +INF .
---- VAR c Consumption levels
LOWER LEVEL UPPER MARGINAL
1 . 95.0000 +INF .
2 . 105.0000 +INF .
---- VAR q Output levels
LOWER LEVEL UPPER MARGINAL
1 . 100.0000 +INF .
2 . 100.0000 +INF .
---- VAR r Factor prices
LOWER LEVEL UPPER MARGINAL
K . 1.1000 +INF .
L . 1.0000 +INF .
---- VAR f Factor use levels
LOWER LEVEL UPPER MARGINAL
K.1 . 81.8182 +INF .
K.2 . 18.1818 +INF .
L.1 . 20.0000 +INF .
L.2 . 80.0000 +INF .
LOWER LEVEL UPPER MARGINAL
---- VAR gdp . 210.0000 +INF .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment