$ontext
$Id: end_reg_model.gms,v 1.1.1.1 2006/03/09 08:58:42 st Exp $
Time-stamp:	<2004-10-22 16:32:48 Shiro Takeda>
Author:		Shiro Takeda
First-written:	<2003/04/24>

Commentary:

In writing this code, I have greatly benefited from GAMS codes in GTAPinGAMS
created by T. F. Rutherford and S. V. Paltsev.  I would express acknowledgment
to them.

$offtext
$title	Define the model:
display "com: Define the model:";

*	----------------------------------------------------------------------
*	Parameter to represent responsivness of regulation.
parameter
    ictax(r)		Implicit carbon tax (inflated by p_u)
    inc_pc		Per capita real income (thousand dollar)
    a_hat		Least square estimate of intercept
    b_hat		Least square estimate of coefficient
    proj_inctax		Projected implicit carbon tax
    resi		Residual
    pop_		Population (mil)

    av_ictax		Average of ictax
    av_inc		Average of real income per capita (thousand dollar)
    n_o_r		The number of regions

    const_tax(r)	Real carbon tax
;
n_o_r = card(r);
display n_o_r;
*	Set temporary values to initialize parameters.	All values have no
*	meaning here.
a_hat = 1;
b_hat = 1;
proj_inctax(r) = 1;
resi(r) = 1;
inc_pc(r) = 1;
pop_(r) = 1;
const_tax(r) = 0;

*	----------------------------------------------------------------------
*	Cost parameters.
display "com: Cost parameters.";
parameter
    cost_o(i,r)		Cost of production
    cost_il(i,r)	Cost of non-resource inputs in xe
    cost_pfe(i,r)	Cost of primary factor-energy composite
    cost_pf(i,r)	Cost of primary factor composite
    cost_ea(i,r)	Cost of energy inputs in nxe
    cost_nel(i,r)	Cost of non-energy inputs in nxe
    cost_lqd(i,r)	Cost of liquidity energy in nxe

    cost_ceg(r)		Cost of energy goods in consumption
    cost_cneg(r)	Cost of non-energy goods in consumption
;
cost_il(xe,r)$vom(xe,r)
    = sum(j, pai0(j,xe,r) * vafm(j,xe,r)) + ld0(xe,r);
display cost_il;

cost_pf(nxe,r)$vom(nxe,r) = ld0(nxe,r) + kd0(nxe,r);
cost_pfe(nxe,r)$vom(nxe,r)
    = cost_pf(nxe,r) + sum(eg, pai0(eg,nxe,r) * vafm(eg,nxe,r));
cost_pf(nxe,r) = round(cost_pf(nxe,r), 4);
cost_pfe(nxe,r) = round(cost_pfe(nxe,r), 4);
display cost_pf, cost_pfe;

cost_o(i,r)$vom(i,r) = (1-ty(i,r)) * vom(i,r);
cost_o(nxe,r)$vom(nxe,r) = sum(neg, pai0(neg,nxe,r)*vafm(neg,nxe,r))
    + cost_pfe(nxe,r);
display cost_o;

cost_ea(nxe,r)$vom(nxe,r) = voei(nxe,r);
display cost_ea;

cost_nel(nxe,r)$vom(nxe,r) = sum(nele, pai0(nele,nxe,r) * vafm(nele,nxe,r));
display cost_nel;

cost_lqd(nxe,r)$vom(nxe,r) = sum(lqd, pai0(lqd,nxe,r) * vafm(lqd,nxe,r));
display cost_lqd;

cost_ceg(r) = sum(eg, pc0(eg,r) * vcm(eg,r));
cost_cneg(r) = sum(neg, pc0(neg,r) * vcm(neg,r));
display cost_ceg, cost_cneg;

*	----------------------------------------------------------------------
*	Share parameters.
display "com: Share parameters.";

parameter
    sh_x(i,r)		Share of export supply in output

    sh_xer(i,r)		Share of resource input in xe
    sh_xe(*,i,r)	Share of non-resource inputs in xe

    sh_neg(j,i,r)	Share of non-energy inpputs in nxe
    sh_pfe(i,r)		Share of PFE composite in nxe
    sh_pf(i,r)		Share of primary factor composite in nxe
    sh_lab(i,r)		Share of primary factor in nxe
    sh_ele(i,r)		Share of electricity in nxe
    sh_col(i,r)		Share of coal in nxe
    sh_lqd(lqd, i,r)	Share of liquidity energy in nxe

    sh_m(i,r)		Share of import goods in Armington aggregation
    sh_mm(i,r,s)	Share of import goods
    gamma(i,s,r)	goods share of unit import cost

    sh_ce(r)		Share of energy composite in consumption
    sh_cneg(i,r)	Share of non-energy goods in consumption
    sh_ceg(i,r)		Share of energy goods in consumption

    sh_t(i,r)		Share of inputs in transport

    sh_cc(r)		Share of aggregate consumption
    sh_inv(r)		Share in global investment
;
sh_x(i,r)$vom(i,r) = vxm(i,r) / vom(i,r);
display sh_x;

sh_xer(xe,r)$cost_o(xe,r) = rd0(xe,r) / cost_o(xe,r);
display sh_xer;

sh_xe("l",xe,r)$cost_il(xe,r) = ld0(xe,r) / cost_il(xe,r);
sh_xe(j,xe,r)$cost_il(xe,r) = pai0(j,xe,r) * vafm(j,xe,r) / cost_il(xe,r);
display sh_xe;

* parameter	chk_xe;
* chk_xe(xe,r) = sh_xer(xe,r) + 1-sh_xer(xe,r);
* option chk_xe:8;
* display chk_xe;

sh_neg(neg,nxe,r)$cost_o(nxe,r)
    = pai0(neg,nxe,r) * vafm(neg,nxe,r) / cost_o(nxe,r);
sh_pfe(nxe,r)$cost_o(nxe,r)
    = cost_pfe(nxe,r) / cost_o(nxe,r);
display sh_neg, sh_pfe;

sh_pf(nxe,r)$cost_pfe(nxe,r)
    = cost_pf(nxe,r) / cost_pfe(nxe,r);
display sh_pf;

sh_lab(nxe,r)$cost_pf(nxe,r) = ld0(nxe,r) / cost_pf(nxe,r);
display sh_lab;

sh_ele(nxe,r)$cost_ea(nxe,r)
    = pai0("ele",nxe,r) * vafm("ele",nxe,r) / cost_ea(nxe,r);
display sh_ele;

sh_col(nxe,r)$cost_nel(nxe,r)
    = pai0("col",nxe,r) * vafm("col",nxe,r) / cost_nel(nxe,r);
display sh_col;

sh_lqd(lqd,nxe,r)$cost_lqd(nxe,r)
    = pai0(lqd,nxe,r) * vafm(lqd,nxe,r) / cost_lqd(nxe,r);
display sh_lqd;

sh_m(i,r)$a0(i,r) = m0(i,r) / a0(i,r);
display sh_m;

sh_ce(r) = cost_ceg(r) / vc(r);
display sh_ce;

sh_ceg(eg,r)$cost_ceg(r) = pc0(eg,r) * vcm(eg,r) / cost_ceg(r);
sh_cneg(neg,r)$cost_cneg(r) = pc0(neg,r) * vcm(neg,r) / cost_cneg(r);
display sh_ceg, sh_cneg;

sh_t(i,r) = vst(i,r) / vt;
display sh_t;

sh_mm(i,s,r)$vim(i,r) =
    (vxmd(i,s,r) * pmx0(i,s,r) + vtwr(i,s,r) * pmt0(i,s,r) ) / vim(i,r);
display sh_mm;

gamma(i,s,r)$vxmd(i,s,r) = vxmd(i,s,r) * pmx0(i,s,r) /
    (vxmd(i,s,r) * pmx0(i,s,r) + vtwr(i,s,r) * pmt0(i,s,r) );
display gamma;

sh_cc(r) = vc(r) / u0(r);
display sh_cc;

sh_inv(r) = ninv(r) / gninv;
display sh_inv;

*	----------------------------------------------------------------------
*	Variable definitions.
display "com: Variable definitions.";

variables
*	Unit cost and price index
    c_y(i,r)		Unit cost of production
    c_ea(i,r)		Unit cost of energy aggregation
    c_a(i,r)		Unit cost of Armington aggregation
    c_m(i,r)		Unit cost of import aggregation
    c_c(r)		Unit cost of consumption
    c_t			Unit cost of transport services
    c_u(r)		Unit cost of utility
    c_ginv		Unit cost of global investment
    p_y(i,r)		Price index of output
    p_il(i,r)		Price index of intermediate input-labor composite
    p_pfe(i,r)		Price index of primary factor-energy composite
    p_pf(i,r)		Price index of primary factor composite
    p_nel(i,r)		Price index of non-electricity energy composite
    p_lqd(i,r)		Price index of liquidity energy composite
    p_mm(i,r,s)		Price index of import
    p_cne(r)		Price index of non-energy goods in consumption
    p_ce(r)		Price index of energy goods in consumption
    p_e(i,j,r)		Price of final energy for intermediate inputs
    p_efd(i,r)		Price of final energy for final demand
    p_x(i,r)		Price of export goods
    p_d(i,r)		Price of domestic goods
    p_m(i,r)		Price of import goods
    p_t			Price of transport services
    p_ea(i,r)		Price of energy composite
    p_l(r)		Wage rate
    p_r(i,r)		Price of resource inputs
    r_k(r)		Rental price
    p_a(i,r)		Price of Armington goods
    p_c(r)		Price index of aggregate consumption
    p_inv		Price of regional investment
    p_u(r)		Price of utility
    p_save		Price of savings


*	Demand and supply
    a_xer(i,r)		Demand for resource inputs
    a_xel(i,r)		Demand for labor
    a_xei(i,j,r)	Demand for intermediate inputs
    a_fl(i,r)		Demand for labor
    a_fk(i,r)		Demand for capital
    a_ea(i,r)		Demand for energy composite
    a_e(j,i,r)		Demand for energy
    a_ad(i,r)		Demand for domestic goods
    a_am(i,r)		Demand for aggregate import
    a_mm(i,s,r)		Demand for import goods
    a_cne(i,r)		Demand for non-energy goods
    a_ce(i,r)		Demand for energy goods
    a_x(i,r)		Export supply
    a_d(i,r)		Domestic supply
    a_t(i,r)		Demand from transport sector
    a_cc(r)		Demand for aggregate consumption
    a_s(r)		Demand for savings

    d_ca(r)		Total emissions
    d_c_e(i,j,r)	Emissions from intermediate inputs
    d_c_fd(i,r)		Emissions from final demand

*	Activity level
    y(i,r)		Production level
    ea(i,r)		Energy aggregation
    a(i,r)		Armington aggregation
    m(i,r)		Import aggregation
    c(r)		Consumption aggregation
    yt			Transport sector
    u(r)		Price of utility

    r_c(r)		Current rate of return from capital stock
    r_e(r)		Expected rate of return from capital stock
    k_e(r)		End-of-period capital stock
    r_g			Global rate of return

    inc_ra(r)		Income of representative agent

    ginv		Global investment
    grossinv(r)		Gross domestic investment
    netinv(r)		Regional net investment (gross minus depreciation)
    rsave(r)		Regional savings

    ic_tax(r)		Implicit carbon tax
    c_tax(r)		Endogenous carbon tax
    rc_tax(r)		Endogenous carbon tax (real)
;
*	----------------------------------------------------------------------
*	Equation definitions.
display "com: Equation definitions.";
equations
*	Unit cost and price index
    e_c_y(i,r)		Unit cost of production
    e_p_y(i,r)		Price index of output
    e_p_il(i,r)		Price index of intermediate input-labor composite
    e_p_pfe(i,r)	Price index of primary factor-energy composite
    e_p_pf(i,r)		Price index of primary factor composite
    e_c_ea(i,r)		Unit cost of energy aggregation
    e_p_nel(i,r)	Price index of non-electricity energy composite
    e_p_lqd(i,r)	Price index of liquidity energy composite
    e_c_a(i,r)		Unit cost of Armington aggregation
    e_c_m(i,r)		Unit cost of import aggregation
    e_p_mm(i,r,s)	Price index of import
    e_c_c(r)		Unit cost of consumption
    e_p_cne(r)		Price index of non-energy goods in consumption
    e_p_ce(r)		Price index of energy goods in consumption
    e_p_e(i,j,r)	Price of final energy for intermediate inputs
    e_p_efd(i,r)	Price of final energy for final demand
    e_c_t		Cost of transport services

*	Activity level
    e_y(i,r)		Production level
    e_ea(i,r)		Energy aggregation
    e_a(i,r)		Armington aggregation
    e_m(i,r)		Import aggregation
    e_c(r)		Consumption aggregation
    e_yt		Transport sector

*	Demand and supply
    e_a_xer(i,r)	Demand for resource inputs
    e_a_xel(i,r)	Demand for labor
    e_a_xei(i,j,r)	Demand for intermediate inputs
    e_a_fl(i,r)		Demand for labor
    e_a_fk(i,r)		Demand for capital
    e_a_ea(i,r)		Demand for energy composite
    e_a_e(j,i,r)	Demand for energy
    e_a_ad(i,r)		Demand for domestic goods
    e_a_am(i,r)		Demand for aggregate import
    e_a_mm(i,s,r)	Demand for import goods
    e_a_cne(i,r)	Demand for non-energy goods
    e_a_ce(i,r)		Demand for energy goods
    e_a_x(i,r)		Export supply
    e_a_d(i,r)		Domestic supply
    e_a_cc(r)		Demand for aggregate consumption
    e_a_s(r)		Demand for savings
    e_a_t(i,r)		Demand from transport sector

    e_d_ca(r)		Total demand for emission permits
    e_d_c_e(i,j,r)	Emissions from intermediate inputs
    e_d_c_fd(i,r)	Emissions from final demand

*	Prices.
    e_p_x(i,r)		Price of export goods
    e_p_d(i,r)		Price of domestic goods
    e_p_m(i,r)		Price of import goods
    e_p_t		Price of transport services
    e_p_ea(i,r)		Price of energy composite
    e_p_l(r)		Wage rate
    e_p_r(i,r)		Price of resource inputs
    e_r_k(r)		Rental price
    e_p_a(i,r)		Price of Armington goods
    e_p_c(r)		Price index of aggregate consumption

    e_inc_ra(r)		Income of representative agent

    e_u(r)		Price of utility
    e_p_inv		Price of regional investment
    e_c_u(r)		Unit cost of utility
    e_p_u(r)		Price of utility
    e_p_save		Price of savings
    e_c_ginv		Unit cost of global investment
    e_ginv		Global investment
    e_grossinv		Gross domestic investment
    e_r_c(r)		Rate of return
    e_r_e(r)		Expected rate of return
    e_k_e(r)		End-of-period capital stock
    e_r_g		Global rate of return

    e_netinv(r)		Net investment
    e_rsave(r)		Regional savings

    e_ic_tax(r)		Implicit carbon tax
    e_c_tax(r)		Endogenous carbon tax
    e_rc_tax(r)		Endogenous carbon tax (real)
;
*	----------------------------------------------------------------------
*	Unit cost and price index.

*	Unit cost of production.
e_c_y(i,r)$vom(i,r) ..

    c_y(i,r) =e=
    ((sh_xer(i,r) * (p_r(i,r))**(1-sig_r(i,r))
    + (1-sh_xer(i,r)) * (p_il(i,r))**(1-sig_r(i,r)))**(1/(1-sig_r(i,r)))
    )$xe(i)
    +
    (sum(neg$sh_neg(neg,i,r),
    sh_neg(neg,i,r) * ((1+ti(neg,i,r))*p_a(neg,r)/pai0(neg,i,r)))
    + sh_pfe(i,r) * p_pfe(i,r)
    )$nxe(i);

*	Price index of output.
e_p_y(i,r)$vom(i,r) ..

    p_y(i,r) =e=
    ((sh_x(i,r)*(p_x(i,r))**(1+eta_o))$sh_x(i,r)
    + (1-sh_x(i,r))*(p_d(i,r))**(1+eta_o)
    )**(1/(1+eta_o));

*	Price index of intermediate goods and labor.
e_p_il(i,r)$cost_il(i,r) ..

    p_il(i,r) =e=
    sh_xe("l",i,r) * p_l(r)
    + sum(j$sh_xe(j,i,r),
    sh_xe(j,i,r) * ((1+ti(j,i,r))*p_a(j,r)/pai0(j,i,r)));

*	Price index of primary factor-energy composite.
e_p_pfe(i,r)$cost_pfe(i,r) ..

    p_pfe(i,r) =e=
    ((sh_pf(i,r)*(p_pf(i,r))**(1-sig_pfe)
    + (1-sh_pf(i,r))*(p_ea(i,r))**(1-sig_pfe))**(1/(1-sig_pfe)))$(sig_pfe ne 1)
    +
    (p_pf(i,r)**(sh_pf(i,r)) * (p_ea(i,r))**(1-sh_pf(i,r)))$(sig_pfe = 1);

*	Price index of primary factor composite.
e_p_pf(i,r)$cost_pf(i,r) ..

    p_pf(i,r) =e=
    ((sh_lab(i,r)*(p_l(r)/tp_kl(r))**(1-sig_pf)
    + (1-sh_lab(i,r))*(r_k(r)/tp_kl(r))**(1-sig_pf)
    )**(1/(1-sig_pf)))$(sig_pf ne 1)
    +
    ((p_l(r)/tp_kl(r))**(sh_lab(i,r))
    * (r_k(r)/tp_kl(r))**(1-sh_lab(i,r)))$(sig_pf = 1);

*	Unit cost of energy aggregation.
e_c_ea(i,r)$cost_ea(i,r) ..

    c_ea(i,r) =e=
    ((sh_ele(i,r)*((1+ti("ele",i,r))*p_a("ele",r)/pai0("ele",i,r))**(1-sig_e)
    + (1-sh_ele(i,r))*(p_nel(i,r))**(1-sig_e))**(1/(1-sig_e)))$(sig_e ne 1)
    +
    (((1+ti("ele",i,r))*p_a("ele",r)/pai0("ele",i,r))**(sh_ele(i,r))
    * (p_nel(i,r))**(1-sh_ele(i,r)))$(sig_e = 1);

*	Price index of non-electricity energy.
e_p_nel(i,r)$cost_nel(i,r) ..

    p_nel(i,r) =e=
    ((sh_col(i,r)*(p_e("col",i,r))**(1-sig_nel)
    + (1-sh_col(i,r))*(p_lqd(i,r))**(1-sig_nel))**(1/(1-sig_nel)))$(sig_nel ne 1)
    +
    ((((p_e("col",i,r))**(sh_col(i,r)))$sh_col(i,r) + 1$(not sh_col(i,r)))
    * (p_lqd(i,r))**(1-sh_col(i,r)))$(sig_nel = 1);

*	Price index of liquidity energy.
e_p_lqd(i,r)$cost_lqd(i,r) ..

    p_lqd(i,r) =e=
    ((sum(lqd$sh_lqd(lqd,i,r),
    sh_lqd(lqd,i,r)*(p_e(lqd,i,r))**(1-sig_lqd)
    ))**(1/(1-sig_lqd)))$(sig_lqd ne 1)
    +
    (prod(lqd$sh_lqd(lqd,i,r),
    (p_e(lqd,i,r))**(sh_lqd(lqd,i,r))
    ))$(sig_lqd = 1);

*	Unit cost of Armington aggregation.
e_c_a(i,r)$a0(i,r) ..

    c_a(i,r) =e=
    (((sh_m(i,r)*(p_m(i,r))**(1-sig_a))$sh_m(i,r)
    + ((1-sh_m(i,r))*(p_d(i,r))**(1-sig_a))$(sh_m(i,r) ne 1)
    )**(1/(1-sig_a)))$(sig_a ne 1)
    +
    ((1$(sh_m(i,r) = 0) +  ((p_m(i,r))**(sh_m(i,r)))$sh_m(i,r))
    * (1$(sh_m(i,r) = 1) +  ((p_d(i,r))**(1-sh_m(i,r)))$(sh_m(i,r) ne 1))
    )$(sig_a = 1);

*	Unit cost of import aggregation.
e_c_m(i,r)$m0(i,r) ..

    c_m(i,r) =e=
    ((sum(s$sh_mm(i,s,r),
    sh_mm(i,s,r)*(p_mm(i,s,r))**(1-sig_m)))**(1/(1-sig_m)))$(sig_m ne 1)
    +
    (prod(s$sh_mm(i,s,r), (p_mm(i,s,r))**(sh_mm(i,s,r))))$(sig_m = 1);

*	Price index of import goods.
e_p_mm(i,r,s)$vxmd(i,r,s) ..

    p_mm(i,r,s) =e=
    gamma(i,r,s)*(1+tm(i,r,s))*(1+tx(i,r,s))*p_x(i,r)/pmx0(i,r,s)
    + (1-gamma(i,r,s))*(1+tm(i,r,s))*p_t/pmt0(i,r,s);

*	Unit cost of consumption aggregation.
e_c_c(r) ..

    c_c(r) =e=
    ((sh_ce(r)*(p_ce(r))**(1-sig_c) + (1-sh_ce(r))*(p_cne(r))**(1-sig_c)
    )**(1/(1-sig_c)))$(sig_c ne 1)
    +
    ((p_ce(r))**sh_ce(r) * (p_cne(r))**(1-sh_ce(r)))$(sig_c = 1);

*	Price index of non-energy consumption goods.
e_p_cne(r) ..

    p_cne(r) =e=
    ((sum(neg$sh_cneg(neg,r),
    sh_cneg(neg,r)*((1+tc(neg,r))*p_a(neg,r)/pc0(neg,r))**(1-sig_cne)
    ))**(1/(1-sig_cne)))$(sig_cne ne 1)
    +
    (prod(neg$sh_cneg(neg,r),
    ((1+tc(neg,r))*p_a(neg,r)/pc0(neg,r))**(sh_cneg(neg,r)))
    )$(sig_cne = 1);

*	Price index of energy consumption goods.
e_p_ce(r) ..

    p_ce(r) =e=
    ((sh_ceg("ele",r)*((1+tc("ele",r))*p_a("ele",r)/pc0("ele",r))**(1-sig_ce)
    + sum(fe$sh_ceg(fe,r),
    sh_ceg(fe,r)*(p_efd(fe,r))**(1-sig_ce))
    )**(1/(1-sig_ce)))$(sig_ce ne 1)
    +
    (((1+tc("ele",r))*p_a("ele",r)/pc0("ele",r))**(sh_ceg("ele",r))
    * prod(fe$sh_ceg(fe,r),
    (p_efd(fe,r))**(sh_ceg(fe,r)))
    )$(sig_ce = 1);

*	Price index of energy for intermediate inputs:
e_p_e(fe,nxe,r)$vafm(fe,nxe,r) ..

    p_e(fe,nxe,r) =e= (1+ti(fe,nxe,r))*p_a(fe,r) / (pai0(fe,nxe,r)*tp_fe(r))
    + (delta(fe,nxe,r)
    * (ic_tax(r)$fl_it + c_tax(r)$fl_et + (rc_tax(r) * p_u(r))$fl_ct) / tp_fe(r)
    )$delta(fe,nxe,r);

*	Price index of energy for final demand:
e_p_efd(fe,r)$vcm(fe,r) ..

    p_efd(fe,r) =e= (1+tc(fe,r))*p_a(fe,r) / pc0(fe,r)
    + (delta(fe,"fd",r)
    * (ic_tax(r)$fl_it + c_tax(r)$fl_et + (rc_tax(r) * p_u(r))$fl_ct)
    )$delta(fe,"fd",r);

*	Unit cost of transport services.
e_c_t ..

    c_t =e=
    ((sum((i,r)$sh_t(i,r),
    sh_t(i,r)*(p_x(i,r))**(1-sig_t)))**(1/(1-sig_t))
    )$(sig_t ne 1)
    +
    (prod((i,r)$sh_t(i,r), (p_x(i,r))**(sh_t(i,r))))$(sig_t = 1);

*	Unit cost of utility:
e_c_u(r) ..

    c_u(r) =e=
    ((sh_cc(r) * (p_c(r))**(1-sig_u) + (1-sh_cc(r)) * (p_save)**(1-sig_u)
    )**(1/(1-sig_u))
    )$(sig_u ne 1)
    +
    ((p_c(r))**(sh_cc(r)) * (p_save)**(1-sh_cc(r)))$(sig_u = 1);

*	----------------------------------------------------------------------
*	Zero profit conditions

*	Production activity.
e_y(i,r)$vom(i,r) ..

    c_y(i,r) =g= (1-ty(i,r)) * p_y(i,r) / py0(i,r);

*	Energy aggregation.
e_ea(i,r)$cost_ea(i,r) ..

    c_ea(i,r) =g= p_ea(i,r);

*	Armington aggregation.
e_a(i,r)$a0(i,r) ..

    c_a(i,r) =g= p_a(i,r);

*	Import aggregation.
e_m(i,r)$m0(i,r) ..

    c_m(i,r) =g= p_m(i,r);

*	Consumption aggregation.
e_c(r) ..

    c_c(r) =g= p_c(r);

*	Transport services.
e_yt ..

    c_t =g= p_t;

*	Utility:
e_u(r) ..

    c_u(r) =g= p_u(r);

*	----------------------------------------------------------------------
*	Demand and supply.

*	Export supply.
e_a_x(i,r)$vxm(i,r) ..

    a_x(i,r) =e= vxm(i,r) * (p_x(i,r)/p_y(i,r))**(eta_o);

*	Domestic supply.
e_a_d(i,r)$vdm(i,r) ..

    a_d(i,r) =e= vdm(i,r) * (p_d(i,r)/p_y(i,r))**(eta_o);

*	Demand for natural resource.
e_a_xer(i,r)$(xe(i) and rd0(i,r)) ..

    a_xer(i,r) =e= rd0(i,r) * (c_y(i,r)/p_r(i,r))**(sig_r(i,r));

*	Demand for labor from fossil fuel production.
e_a_xel(i,r)$(xe(i) and ld0(i,r)) ..

    a_xel(i,r) =e=
    ld0(i,r) * (c_y(i,r)/p_il(i,r))**(sig_r(i,r));

*	Demand for intermediate goods from fossil fuel production.
e_a_xei(j,i,r)$(xe(i) and vafm(j,i,r)) ..

    a_xei(j,i,r) =e=
    vafm(j,i,r) * (c_y(i,r)/p_il(i,r))**(sig_r(i,r));

*	Demand for labor from non-fossil fuel production.
e_a_fl(i,r)$(nxe(i) and ld0(i,r)) ..

    a_fl(i,r)
    =e= ld0(i,r) * (p_pf(i,r)/p_l(r))**(sig_pf) * (tp_kl(r))**(sig_pf - 1)
    * (p_pfe(i,r)/p_pf(i,r))**(sig_pfe);

*	Demand for capital from non-fossil fuel production.
e_a_fk(i,r)$(nxe(i) and kd0(i,r)) ..

    a_fk(i,r)
    =e= kd0(i,r) * (p_pf(i,r)/r_k(r))**(sig_pf) * (tp_kl(r))**(sig_pf - 1)
    * (p_pfe(i,r)/p_pf(i,r))**(sig_pfe);

*	Demand for energy composite from non-fossil fuel production.
e_a_ea(i,r)$(nxe(i) and voei(i,r)) ..

    a_ea(i,r) =e= voei(i,r) * (p_pfe(i,r)/p_ea(i,r))**(sig_pfe);

*	Demand for energy goods.
e_a_e(eg,i,r)$(cost_ea(i,r) and vafm(eg,i,r)) ..

    a_e(eg,i,r) =e=

    (vafm(eg,i,r)
    * (c_ea(i,r)/((1+ti(eg,i,r))*p_a(eg,r)/pai0(eg,i,r)))**(sig_e)
    )$ele(eg)
    +
    (vafm(eg,i,r) * (tp_fe(r))**(-1)
    * (p_nel(i,r)/p_e(eg,i,r))**(sig_nel)
    * (c_ea(i,r)/p_nel(i,r))**(sig_e)
    )$col(eg)
    +
    (vafm(eg,i,r) * (tp_fe(r))**(-1)
    * (p_lqd(i,r)/p_e(eg,i,r))**(sig_lqd)
    * (p_nel(i,r)/p_lqd(i,r))**(sig_nel)
    * (c_ea(i,r)/p_nel(i,r))**(sig_e)
    )$lqd(eg)
    ;

*	Demand for domestic goods.
e_a_ad(i,r)$d0(i,r) ..

    a_ad(i,r) =e= d0(i,r) * (c_a(i,r)/p_d(i,r))**(sig_a);

*	Demand for aggregate import.
e_a_am(i,r)$m0(i,r) ..

    a_am(i,r) =e= m0(i,r) * (c_a(i,r)/p_m(i,r))**(sig_a);

*	Demand for import goods.
e_a_mm(i,r,s)$vxmd(i,r,s) ..

    a_mm(i,r,s) =e=
    vxmd(i,r,s) * (c_m(i,s) / p_mm(i,r,s))**(sig_m);

