$title	An exchange model with endogenous provision of portering services

$ontext

This is a static general equilibrium exchange model with costly trade
flows.  There are multiple regions, each with a representative consumers.
There are multiple commodities.  Initial endowments of commodities,
e(g,r), are randomly distributed between zero and one.  

Representative agents in each of these regions are endowed with a
single unit of time which they may either devote to leisure or to the
provision of transportation services.  All agents share identical
Cobb-Douglas preferences over the consumption of goods, g, and 
leisure, L:

	U(c,L) = prod(g, C(g)) * L

Regions are randomly (uniformly) situated on a square field.
Interregional distances are Euclidian.  

Goods exported from region r to region rr rely on portering services
provided either by agents from region r or from region rr.  When a
porter carries a load from region r to region rr, he is assumed to be
available to carry a return load from rr to rr, although in
equilibrium there may be more porters on the trail from rr to r than
there are loads to be carried.

The number of porter-hours required for the transport of good g from r
to rr depends on commodity g'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 using
MPSGE.

$offtext

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

ALIAS (s,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);

set	t(s,r,rr)	Transportation routes;
t(s,r,rr) = yes$((ord(r) < ord(rr)) and (sameas(s,r) or sameas(s,rr)));

$ontext
$model:porters

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

$sectors:

*	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 g from r to rr
	PORTER(s,r,rr)$t(s,r,rr)		! Provision of transport services 

*	Note: PORTER(s,r,rr) represents porter services on the r-rr route 
*	provided by porters from region s. In this context s represents either 
*	r or rr  -- loads carried from r to rr are only carried by porters 
*	from r or rr.

$commodities:
	P(g,r)				! Commodity prices
	PL(r)				! Wage rate in region r
	PT(r,rr)$(not sameas(r,rr))	! Cost of transport from r to rr

$consumers:
	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:1
	i:P(g,r)	q:1
	i:PT(r,rr)	q:(1-phi(g,r,rr))

*	When a porter from s carries loads between r and rr, he provides
*	transport services in both directions:

$PROD:PORTER(s,r,rr)$t(s,r,rr)
	o:PT(r,rr)	q:1
	o:PT(rr,r)	q:1
	i:PL(s)		q:1

*	Final demand is Cobb-Douglas:

$demand:RA(r)  s:1
	d:P(g,r)	q:1
	d:PL(r)		q:1
	e:PL(r)		q:1		! Each region has a unit endowment of time
	e:P(g,r)	q:e(g,r)	! and a random endowment of commodities.

$report:
	v:welfare(r)	w:RA(r)		! Generate a welfare index

$offtext
$sysinclude mpsgeset porters

*	Generate and solve the model:

$include porters.gen
solve porters using mcp;

PORTER.L(s,r,rr)$(not t(s,r,rr)) = 0;
PT.L(r,r) = 0;

*	Report prices:

DISPLAY PT.L;

*	Report difference between supply and demand of portering
*	services:

PARAMETER	loads(r,rr)		Aggregate loads from r to rr,
		xssupply(r,rr)		Excess supply of portering services,
		deadheadpct(r,rr)	Porters without loads as a percent of porters on route;

loads(r,rr) = sum(g, EXPORT.L(g,r,rr)*(1-phi(g,r,rr)));
xssupply(r,rr) = round(sum(s, PORTER.L(s,r,rr)$t(s,r,rr) + PORTER.L(s,rr,r)$t(s,rr,r)) 
		- loads(r,rr) ,3);
deadheadpct(r,rr)$(xssupply(r,rr) + loads(r,rr))
	= round(100 * xssupply(r,rr) / (xssupply(r,rr) + loads(r,rr)));

option deadheadpct:0;
display xssupply, deadheadpct;

*	Produce a report of 

parameter	summary(r,*)	 Percentage of porters on joint trail from row region;
summary(r,"PLnom") = PL.L(r);
summary(r,"P") = PROD(g, P.L(g,r))**(1/card(g));
summary(r,"PLreal") = PL.L(r)/summary(r,"P");
summary(r,"INCOME") = RA.L(r);
summary(r,"WELFARE") = WELFARE.L(r);
summary(r,"LOADS") = sum(t(r,s,rr),PORTER.L(r,s,rr));
display summary;

Results

Note in the first two tables of results that the cost of transportation services is zero for those trade links in which there are excess supplies of portering services. When lots of loads originate in r destine for rr, there may not be as many return loads.
----    418 VARIABLE PT.L  Cost of transport from r to rr

             r1          r2          r3          r4          r5          r6          r7          r8          r9         r10

r1                    0.244       0.105                   0.199                   0.212       0.302       0.068       0.181
r2        0.134                   0.097                   0.151                   0.166       0.378       0.081
r3        0.289       0.282                               0.200       0.034       0.224       0.333       0.119       0.184
r4        0.407       0.378       0.394                   0.268                   0.323       0.527       0.195       0.427
r5        0.208       0.227       0.194       0.145                   0.040       0.412       0.412       0.166       0.121
r6        0.407       0.378       0.360       0.498       0.373                   0.439       0.498       0.481       0.498
r7        0.195       0.212       0.170       0.145                   0.029                   0.416       0.172       0.126
r8        0.105                   0.061       0.015                               0.052                   0.050
r9        0.339       0.297       0.275       0.286       0.246                   0.296       0.430                   0.325
r10       0.226       0.378       0.210       0.137       0.291                   0.342       0.542       0.156


----    434 PARAMETER xssupply  Excess supply of portering services

            r2          r4          r5          r6         r10

r1                   0.025                   0.012
r2                   0.026                   0.049       0.050
r3                   0.001
r4                                           0.004
r7                               0.002
r8       0.038                   0.036
r9                                           0.011


----    434 PARAMETER deadheadpct  Porters without loads as a percent of porters on route

            r2          r4          r5          r6         r10

r1                      52                     100
r2                      54                      90          75
r3                       4
r4                                              37
r7                                  21
r8          69                      94
r9                                              36
Notice in the summary table that regions with low read wages and low incomes carry most of the loads:
----    445 PARAMETER summary  Percentage of porters on joint trail from row region

          PLnom           P      PLreal      INCOME     WELFARE       LOADS
r1        0.407       1.114       0.365       4.081       0.365       0.088
r2        0.378       1.126       0.336       3.105       0.277       0.254
r3        0.394       1.109       0.355       4.115       0.370       0.050
r4        0.564       1.096       0.515       6.203       0.547
r5        0.412       1.110       0.372       4.041       0.362       0.109
r6        0.498       1.087       0.458       5.188       0.466       0.053
r7        0.468       1.114       0.420       5.011       0.442       0.027
r8        0.542       1.146       0.473       5.895       0.501       0.011
r9        0.481       1.099       0.437       4.856       0.433       0.081
r10       0.583       1.108       0.526       6.409       0.558

Graphical Representation of Equilibrium Flows

This figure is generated with LaTeX using the GAMS code shown in http://www.mpsge.org/iceberg: