$title	Simple exchange model with iceberg trade costs


This is a static general equilibrium exchange model with costly trade
flows.  There are multiple regions with representative consumers.
There are multiple commodities.  Initial endowments of commodities,
e(g,r), are randomly distributed between zero and one.  Representative
agents in these regions share identical Cobb-Douglas preferences, U(c)
= prod(g, C(g)).

Regions are randomly (uniformly) situated on a square field.
Interregional distances are Euclidian.  When good g is exported from
region r to region rr, a fraction of the export is lost during
shipment.  The amount lost depends on the commodity's unit weight,
w(g), and the distance between regions r and rr, d(r,rr).  

This model is implemented as a nonlinear complementarity problem,
first as an algebraic model and then using MPSGE.

Thomas F. Rutherford
July, 2006


SETS	r	Regions /r1*r10/
	g	Goods	/g1*g10/;

ALIAS (r,rr);

PARAMETERS	d(r,rr)		Distance
		x(r)		X coordinate of region r
		y(r)		Y coordinate of region r
		w(g)		Weight (shipping cost)
		e(g,r)		Endowments
		phi(g,r,rr)	Iceberg output coefficient
		theta		Commodity value share;

*	Regional coordinates are randomly distributed:

x(r) = UNIFORM(0,1);
y(r) = UNIFORM(0,1);

*	Inter-regional distances are Euclidian:

d(r,rr) = SQRT(SQR(x(r)-x(rr)) + SQR(y(r)-y(rr)));

*	Initial endowments are uniformly distributed between 0 and 1:

e(g,r) = UNIFORM(0,1);

*	Commodity weights (transport costs) are indices between 0 and 1:

w(g) = UNIFORM(0,1);

*	Cobb-Douglas preferences with symmetric value shares:

theta = 1/CARD(g);

*	Iceberg output coefficient declines with distance and with
*	commodity weight:

phi(g,r,rr) = 1-(d(r,rr)/SQRT(2))*w(g);

VARIABLES	P(g,r)		Equilibrium price
		RA(r)		Representative agent income levels
		EXPORT(g,r,rr)	Bilateral exports;

EQUATIONS	MARKET(g,r)	Market clearance
		INCOME(r)	Income balance
		PROFIT(g,r,rr)	Zero profit;

*	Initial endowment plus imports to region r
*	equals final demand plus exports:

MARKET(g,r)..	e(g,r) + SUM(rr, phi(g,rr,r)*EXPORT(g,rr,r)) =e=
		theta*RA(r)/P(g,r) + SUM(rr, EXPORT(g,r,rr));

*	Income of the representative agent equals the value
*	of initial endowments:

INCOME(r)..	RA(r) =e= SUM(g, P(g,r)*e(g,r));

*	Free entry and perfect competition implies there are no
*	opportunities for arbitrage through trade.  The cost of 
*	buying one unit of good g in region r can be no less
*	than the delivered value of that good in any other region
*	rr.  


		P(g,r) =g= phi(g,r,rr) * P(g,rr);

*	We omit trade flows from region r to itself.  Fixing a 
*	variable in the complementarity framework drops the associated
*	equation:

EXPORT.FX(g,r,r) = 0;

*	Declare this model as a complementarity problem, associating
*	equations with variables:


*	Provide an initial estimate of equilibrium prices to help the
*	solver.  If we don't do this, the solver is initiated at a 
*	default point with all values equal to zero which creates 
*	problems because the functions cannot be evaluated:

P.L(g,r) = 1;
RA.L(r) = SUM(g, e(g,r));
EXPORT.L(g,r,rr) = 0;

*	Normalize prices by fixing the income level of one of the
*	regions:

RA.FX(r)$(ORD(r)=1) = RA.L(r);

*	Solve the model:

solve icebergmcp using mcp;

*	Save the MCP equilibrium values for comparison:

PARAMETER	equilibrium	Equilibrium values;
equilibrium(g,r,"P") = P.L(g,r);
equilibrium(g,r,rr) = EXPORT.L(g,r,rr);