*	Demand for non-energy consumption.
e_a_cne(i,r)$(neg(i) and vcm(i,r)) ..

    a_cne(i,r) =e= vcm(i,r)
    * (p_cne(r)/((1+tc(i,r))*p_a(i,r)/pc0(i,r)))**(sig_cne)
    * (c_c(r)/p_cne(r))**(sig_c);

*	Demand for energy consumption.
e_a_ce(i,r)$(eg(i) and vcm(i,r)) ..

    a_ce(i,r) =e=

    (vcm(i,r)
    * (p_ce(r)/((1+tc(i,r))*p_a(i,r)/pc0(i,r)))**(sig_ce)
    * (c_c(r)/p_ce(r))**(sig_c))$ele(i)
    +
    (vcm(i,r)
    * (p_ce(r)/p_efd(i,r))**(sig_ce)
    * (c_c(r)/p_ce(r))**(sig_c))$(not ele(i));
;
*	Demand from transport sector.
e_a_t(i,r)$vst(i,r) ..

    a_t(i,r) =e= vst(i,r) * (c_t / p_x(i,r))**(sig_t);

*	Demand for aggregation consumption:
e_a_cc(r) ..

    a_cc(r) =e= vc(r) * (p_u(r) / p_c(r))**(sig_u);

*	Demand for savings:
e_a_s(r) ..

    a_s(r) =e= save(r) * (p_u(r) / p_save)**(sig_u);

*	Emissions from intermediate inputs:
e_d_c_e(fe,nxe,r)$delta_(fe,nxe,r) ..

    d_c_e(fe,nxe,r) =e=
    delta_(fe,nxe,r) * a_e(fe,nxe,r) * ea(nxe,r);

*	Emissions from final demand:
e_d_c_fd(fe,r)$delta_(fe,"fd",r) ..

    d_c_fd(fe,r) =e= delta_(fe,"fd",r) * a_ce(fe,r) * c(r);

*	Total demand for emission permits:
e_d_ca(r) ..

    d_ca(r) =e= sum((fe,nxe)$delta(fe,nxe,r), d_c_e(fe,nxe,r))
    + sum(fe$delta(fe,"fd",r), d_c_fd(fe,r));

*	----------------------------------------------------------------------
*	Market clearing conditions

*	Export goods.
e_p_x(i,r)$vxm(i,r) ..

    a_x(i,r)*y(i,r) =g=
    sum(s$vxmd(i,r,s), a_mm(i,r,s) * m(i,s))
    + (a_t(i,r) * yt)$vst(i,r);

*	Domestic goods.
e_p_d(i,r)$vdm(i,r) ..

    a_d(i,r) * y(i,r) =g=
    ( a_ad(i,r)*a(i,r) )$(not cgd(i))
    +
    (ninv(r)*netinv(r) + scale_k(r) * depr(r) * k_b(r))$cgd(i);

*	Import goods.
e_p_m(i,r)$vim(i,r) ..

    m0(i,r) * m(i,r) =g= a_am(i,r) * a(i,r);

*	Transport services.
e_p_t ..

    vt * yt =g= sum((i,r,s)$vxmd(i,r,s), tau(i,r,s) * a_mm(i,r,s) * m(i,s));

*	Energy composite.
e_p_ea(i,r)$voei(i,r) ..

    voei(i,r) * ea(i,r) =g= a_ea(i,r) * y(i,r);

*	Labor.
e_p_l(r) ..

    scale_l(r) * end_l(r) =e=
    sum(xe$ld0(xe,r), a_xel(xe,r) * y(xe,r))
    + sum(nxe$ld0(nxe,r), a_fl(nxe,r) * y(nxe,r));

*	Capital.
e_r_k(r) ..

    scale_k(r) * end_k(r) =g= sum(nxe$kd0(nxe,r), a_fk(nxe,r) * y(nxe,r));

*	Natural resource.
e_p_r(i,r)$(xe(i) and rd0(i,r)) ..

    scale_r(r) * rd0(i,r) =g= a_xer(i,r) * y(i,r);

*	Armington goods.
e_p_a(i,r)$a0(i,r) ..

    a0(i,r) * a(i,r) =g=

    ( sum(xe$vafm(i,xe,r), a_xei(i,xe,r) * y(xe,r))
    + sum(nxe$vafm(i,nxe,r), vafm(i,nxe,r) * y(nxe,r))
    + (a_cne(i,r) * c(r))$vcm(i,r)
    )$neg(i)
    +
    ( sum(xe$vafm(i,xe,r), a_xei(i,xe,r) * y(xe,r))
    + sum(nxe$vafm(i,nxe,r), a_e(i,nxe,r) * ea(nxe,r))
    + (a_ce(i,r) * c(r))$vcm(i,r)
    )$eg(i)
    ;

*	Aggregate consumption.
e_p_c(r) ..

    vc(r) * c(r) =g= a_cc(r) * u(r);

*	Carbon emissions.
e_ic_tax(r)$fl_it ..

    carblim(r) =g= d_ca(r);

*	Utility:
e_p_u(r) ..

    inc_ra(r) =g= p_u(r) * u0(r) * u(r);

*	Market for savings:
e_p_save ..

    gninv * ginv =g= sum(r, save(r) * rsave(r));

*	----------------------------------------------------------------------
*	Income.

e_inc_ra(r) ..

    inc_ra(r) =e=

    sum(i$vom(i,r), ty(i,r) * p_y(i,r) * vom(i,r) * y(i,r))

    + sum((xe,j)$vafm(j,xe,r), ti(j,xe,r) * p_a(j,r) * a_xei(j,xe,r) * y(xe,r))

    + sum((nxe,fe)$vafm(fe,nxe,r),
    ti(fe,nxe,r) * p_a(fe,r) * a_e(fe,nxe,r) * ea(nxe,r))

    + sum(nxe$vafm("ele",nxe,r),
    ti("ele",nxe,r) * p_a("ele",r) * a_e("ele",nxe,r) * ea(nxe,r))

    + sum((nxe,neg)$vafm(neg,nxe,r),
    ti(neg,nxe,r) * p_a(neg,r) * vafm(neg,nxe,r) * y(nxe,r))

    + sum((i,s)$vxmd(i,r,s), tx(i,r,s) * p_x(i,r) * a_mm(i,r,s) * m(i,s))

    + sum((i,s)$vxmd(i,s,r),
    tm(i,s,r) * ((1+tx(i,s,r)) * p_x(i,s) + p_t * tau(i,s,r))
    * a_mm(i,s,r) * m(i,r))

    + sum(neg$vcm(neg,r), tc(neg,r) * p_a(neg,r) * a_cne(neg,r) * c(r))

    + sum(fe$vcm(fe,r), tc(fe,r) * p_a(fe,r) * a_ce(fe,r) * c(r))
    + tc("ele",r) * p_a("ele",r) * a_ce("ele",r) * c(r)

    + p_l(r) * scale_l(r) * end_l(r)

    + r_k(r) * scale_k(r) * end_k(r)

    + sum(xe, p_r(xe,r) * scale_r(r) * rd0(xe,r))

    - sum(cgd, p_d(cgd,r) * scale_k(r) * depr(r) * k_b(r))

    + (ic_tax(r) * carblim(r))$fl_it

    + (c_tax(r) * d_ca(r))$fl_et

    + (p_u(r) * rc_tax(r) * d_ca(r))$fl_ct
;
*	----------------------------------------------------------------------
*	Investment:

*	Price of regional investment:
e_p_inv(r) ..

    p_inv(r) =e= sum(cgd, p_d(cgd,r));

*	Unit cost of global investment:
e_c_ginv$(not rordelta) ..

    c_ginv =e= sum(r, sh_inv(r) * p_inv(r));

*	Global investment:
e_ginv ..

    (gninv * ginv - sum(r, ninv(r) * netinv(r)))$rordelta
    +
    (c_ginv - p_save)$(not rordelta)
    =e= 0
    ;
*	Regional gross investment:
e_grossinv(r) ..

    inv(r) * grossinv(r)
    =e= ninv(r) * netinv(r) + scale_k(r) * depr(r) * k_b(r);

*	The current rate of return from capital stock:
e_r_c(r)$rordelta ..

    r_c(r) =e= r_k(r) / p_inv(r) - depr(r);

*	The expected rate of return from capital stock:
e_r_e(r)$rordelta ..

    r_e0(r) * r_e(r) =e=
    r_c(r) * (k_e(r)/(scale_k(r) * k_b(r)))**(-rorflex(r));
*     log(r_e0(r) * r_e(r)) =e=
*     log(r_c(r)) - rorflex(r) * (log(k_e(r)/(scale_k(r) * k_b(r))));

*	The global rate of return:
e_r_g$rordelta ..

    sum(r, p_inv(r) * ninv(r) * netinv(r)) =e= p_save * gninv * ginv;

*	The end-of-period capital stock:
e_k_e(r) ..

    k_e(r) =e= scale_k(r) * k_b(r) + ninv(r) * netinv(r);

*	Regional net investment:
e_netinv(r) ..

    (r_g - r_e(r))$rordelta
    +
    (netinv(r) - ginv)$(not rordelta)
    =e= 0;

*	Regional savings:
e_rsave(r) ..

    save(r) * rsave(r) =e= a_s(r) * u(r);

*	----------------------------------------------------------------------
*	Carbon tax:

*	Endogenous carbon tax:
e_c_tax(r)$fl_et ..

    rc_tax(r) =e=
    resi(r) + a_hat + c_reg * b_hat * inc_ra(r) * 10 / (pop_(r) * p_u(r))
    + (1 - c_reg) * b_hat * inc_pc(r);

*	Real carbon tax:
e_rc_tax(r)$(fl_it or fl_et or fl_ct) ..

    rc_tax(r) =e=
    (ic_tax(r)$fl_it + c_tax(r)$fl_et) / p_u(r) + const_tax(r)$fl_ct;

*	----------------------------------------------------------------------
*	Model definition.
display "com: Model definition.";

model end_reg_mcp A multi-region recursive model for carbon tax analysis /

      e_c_y.c_y, e_p_y.p_y, e_p_il.p_il, e_p_pfe.p_pfe, e_p_pf.p_pf,
      e_c_ea.c_ea, e_p_nel.p_nel, e_p_lqd.p_lqd, e_c_a.c_a, e_c_m.c_m,
      e_p_mm.p_mm, e_c_c.c_c, e_p_cne.p_cne, e_p_ce.p_ce, e_p_e.p_e,
      e_p_efd.p_efd, e_c_t.c_t,

      e_y.y, e_ea.ea, e_a.a, e_m.m, e_c.c, e_yt.yt,

      e_a_x.a_x, e_a_d.a_d, e_a_xer.a_xer, e_a_xel.a_xel, e_a_xei.a_xei,
      e_a_fl.a_fl, e_a_fk.a_fk, e_a_ea.a_ea, e_a_e.a_e, e_a_ad.a_ad,
      e_a_am.a_am, e_a_mm.a_mm, e_a_cne.a_cne, e_a_ce.a_ce, e_a_t.a_t,

      e_d_ca.d_ca, e_d_c_e.d_c_e, e_d_c_fd.d_c_fd,

      e_p_x.p_x, e_p_d.p_d, e_p_m.p_m, e_p_t.p_t, e_p_ea.p_ea, e_p_l.p_l,
      e_p_r.p_r, e_r_k.r_k, e_p_a.p_a, e_p_c.p_c, e_ic_tax.ic_tax,

      e_inc_ra.inc_ra,

      e_p_inv.p_inv, e_c_u.c_u, e_p_u.p_u, e_u.u, e_p_save.p_save,
      e_ginv.ginv, e_grossinv.grossinv, e_c_ginv.c_ginv, e_r_c.r_c, e_r_e.r_e,
      e_k_e.k_e, e_r_g.r_g, e_netinv.netinv, e_rsave.rsave, e_a_cc.a_cc,
      e_a_s.a_s, e_c_tax.c_tax, e_rc_tax.rc_tax

      /;