*	Set up the same model using the MPSGE tabular format:


*	Declare variables according to their interpretation in the
*	economic equilibrium model:


*	Unlike the algebraic model, MPSGE requires that we explicitly
*	omit commodities which are not in the model.  This is done
*	using the GAMS exception operator, $:

	EXPORT(g,r,rr)$(not SAMEAS(r,rr))	! Export of good i from r to rr

	P(g,r)		! Commodity prices

	RA(r)		! Representative agents

*	Declare a "production" activity which removes one unit
*	of good g from the region r market and delivers phi(g,r,rr)
*	units to the corresponding region rr market:

$prod:EXPORT(g,r,rr)$(not sameas(r,rr))
	o:P(g,rr)	q:phi(g,r,rr)
	i:P(g,r)	q:1

*	Declare final demand assuming Cobb-Douglas preferences:

$demand:RA(r)  s:1
	d:P(g,r)	q:1
	e:P(g,r)	q:e(g,r)

$sysinclude mpsgeset icebergmge

*	Assign default value for exports:

EXPORT.FX(g,r,r) = 0;

*	Generate and solve the model:

$include icebergmge.gen
solve icebergmge using mcp;

parameter	dev	Deviation between MCP and MGE solutions;
dev =	sum((g,r), abs(P.L(g,r)-equilibrium(g,r,"P"))) +
	sum((g,r,rr), abs(EXPORT.L(g,r,rr)-equilibrium(g,r,rr)));
display dev;

*	It is often insightful to draw a little picture illustrating 
*	the equilibrium structure of a spatial model.  I like to do 
*	this sort of thing using Latex because it is familar.  The 
*	appropriate visual tool depends on experience.  For me, GNUPLOT 
*	would be another alternative.

*	The code shown below produces network.pdf.

*	Begin by writing the output file "header" using the GAMS
*	$onecho facility.  This simply copies the text lines between
*	"$onecho" and "$offecho" to a file named "network.tex":

$onecho >network.tex 
\caption{Initial Endowments and Equilibrium Trade Flows}

*	After having written the header, we then open the same file
*	in append mode (.ap=1), with variable width numeric output 
*	(.nw=0) and two decimals in numeric output (.nw=2):

file ktex /network.tex/; put ktex; ktex.nw=0; ktex.nd=2; ktex.ap=1; 


*	Generate a multi-picture figure.  This will fit on a 
*	single page, with one picture per commodity:

	if (ord(g)<>1, put '\hfill'/;);
	put '\begin{minipage}[t]{.45\textwidth}'/;
	put '\begin{center}'/;
 	put '\begin{picture}(1.25,1.5)'/;

*	Label each picture with the commodity weight, the 
*	determinant of transport cost (heavy goods are more 
*	costly to transport):

	put '\put(0.7,1.05){w=',w(g),'}'/;
	put '\put(0.1,-.1){Commodity ',g.tl,'}'/;

*	Center a circle at each regional location.  Make these circle
*	of a size proportional to regional initial endowments (bigger
*	circles imply larger initial endowments):

	loop(r,put '\put(',(x(r)),',',(y(r)),'){\circle{',(0.3*e(g,r)),'}}'/;);

*	Draw a dotted line indicating the boundary of the square field
*	containing the randomly situated regions:

	put '\dottedline[.]{0.05}(0,0)(1,0)(1,1)(0,1)(0,0)'/;

*	Draw lines which portray positive equilibrium trade flows for
*	the associated commodity.  The diagram reveals that 

*		(i) Trade flows take place between big circles
*		(regions with abundant initial endowments) and small 
*		circles (regions with less abundant endowments).

*		(ii) There is more trade for commodities which are
*		less costly to trade.

		put '\drawline(',x(r),',',y(r),')(',x(rr),','y(rr),')'/;
	put '\end{picture}'/;
	put '\end{center}'/;
	put '\end{minipage}'/;
put '\end{figure}'/;
put '\end{document}'/;