*	----------------------------------------------------------------------
*	Set lower bounds and initial values
display "com: Set lower bounds and initial values";
$include end_reg_initial.gms

*	Fix income:
inc_ra.fx("usa") = inc_ra.l("usa");

*	----------------------------------------------------------------------
*	Fix irrelevant values.
display "com: Fix irrelevant values.";

parameter
    res_u		Utility
    res_p_u		Price of utility
    res_inc		Income
    res_inc_pc		Per capita income
    res_c		Consumption
    res_gdp		GDP
    res_k		Total capital stock
    res_kst		Total capital stock (capital earnings)
    res_save		Savings
    res_ninv		Regional net investment
    res_inv		Regional gross investment
    res_ginv		Global net investment
    res_carb		Carbon emissions (BtC)
    res_carb_fe		Carbon emissions (BtC)
    res_ene_fe		Energy (EJ)
    res_carb_sec	Carbon emissions by sector (BtC)
    res_c_tax		Carbon tax
    res_c_tax_		Carbon tax
    res_leakage		Leakage rate in 2010 (%)
    res_y		Output

    rc_carb		The rate of change in carbon emissions (%)

    pc_gdp		% change in GDP from BAU
    pc_carb		% change in carbon emissions from BAU
;
parameter
    chk_carb		Carbon emissions (BtC)
    chk_carb_fe		Carbon emissions (BtC)
    chk_carb_o		Carbon emissions from oil (BtC)
    chk_carb_c		Carbon emissions from coal (BtC)
    chk_carb_g		Carbon emissions from gas (BtC)
    chk_gdp		GDP
;
*	Declaration of parameters:
$include par_result_2010bau.gms

*	----------------------------------------------------------------------
*	Benchmark replication in 1997:
display "com: Benchmark replication in 1997:";

*	No carbon taxes in the benchmark:
carblim(r) = 500000;
display carblim;

end_reg_mcp.iterlim = 0;
end_reg_mcp.optfile = 1;
solve end_reg_mcp using mcp;

*	----------------------------------------------------------------------
*	Cleanup calculation in 1997:
display "com: Cleanup calculation in 1997:";
end_reg_mcp.iterlim = 8000;
solve end_reg_mcp using mcp;
display "Benchmark tolerance:", end_reg_mcp.objval;
abort$(end_reg_mcp.modelstat <> 1)
     "Model not normally completed", end_reg_mcp.modelstat;
abort$(end_reg_mcp.solvestat <> 1)
     "No local optimum found", end_reg_mcp.solvestat;

res_carb("bau","1997",r) = d_ca.l(r);
res_carb("bau","1997","world") = sum(r, res_carb("bau","1997",r));
display res_carb, carbon95;

res_carb_fe("bau","1997",fe,r)
    = sum(nxe$delta_(fe,nxe,r), d_c_e.l(fe,nxe,r)) + d_c_fd.l(fe,r);
res_carb_fe("bau","1997","total",r) = sum(fe, res_carb_fe("bau","1997",fe,r));
res_carb_sec("bau","1997",i,r) =
    sum(fe$delta_(fe,i,r), d_c_e.l(fe,i,r));
res_carb_sec("bau","1997","fd",r) = sum(fe$delta_(fe,"fd",r), d_c_fd.l(fe,r));
res_carb_sec("bau","1997","total",r) = sum(i, res_carb_sec("bau","1997",i,r))
    + res_carb_sec("bau","1997","fd",r);
display res_carb_fe, res_carb_sec;

if(scale_ch,
*	----------------------------------------------------------------------
*	Scale check
    display "com: Scale check:";

    scale_k(r) = 1.1;
    scale_l(r) = 1.1;
    scale_r(r) = 1.1;
    solve end_reg_mcp using mcp;
    display "Tolerance:", end_reg_mcp.objval;
    abort$(end_reg_mcp.modelstat <> 1)
	 "Model not normally completed", end_reg_mcp.modelstat;
    abort$(end_reg_mcp.solvestat <> 1)
	 "No local optimum found", end_reg_mcp.solvestat;
    scale_k(r) = 1;
    scale_l(r) = 1;
    scale_r(r) = 1;

);
$if %scale_ch%==1 $goto end

if(fl_test,
*	----------------------------------------------------------------------
*	Test solve:
    display "com: Test solve:";

    fl_it = 1;
    display fl_it;
    carblim(r)$annexb(r) = 0.9 * res_carb("bau","1997",r);
    display carblim;

*     tp_kl(r) = 1.1;
*     tp_fe(r) = 1.5;

    solve end_reg_mcp using mcp;
    display "Tolerance:", end_reg_mcp.objval;
    abort$(end_reg_mcp.modelstat <> 1)
	 "Model not normally completed", end_reg_mcp.modelstat;
    abort$(end_reg_mcp.solvestat <> 1)
	 "No local optimum found", end_reg_mcp.solvestat;

    res_carb_fe("bau","1997_",fe,r)
	= sum(nxe$delta_(fe,nxe,r), d_c_e.l(fe,nxe,r)) + d_c_fd.l(fe,r);
    res_carb_fe("bau","1997_","total",r)
	= sum(fe, res_carb_fe("bau","1997_",fe,r));
    res_carb_sec("bau","1997_",i,r) =
	sum(fe$delta_(fe,i,r), d_c_e.l(fe,i,r));
    res_carb_sec("bau","1997_","fd",r)
	= sum(fe$delta_(fe,"fd",r), d_c_fd.l(fe,r));
    res_carb_sec("bau","1997_","total",r)
	= sum(i, res_carb_sec("bau","1997_",i,r))
	+ res_carb_sec("bau","1997_","fd",r);
    display res_carb_fe;

    res_carb("bau","1997_",r) = d_ca.l(r);
    res_carb("bau","1997_","world") = sum(r, res_carb("bau","1997_",r));
    display res_carb;

);
$if %fl_test%==1 $goto end

$label end

* --------------------
* Local Variables:
* mode: gams
* fill-column: 78
* End: