co2mge.gms : Carbon-related trade model (static)

Description

Carbon-Related Trade Model (static).


Reference

  • Perroni, C, and Rutherford, T F, International Trade in Carbon Emission Rights and Basic Materials: General Equilibrium Calculations for 2020. Scandinavian Journal of Economics 95, 3 (1993), 257-278.

Large Model of Types : MPSGE mcp


Category : GAMS Model library


Main file : co2mge.gms

$title Carbon-Related Trade Model (static) (CO2MGE,SEQ=142)

$onText
Carbon-Related Trade Model (static).


Perroni, C, and Rutherford, T F, International Trade in Carbon Emission Rights
and Basic Materials: General Equilibrium Calculations for 2020.
Scandinavian Journal of Economics 95, 3 (1993), 257-278.

Keywords: mixed complementarity problem, general equilibrium model, Carbon dioxide emissions
          international trade, emission, forecasting, greenhouse gases
$offText

Set
   SCENARIOS     'scenarios used for graphs in paper'
                 / BENCH,  GLOBAL-B, GLOBAL-E, GLOBAL-T, GLOBAL
                   OECD-B, OECD-E,   OECD-L,   OECD-T,   OECD   /
   SC(SCENARIOS) 'single scenario to run here' / OECD-L /
   R             'regions' / USA 'USA'
                             OEC 'OECD countries'
                             SUE 'Soviet Union and Eastern Europe'
                             CHN 'China'
                             ROW 'Rest of the World'               /
   OECD(R) 'OECD regions'  / USA, OEC /
   ES      'ETA sectors'   / HYDR 'Global 2100 electric sector HYDRO'
                             COLR 'Global 2100 electric sector COAL-R'
                             NUCR 'Global 2100 electric sector NUC-R'
                             GASN 'Global 2100 electric sector GAS-N'
                             COLN 'Global 2100 electric sector COAL-N'
                             ADVL 'Global 2100 electric sector ADV-LC'
                             ADVH 'Global 2100 electric sector ADV-HC'
                             NEBK 'Global 2100 non-electric sector NE-BAK'
                             RNEW 'Global 2100 non-electric sector RNEW'
                             SYNF 'Global 2100 non-electric sector SYNF'
                             CLDU 'Global 2100 non-electric sector CLDU'
                             OILM 'Global 2100 non-electric sector OILMX'
                             OILX 'Global 2100 non-electric sector OILMX'
                             OILL 'Global 2100 non-electric sector OIL-LC'
                             OILH 'Global 2100 non-electric sector OIL-HC'
                             GASL 'Global 2100 non-electric sector GAS-LC'
                             GASH 'Global 2100 non-electric sector GAS-HC'
                             GNEL 'Global 2100 non-electric sector GNEL'   /
   ET(ES)  'electric technologies'
           / HYDR, COLR, NUCR, GASN, COLN, ADVL, ADVH /
   NT(ES)  'non-electric technologies'
           / NEBK, RNEW, SYNF, CLDU, OILM, OILX, OILL, OILH, GNEL /
   GS(ES)  'gas supply technologies'
           / GASL, GASH /
   G       'goods' / DOME 'non-basic production (Y)'
                     DOMI 'K-L-E-N-BSMA aggregate in non-basic production'
                     BSMA 'basic materials'
                     NELE 'non-electric energy'
                     ELEC 'electric energy'
                     RESR 'basic material resource'
                     SBVA 'basic material intermediate inputs'
                     GASS 'gas supply'
                     CRTS 'CO2 emission rights'
                     OILT 'internationally traded oil'
                     UBND 'upper bounds'
                     LBND 'lower bounds'
                     KSPC 'specific capital'
                     KLVA 'capital-labor value added'                      /
   MS      'macro sectors' / CONS 'Regional consumer'
                             SDOM 'DOME production'
                             SDMI 'DOMI production'
                             SBSM 'BSMA production'
                             SBVA 'BSMA intermediate production'
                             DOMX 'DOME exports'
                             DOMM 'DOME imports'
                             BSMX 'BSMA exports'
                             BSMM 'BSMA imports'
                             CO2X 'Carbon rights export'
                             CO2M 'Carbon rights import'
                             IMEX 'Current account balance'
                             ETAG 'Aggregated ETA sector'        /
   TP          'time periods' / BASE, FUTURE /
   EG(G)       'ETA input goods'
   BE(G)       'basic energy goods'
   OILM(ES)    'oil import sector'
   OILX(ES)    'oil export sector'
   UPPER(ES,R) 'ETA activities with active upper bounds'
   LOWER(ES,R) 'ETA activities with active lower bounds'
   FIXED(ES,R) 'ETA activities fixed'
   BASIC(ES,R) 'ETA activities operated between bounds';

Alias (R,RR);

EG(G)        =  no;
EG("NELE")   = yes;
EG("ELEC")   = yes;
EG("GASS")   = yes;
OILM(ES)     =  no;
OILM("OILM") = yes;
OILX(ES)     =  no;
OILX("OILX") = yes;
BE(G)        =  no;
BE("NELE")   = yes;
BE("ELEC")   = yes;

Scalar
   BYR 'base year'   / 1990 /
   FYR 'future year' / 2020 /;

Table BYD(R,*) 'base year macro data (1990).'
* GDP   Gross Domestic product (US$ billions)
* PN    Reference non-electric price ($ per MBTU).
* QN    Total non-electric energy (MBTU)
* QE    Total electric energy (TKWH)
* BMAM  Basic materials imports (US$ millions)
           GDP  ELVS   PN      QN     QE  BMAM
   USA    5.60  0.33  3.5  51.335  2.661    10
   OEC   10.20  0.33  4.0  50.858  3.288   -66
   SUE    2.68  0.33  2.0  47.207  1.406     4
   CHN    1.10  0.33  2.0  22.610  0.541     4
   ROW    3.34  0.33  2.0  49.870  2.111    49;

Table FYD(R,*) 'future year data'
* GDP  Gross Domestic product (US$ billions)
* PN   Reference non-electric price ($ per MBTU).
* PE   Reference electric price ($ per TKWH).
* PG   Reference price natural gas ($ per MBTU).
* PO   Reference price of oil ($ per MBTU).
            GDP    PN    PE   PG   PO
   USA   10.431  11.0  51.0  6.1  9.0
   OEC   19.788  11.0  51.0  6.1  9.0
   SUE    4.950   9.0  51.0  5.0  9.0
   CHN    3.698   9.0  51.0  4.8  9.0
   ROW    8.615   9.0  51.0  4.8  9.0;

Table ELTECH(ET,R,*) 'electric technology data.'
* COST    US $ per TKWH
* CARBON  CO2 emission rate (tons per TKWH).
* GAS     Gas inputs (MBTU per TKWH).
              COST  CARBON    GAS
   HYDR.USA    2.6
   HYDR.OEC    2.6
   HYDR.SUE    2.6
   HYDR.CHN    2.1
   HYDR.ROW    3.6

   COLR.USA   20.1  0.2779
   COLR.OEC   23.2  0.2844
   COLR.SUE   20.1  0.2680
   COLR.CHN   26.1  0.2776
   COLR.ROW   27.9  0.3600

   NUCR.USA   20.6
   NUCR.OEC   20.6
   NUCR.SUE   20.6
   NUCR.CHN   18.2
   NUCR.ROW   25.4

* NOTE: THESE COSTS ARE REDUCED TO AVOID BENCHMARK LOSS:
   GASN.USA   12.0          7.500
   GASN.OEC   12.0          7.500
   GASN.SUE   12.0          7.500
   GASN.CHN   12.0          7.500
   GASN.ROW   15.0          7.500

   COLN.USA   51.0  0.2533
   COLN.OEC   51.0  0.2533
   COLN.SUE   51.0  0.2533
   COLN.CHN   51.0  0.2533
   COLN.ROW   51.0  0.2533

   ADVH.USA   75.0
   ADVH.OEC   75.0
   ADVH.SUE   75.0
   ADVH.CHN   75.0
   ADVH.ROW   75.0

   ADVL.USA   50.0
   ADVL.OEC   50.0
   ADVL.SUE   50.0
   ADVL.CHN   50.0
   ADVL.ROW   50.0               ;

Table GASTECH(GS,R,*) 'gas supply data.'
* COST    US $ per MBTU
* CARBON  CO2 emission rate (tons per MBTU).
              COST   CARBON
   GASL.USA    1.5  0.01374
   GASL.OEC    1.5  0.01374
   GASL.SUE    1.5  0.01374
   GASL.CHN    1.5  0.01374
   GASL.ROW    0.5  0.01374

   GASH.USA    5.0  0.01374
   GASH.OEC    5.0  0.01374
   GASH.SUE    5.0  0.01374
   GASH.CHN    5.0  0.01374
   GASH.ROW    5.0  0.01374;

Table NETECH(NT,R,*) 'non-electric technology data.'
* COST    US $ per MBTU
* CARBON  CO2 emission rate (tons per MBTU).
* GAS     Natural gas inputs (MBTU per MBTU).
* OILT    Oil trade coefficient (MBTU export per unit activity)
                COST    CARBON    GAS    OILT
   NEBK.USA   16.667
   NEBK.OEC   16.667
   NEBK.SUE   16.667
   NEBK.CHN   16.667
   NEBK.ROW   16.667

   RNEW.USA    6.000
   RNEW.OEC    6.000
   RNEW.SUE    6.000
   RNEW.CHN    6.000
   RNEW.ROW    6.000

   SYNF.USA    8.333   0.04
   SYNF.OEC    8.333   0.04
   SYNF.SUE    8.333   0.04
   SYNF.CHN    8.333   0.04
   SYNF.ROW    8.333   0.04

   CLDU.USA    2.0     0.02412
   CLDU.OEC    3.0     0.02412
   CLDU.SUE    2.0     0.02412
   CLDU.CHN    2.0     0.02412
   CLDU.ROW    2.0     0.02412

   OILM.USA            0.01994         -1.000
   OILM.OEC            0.01994         -1.000
   OILM.SUE            0.01994         -1.000
   OILM.CHN            0.01994         -1.000
   OILM.ROW            0.01994         -1.000

   OILX.USA           -0.01994          1.000
   OILX.OEC           -0.01994          1.000
   OILX.SUE           -0.01994          1.000
   OILX.CHN           -0.01994          1.000
   OILX.ROW           -0.01994          1.000

   OILL.USA    2.5     0.01994
   OILL.OEC    2.5     0.01994
   OILL.SUE    2.5     0.01994
   OILL.CHN    2.5     0.01994
   OILL.ROW    1.0     0.01994

   OILH.USA    6.0     0.01994
   OILH.OEC    6.0     0.01994
   OILH.SUE    6.0     0.01994
   OILH.CHN    6.0     0.01994
   OILH.ROW    6.0     0.01994

* Note: these costs have been reduced relative to
* the Global 2100 numbers.
   GNEL.USA    1.0              1.000
   GNEL.OEC    1.0              1.000
   GNEL.SUE    1.0              1.000
   GNEL.CHN    1.0              1.000
   GNEL.ROW    1.0              1.000;

Table ELSUPPLY(ET,R,*) 'electric supplies bounds and elasticities.'
* UBND  Upper bound (TKWH).
* LBND  Lower bound (TKWH).
* LVL   Reference output level for 2020 (TKWH).
* ESUP  Elasticity of supply for activities operating in 2020.
               UBND   LBND    LVL   ESUP
   HYDR.USA   0.190  0.190  0.190
   HYDR.OEC   0.835  0.835  0.835
   HYDR.SUE   0.213  0.213  0.213
   HYDR.CHN   0.099  0.099  0.099
   HYDR.ROW   0.452  0.452  0.452

   COLR.USA   0.740         0.740  1.000
   COLR.OEC   0.458         0.458  1.000
   COLR.SUE   0.096         0.096  1.000
   COLR.CHN   0.191         0.191  1.000
   COLR.ROW   0.430         0.430  1.000

   NUCR.USA   0.280         0.280
   NUCR.OEC   0.424         0.424
   NUCR.SUE   0.157         0.105  1.000

   GASN.USA   3.200         0.072  1.000
   GASN.OEC   3.200         0.072  1.000
   GASN.SUE   3.200         0.289  1.000
   GASN.CHN   3.200         0.072  1.000
   GASN.ROW   3.200         0.072  1.000

   COLN.USA    +INF         2.985  1.000
   COLN.OEC    +INF         2.995  1.000
   COLN.SUE    +INF         2.102  1.000
   COLN.CHN    +INF         1.703  1.000
   COLN.ROW    +INF         4.238  1.000

   ADVL.USA     0.1         0.100  1.000
   ADVL.OEC     0.2         0.198  1.000
   ADVL.SUE     0.1         0.100  1.000
   ADVL.CHN     0.1         0.100  1.000
   ADVL.ROW     0.1         0.100  1.000

   ADVH.USA     0.8
   ADVH.OEC     1.5
   ADVH.SUE     0.8
   ADVH.CHN     0.8
   ADVH.ROW     0.8                     ;

Table NESUPPLY(NT,R,*) 'non-electric supplies bounds and elasticities.'
* UBND  Upper bound (MBTU).
* LBND  Lower bound (MBTU).
* LVL   Reference output level for 2020 (MBTU).
* ESUP  Elasticity of supply for activities operating in 2020.
                UBND  LBND     LVL   ESUP
   CLDU.USA    2.740         2.740
   CLDU.OEC    5.250         5.250
   CLDU.SUE   11.440        11.440
   CLDU.CHN   17.590        17.590
   CLDU.ROW   12.230        12.230

   NEBK.USA     +INF
   NEBK.OEC     +INF
   NEBK.SUE     +INF
   NEBK.CHN     +INF
   NEBK.ROW     +INF

   RNEW.USA     10.0        10.000
   RNEW.OEC     10.0        10.000
   RNEW.SUE     10.0         5.254  1.000
   RNEW.CHN     10.0         5.293  1.000
   RNEW.ROW     10.0         9.695  1.000

   SYNF.USA     +INF         2.926  1.000
   SYNF.OEC     +INF         2.617  1.000
   SYNF.CHN     +INF         0.851  1.000
   SYNF.ROW     +INF         0.426  1.000

   OILM.USA     +INF        27.909
   OILM.OEC     +INF        24.825

   OILX.SUE      3.0           3.0
   OILX.CHN      0.6           0.6
   OILX.ROW     +INF        49.134

   OILL.USA    8.223         8.223
   OILL.OEC    8.295         8.295
   OILL.SUE   15.369        15.369
   OILL.CHN    5.504         5.504
   OILL.ROW   59.465        59.465

   OILH.USA     +INF         3.027  1.000
   OILH.OEC     +INF         4.442  1.000
   OILH.SUE     +INF         1.041  1.000
   OILH.CHN     +INF         3.588  1.000
   OILH.ROW     +INF        19.947  1.000

* NB: GNEL NUMBERS ADJUSTED SLIGHTLY TO ACHIEVE GAS MARKET BALANCE:
   GNEL.USA     +INF        10.720  1.000
   GNEL.OEC     +INF        17.302  1.000
   GNEL.SUE     +INF        25.507  1.000
   GNEL.CHN     +INF         4.026  1.000
   GNEL.ROW     +INF        37.648  1.000;

Table GASSUPPLY(GS,R,*) 'natural gas supplies bounds and elasticities.'
* UBND  Upper bound (MBTU).
* LBND  Lower bound (MBTU).
* LVL   Reference output level for 2020 (MBTU).
* ESUP  Elasticity of supply for activities operating in 2020.
                UBND  LBND     LVL   ESUP
   GASL.USA    8.148         8.148
   GASL.OEC   12.546        12.546
   GASL.SUE   27.675        27.675
   GASL.CHN    2.441         2.441
   GASL.ROW   22.831        22.831

   GASH.USA     +INF         3.112  1.000
   GASH.OEC     +INF         5.296  1.000
   GASH.CHN     +INF         2.125  1.000
   GASH.ROW     +INF        15.357  1.000;

Set ETACOL / GASOUT, GASINP,  NELEOUT, NELEINP, ELECOUT, ELECINP, OILEXP
             OILIMP, CARBOUT, CARBINP, YOUT,    YINP,    KINP            /;

Parameter
   GDP(R,TP)        'domestic GDP'
   GDPGR(R)         'GDP growth factor'
   PN(R,TP)         'reference price of non-electric'
   PE(R,TP)         'reference price of electric'
   PG(R,TP)         'reference price of gas'
   PO(R,TP)         'reference price of oil'
   QN(R,TP)         'non-electric energy production'
   QE(R,TP)         'electric energy production'
   BMAM(R)          'basic materials imports (base year)'
   ELVS(R)          'electricity value share'
   BDRT(R)          'basic materials share of domestic product'
   NBSH(R)          'non-electric value share of basic materials'
   EBSH(R)          'electric value share of basic materials'
   RSHR(R)          'resource share of basic materials (calibrated)'
   BDEL(R)          'basic-GDP growth elasticity'
   ELEC(ES,R)       'electricity supply'
   NELE(ES,R)       'non-electric supply'
   GASS(ES,R)       'gas supply'
   OILT(ES,R)       'oil trade'
   UBND(ES,R)       'energy sector upper bound'
   LBND(ES,R)       'energy sector lower bound'
   LEVL(ES,R)       'reference activity level'
   COST(ES,R)       'domestic inputs to energy production'
   CARBON(ES,R)     'carbon coefficient'
   ESUP(ES,R)       'elasticity of supply'
   QB(R)            'BMAT benchmark quantity'
   QG(R)            'BMAT benchmark quantity'
   QD(R)            'BMAT benchmark quantity'
   PNI(R)           'future price index'
   PEI(R)           'future price index'
   PGI(R)           'future price index'
   PDI(R)           'future price index'
   PBI(R)           'future price index'
   BMESHR(R,G)      'basic materials share of domestic energy (%)'
   GDPSHR(R,G)      'cost shares of GDP (%)'
   DOMSHR(R,G)      'cost shares in gross output (%)'
   BMMSHR(R)        'basic material import share of consumption (%)'
   MX(R,MS,G)       'macro accounts for future year'
   ROWSUM(G,R)      'row sum check for macro accounts'
   COLSUM(MS,R)     'column sum check for macro accounts'
   EX(R,ES,G)       'ETA accounts for future year'
   GASBAL(R)        'check of gas market balance'
   BMCHK(G)         'check of world market balance'
   BMCRTS(R)        'benchmark CRTS'
   PCTPFT(ES,R)     'unit profit margin in benchmark'
   PROFIT(ES,R)     'adjusted ETA profits'
   UNITPROFIT(ES,R) 'adjusted ETA profits per unit activity'
   BMPROFIT(ES,R)   'benchmark ETA profits'
   NETLOSS(ES,R)    'benchmark loss'

* PARAMETERS USED IN MODEL PRESENTATION:
   ESUBB(R)         'energy-other input substitution in B'
   ESUBC(R)         'substitution elasticity in Y'
   Y0(R)            'non-energy output'
   W0(R)            'non-ernery demand'
   NY0(R)           'non-electric energy input to Y'
   EY0(R)           'electric energy input to Y'
   VY0(R)           'value-added input to Y'
   BY0(R)           'basic materials input to Y'
   B0(R)            'basic materials production'
   RB0(R)           'resource inputs to B'
   NB0(R)           'non-electric energy input to B'
   EB0(R)           'electric energy input to Y'
   VB0(R)           'value-added input to Y'
   ETA(R,ES,ETACOL) 'energy technology'
   CRTS_N(R)        'Carbon rights allocation (non-traded)'
   CRTS_T(R)        'Carbon rights allocation (traded)'
   VA0(R)           'regional value-added endowment'
   EMIT0(*)         'benchmark emissions'
   CO2EMIT(*)       'CO2 emissions'
   RESULTS          'results summary';

Scalar
   NYR     'number of years projected'
   OILBAL  'check of world oil market balance'
   BMATBAL 'check of basic materials trade balance'
   BMATFAC 'BMAT growth factor'
   BEPS    'epsilon for diagnosing bounds' / 1.E-5 /
   ALPHA   'calibrated DOME value share';

Set LVL 'emission levels' / L1*L6 /;

Parameter CO2LEVEL(LVL) 'CO2 abatement levels'
                        / L1 1.2, L2 1.1, L3 1.0, L4 0.9, L5 0.8, L6 0.7 /;

Table CARBLIM(R,*) 'Carbon emissions limits and CRTS trade flag.'
         LEVEL  TRADE
   USA   1.144      0
   OEC   1.100      0
   SUE   0.844      0
   CHN   0.962      0
   ROW   2.253      0;

Table BMATPROD(R,*) 'basic materials production data.'
* NBSH  Non-electric share of basic materials cost.
* EBSH  Electric share of basic materials cost.
* BDRT  Basic-GDP ratio.
* BDEL  Basic materials : GDP growth elasticity.
          NBSH   EBSH   BDRT  BDEL
   USA   0.070  0.070  0.125   0.6
   OEC   0.070  0.070  0.125   0.6
   SUE   0.070  0.070  0.200   0.8
   CHN   0.070  0.070  0.200   0.8
   ROW   0.070  0.070  0.125   0.8;

Table ELAST(R,*) 'elasticities of substitution and supply'
* ESUBC  Elasticity of substitution in non-basic production.
* ESUBB  Elasticity of substitution in basic materials production.
* ELEC   Elasticity of supply for operating electric technologies.
* NELE   Elasticity of supply for operating non-electric technologies.
* GAS    Elasticity of supply for operating gas technologies.
* BMAT   Elasticity of supply for basic materials.
         ESUBC  ESUBB  ELEC  NELE  GAS  BMAT
   USA    0.5     0.3   1.0   1.0  1.0   1.0
   OEC    0.5     0.3   1.0   1.0  1.0   1.0
   SUE    0.25    0.3   1.0   1.0  1.0   1.0
   CHN    0.25    0.3   1.0   1.0  1.0   1.0
   ROW    0.25    0.3   1.0   1.0  1.0   1.0;

* VERIFY THAT EXACTLY ONE COUNTERFACTUAL SCENARIO HAS BEEN SELECTED:
abort$(sum(SCENARIOS$SC(SCENARIOS), 1) <> 1) " A SINGLE SCENARIO NOT SELECTED";

if(SC("BENCH"),
$sTitle: Carbon-related Trade Model - Benchmark Replication
   CARBLIM(R,"LEVEL")           = +inf;
   CO2LEVEL(LVL)$(ord(LVL) > 1) = 0;
);
if(SC("OECD-L"),
$sTitle: Carbon-related Trade Model - OECD Abatement with high Leakage
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
   CARBLIM(OECD,"TRADE") = 1;
   ELAST(R,"BMAT")  = 4;
   ELAST(R,"ESUBC") = 2*ELAST(R,"ESUBC");
   ELAST(R,"ESUBB") = 2*ELAST(R,"ESUBB");
);
if(SC("GLOBAL-E"),
$sTitle: Carbon-related Trade Model - Global Abatement with low Elasticity
   CARBLIM(R,"TRADE") = 1;
   ELAST(R,"ESUBC")   = 0.5*ELAST(R,"ESUBC");
   ELAST(R,"ESUBB")   = 0.5*ELAST(R,"ESUBB");
);
if(SC("GLOBAL-T"),
$sTitle: Carbon-related Trade Model - Global Abatement with Trade in CRTS
   CARBLIM(R,"TRADE") = 1;
);
if(SC("GLOBAL"),
$sTitle: Carbon-related Trade Model - Global Abatement with no Trade in CRTS
);
if(SC("OECD-B"),
$sTitle: Carbon-related Trade Model - OECD Abatement with high BMAT Elasticity
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
   CARBLIM(OECD,"TRADE") = 1;
   ELAST(R,"BMAT")       = 4;
);
if(SC("OECD-E"),
$sTitle: Carbon-related Trade Model - OECD Abatement with low Elasticities
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
   CARBLIM(OECD,"TRADE") = 1;
   ELAST(R,"ESUBC")      = 0.5*ELAST(R,"ESUBC");
   ELAST(R,"ESUBB")      = 0.5*ELAST(R,"ESUBB");
);
if(SC("OECD-L"),
$sTitle: Carbon-related Trade Model - OECD Abatement with high Leakage
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
   CARBLIM(OECD,"TRADE") = 1;
   ELAST(R,"BMAT")  = 4;
   ELAST(R,"ESUBC") = 2*ELAST(R,"ESUBC");
   ELAST(R,"ESUBB") = 2*ELAST(R,"ESUBB");
);
if(SC("OECD-T"),
$sTitle: Carbon-related Trade Model - OECD Abatement with Trade
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
   CARBLIM(OECD,"TRADE") = 1;
);
if(SC("OECD"),
$sTitle: Carbon-related Trade Model - OECD Abatement with no Trade in CRTS
   CARBLIM(R,"LEVEL")$(not OECD(R)) = +inf;
);

* BENCHMARKING BEGINS HERE:
* ========================
NYR = FYR - BYR;

GDP(R,"BASE") = BYD(R,"GDP");
PN(R,"BASE")  = BYD(R,"PN");
QN(R,"BASE")  = BYD(R,"QN");
QE(R,"BASE")  = BYD(R,"QE");
ELVS(R)       = BYD(R,"ELVS");
BMAM(R)       = 0.001*BYD(R,"BMAM");

BDRT(R) = BMATPROD(R,"BDRT");
NBSH(R) = BMATPROD(R,"NBSH");
EBSH(R) = BMATPROD(R,"EBSH");
BDEL(R) = BMATPROD(R,"BDEL");

GDP(R,"FUTURE") = FYD(R,"GDP");
PN(R, "FUTURE") = FYD(R,"PN");
PE(R, "FUTURE") = FYD(R,"PE");
PG(R, "FUTURE") = FYD(R,"PG");
PO(R, "FUTURE") = FYD(R,"PO");

ELEC(ET,R)   =  1;
NELE(NT,R)   =  1;
NELE(OILX,R) = -1;
GASS(GS,R)   =  1;
GASS(ET,R)   = -ELTECH(ET,R,"GAS");
GASS(NT,R)   = -NETECH(NT,R,"GAS");
COST(ET,R)   =  ELTECH(ET,R,"COST");
COST(NT,R)   =  NETECH(NT,R,"COST");
COST(GS,R)   =  GASTECH(GS,R,"COST");
CARBON(ET,R) =  ELTECH(ET,R,"CARBON");
CARBON(NT,R) =  NETECH(NT,R,"CARBON");
CARBON(GS,R) =  GASTECH(GS,R,"CARBON");
OILT(NT,R)   =  NETECH(NT,R,"OILT");

UBND(ET,R)   = ELSUPPLY(ET,R,"UBND");
LBND(ET,R)   = ELSUPPLY(ET,R,"LBND");
LEVL(ET,R)   = ELSUPPLY(ET,R,"LVL");
ESUP(ET,R)   = ELSUPPLY(ET,R,"ESUP")*ELAST(R,"ELEC");

UBND(NT,R)   = NESUPPLY(NT,R,"UBND");
LBND(NT,R)   = NESUPPLY(NT,R,"LBND");
LEVL(NT,R)   = NESUPPLY(NT,R,"LVL");
ESUP(NT,R)   = NESUPPLY(NT,R,"ESUP")*ELAST(R,"NELE");

UBND(GS,R)   = GASSUPPLY(GS,R,"UBND");
LBND(GS,R)   = GASSUPPLY(GS,R,"LBND");
LEVL(GS,R)   = GASSUPPLY(GS,R,"LVL");
ESUP(GS,R)   = GASSUPPLY(GS,R,"ESUP")*ELAST(R,"GAS");

* Benchmark calculations for the Carbon Trade model.
* Check ETA data consistency:
abort$(smax((ES,R), LBND(ES,R) - UBND(ES,R)) > 0)
   " *** ERROR: ETA SUPPLY LOWER BOUND EXCEEDS UPPER BOUND";
abort$(smax((ES,R), LEVL(ES,R) - UBND(ES,R)) > 0)
   " *** ERROR: ETA BENCHMARK SUPPLY EXCEEDS UPPER BOUND";
abort$(smax((ES,R), LBND(ES,R)-  LEVL(ES,R)) > 0)
   " *** ERROR: ETA BENCHMARK SUPPLY VIOLATES LOWER BOUND";

BMATBAL = sum(R, BMAM(R));
abort$(abs(BMATBAL) > 0.01) " Imbalance in BMAT trade data.", BMAM, BMATBAL;

GASBAL(R) = sum(ES, GASS(ES,R)*LEVL(ES,R));
abort$(smax(R, abs(GASBAL(R))) > 0.01) " Gas supply - demand imbalance.", GASBAL;

OILBAL = sum((R,ES), OILT(ES,R)*LEVL(ES,R));
abort$(OILBAL > 0.01) " International oil market imbalance.", OILBAL;

* DATA ADJUSTMENTS:

* Impose balance in basic materials trade:
loop(R$(ord(R) = 1), BMAM(R) = BMAM(R) - BMATBAL;);

* Check gas supply-demand balances and adjust GNEL accordingly:
LEVL("GNEL",R) = LEVL("GNEL",R) - GASBAL(R)/LEVL("GNEL",R);

* Assign oil trade discrepency to first region:
loop(R$(ord(R) = card(R)),
   LEVL("OILX",R) = LEVL("OILX",R) - OILBAL/LEVL("OILX",R);
   UBND("OILX",R) = min( UBND("OILX",R), LEVL("OILX",R));
);

* ETA CALIBRATION AND BENCHMARK:
* Initialize the ETA SAM:
EX(R,ES,G) = 0;

* Pull out coefficients (value):
EX(R,ES,"NELE") =  PN(R,"FUTURE")*NELE(ES,R)/1000;
EX(R,ES,"ELEC") =  PE(R,"FUTURE")*ELEC(ES,R)/1000;
EX(R,ES,"GASS") =  PG(R,"FUTURE")*GASS(ES,R)/1000;
EX(R,ES,"OILT") =  PO(R,"FUTURE")*OILT(ES,R)/1000;
EX(R,ES,"DOME") = -COST(ES,R)/1000;

* Compute benchmark profit (per unit activity):
BMPROFIT(ES,R) = sum(G, EX(R,ES,G));

NETLOSS(ES,R) = min(LEVL(ES,R)*(BMPROFIT(ES,R) - EX(R,ES,"DOME")), 0);
abort$(smin((ES,R), NETLOSS(ES,R)) < 0)
   " --- BENCHMARK PROFIT INCONSISTENCY", BMPROFIT, NETLOSS, COST, EX;

* Define arrays which indicate the benchmark state of ETA activities:
FIXED(ES,R) = yes$(UBND(ES,R) < LBND(ES,R) + BEPS);
LEVL(ES,R)$FIXED(ES,R) = LBND(ES,R);
UBND(ES,R)$FIXED(ES,R) = LBND(ES,R);

UPPER(ES,R)$(not FIXED(ES,R)) = yes$(LEVL(ES,R) > UBND(ES,R) - BEPS);
LOWER(ES,R)$(not FIXED(ES,R)) = yes$(LEVL(ES,R) < LBND(ES,R) + BEPS);
BASIC(ES,R) = yes$(not (FIXED(ES,R) + UPPER(ES,R) + LOWER(ES,R)));

* Check that activities at bounds have appropriate profits:
abort$(smin((ES,R)$UPPER(ES,R), BMPROFIT(ES,R)) < 0)
   " Upper bounded activity makes negative profit:", BMPROFIT, UPPER;

abort$(smax((ES,R)$LOWER(ES,R), BMPROFIT(ES,R)) > 0)
   " Lower bounded activity makes positive profit:", BMPROFIT, LOWER;

* Calibrate the supply functions:
loop((ES,R)$FIXED(ES,R),
   EX(R,ES,"KSPC") = 0;
   EX(R,ES,"UBND") = -BMPROFIT(ES,R);
   EX(R,ES,"LBND") = 0;
);

loop((ES,R)$(not FIXED(ES,R)),
   if(BASIC(ES,R),
      ALPHA = ESUP(ES,R)/(1 + ESUP(ES,R));
      EX(R,ES,"KSPC") = (-BMPROFIT(ES,R) + EX(R,ES,"DOME"))*(1 - ALPHA);
      EX(R,ES,"DOME") = ALPHA*EX(R,ES,"KSPC")/(1 - ALPHA);
      EX(R,ES,"UBND") = 0;
      EX(R,ES,"LBND") = 0;
   else
      if(ESUP(ES,R)*LEVL(ES,R) > 0,
         ALPHA = ESUP(ES,R)/(1 + ESUP(ES,R));
         EX(R,ES,"KSPC") = (-BMPROFIT(ES,R) + EX(R,ES,"DOME"))*(1 - ALPHA);
         EX(R,ES,"DOME") = ALPHA*EX(R,ES,"KSPC")/(1 - ALPHA);
         EX(R,ES,"UBND") = 0;
         EX(R,ES,"LBND") = 0;
      else
         EX(R,ES,"KSPC") = 0;
         EX(R,ES,"UBND")$UPPER(ES,R) = -BMPROFIT(ES,R);
         EX(R,ES,"LBND")$LOWER(ES,R) =  BMPROFIT(ES,R);
      );
   );
);

UNITPROFIT(ES,R)$(not FIXED(ES,R)) = sum(G, EX(R,ES,G));
PROFIT(ES,R)    $(not FIXED(ES,R)) = LEVL(ES,R)*sum(G, EX(R,ES,G));

display BMPROFIT, PROFIT, UNITPROFIT, EX, FIXED, BASIC, UPPER, LOWER;

* Redefine the UPPER and LOWER indicator arrays to include
* bounds which are inactive in the benchmark:
loop((ES,R)$LBND(ES,R), LOWER(ES,R)$(BASIC(ES,R) + UPPER(ES,R)) = yes;);
loop((ES,R)$(UBND(ES,R) < inf), UPPER(ES,R)$(BASIC(ES,R) + LOWER(ES,R)) = yes;);

UPPER(ES,R)$FIXED(ES,R) = no;
LOWER(ES,R)$FIXED(ES,R) = no;
LOWER(ES,R)$(LBND(ES,R) = 0) = no;

* MACRO CALIBRATION AND BENCHMARK:

* Initialize the MACRO SAM:
MX(R,MS,G) = 0;

* Incorporate row representing ETA commodity inputs:
MX(R,"ETAG",G) = sum(ES, EX(R,ES,G)*LEVL(ES,R));

* Trade balance

* Oil trade:
MX(R,"IMEX","OILT") = -MX(R,"ETAG","OILT");

* Compute BMAT 1990=2020 trade index:
GDPGR(R) = (GDP(R,"FUTURE")/GDP(R,"BASE"))**(1.0/NYR) - 1;

* BMAT growth factor based on geometric mean:
BMATFAC = prod(R, (1 + GDPGR(R)*BDEL(R))**NYR)**(1/card(R));

* BMAT trade extrapolated using growth factor:
MX(R,"IMEX","BSMA") = BMAM(R)*BMATFAC;

* Non-basic trade:
MX(R,"IMEX","DOME") = -sum(G, MX(R,"IMEX",G));

* Infer RSHR(R) from the supply elasticity:
RSHR(R) = 1/(1 + ELAST(R,"BMAT"));

* 2020 B quantity:
QB(R) = BDRT(R)*GDP(R,"BASE")*(1 + BDEL(R)*GDPGR(R))**NYR;
QD(R) = QB(R)*(1 - RSHR(R) - EBSH(R) - NBSH(R));

* B production: conditional demands and output (values at 2020 prices)
MX(R,"SBSM","RESR") = - QB(R)*RSHR(R);
MX(R,"SBSM","NELE") = - QB(R)*NBSH(R);
MX(R,"SBSM","ELEC") = - QB(R)*EBSH(R);
MX(R,"SBSM","KLVA") = - QD(R);

* Total B production:
MX(R,"SBSM","BSMA") = - sum(G, MX(R,"SBSM",G));

* Energy inputs to macro production: values are computed as
* residual, the difference between supply and B sector inputs.
MX(R,"SDMI",BE) = - MX(R,"ETAG",BE) - MX(R,"SBSM",BE);

* NB: GDP defined as consumption plus investment, which is then
* equal to K-L value added plus net value of capacity constraints,
* KLVA = GDP - net value of capacity constraints.
MX(R,"SDMI","KLVA") = - (GDP(R,"FUTURE") + QD(R) + MX(R,"ETAG","UBND") - MX(R,"ETAG","LBND"));
MX(R,"SDMI","BSMA") = - (MX(R,"SBSM","BSMA") + MX(R,"IMEX","BSMA"));

abort$(smax(R, MX(R,"SDMI","BSMA")) > 0) " NEGATIVE INPUTS OF BMAT.", MX;

* Total DOMI production:
MX(R,"SDMI","DOMI") = -sum(G, MX(R,"SDMI",G));

* DOME:
MX(R,"SDOM","DOMI") = -MX(R,"SDMI","DOMI");

* Domestic non-basic production:
MX(R,"SDOM","DOME") = -sum(G, MX(R,"SDOM",G));

* Consumer:
MX(R,"CONS","RESR") = -MX(R,"SBSM","RESR");
MX(R,"CONS","KLVA") = -MX(R,"SDMI","KLVA") - MX(R,"SBSM","KLVA");
MX(R,"CONS","UBND") = -MX(R,"ETAG","UBND");
MX(R,"CONS","LBND") = -MX(R,"ETAG","LBND");
MX(R,"CONS","KSPC") = -MX(R,"ETAG","KSPC");
MX(R,"CONS","DOME") = -sum(MS, MX(R,MS,"DOME"));

* Install carbon emissions coefficient (price=0 in benchmark)
* and define carbon rights for the benchmark:
EX(R,ES,"CRTS") = -CARBON(ES,R);
BMCRTS(R) = -sum(ES, EX(R,ES,"CRTS")*LEVL(ES,R));
BMCHK(G)  =  sum(R, MX(R,"IMEX", G));

* Basic materials share of energy inputs:
BMESHR(R,BE) = -100*MX(R,"SBSM",BE)/MX(R,"ETAG",BE);
GDPSHR(R,BE) =  100*MX(R,"ETAG",BE)/GDP(R,"FUTURE");
DOMSHR(R,G)  = -100*MX(R,"SDMI",G)/MX(R,"SDOM","DOME");
DOMSHR(R,"DOMI") = 0;
BMMSHR(R) = -MX(R,"IMEX","BSMA")/MX(R,"SDMI","BSMA");

* Trap benchmark errors:
abort$(smax((R,BE), MX(R,"SDMI",BE)) > 0) "*** Negative ELEC or NELE inputs to SDMI.";

ROWSUM(G, R) = sum(MS, MX(R,MS,G));
COLSUM(MS,R) = sum(G,  MX(R,MS,G));

display BMCRTS, BMCHK, BMESHR, GDPSHR, DOMSHR, BMMSHR, ROWSUM, COLSUM;

* Extract elasticities:
ESUBC(R) = ELAST(R,"ESUBC");
ESUBB(R) = ELAST(R,"ESUBB");

* EXTRACT DATA FROM THE BENCHMARK
W0(R)  = -MX(R,"CONS","DOME");
Y0(R)  =  MX(R,"SDOM","DOME");
NY0(R) = -MX(R,"SDMI","NELE");
EY0(R) = -MX(R,"SDMI","ELEC");
VY0(R) = -MX(R,"SDMI","KLVA");
BY0(R) = -MX(R,"SDMI","BSMA");
B0(R)  =  MX(R,"SBSM","BSMA");
RB0(R) = -MX(R,"SBSM","RESR");
NB0(R) = -MX(R,"SBSM","NELE");
EB0(R) = -MX(R,"SBSM","ELEC");
VB0(R) = -MX(R,"SBSM","KLVA");
VA0(R) =  VY0(R) + VB0(R);
EMIT0(R)       = -sum(ES, LEVL(ES,R)*EX(R,ES,"CRTS"));
EMIT0("TOTAL") =  sum(R, EMIT0(R));

ETA(R,ES,"GASOUT")  = max( EX(R,ES,"GASS"), 0);
ETA(R,ES,"GASINP")  = max(-EX(R,ES,"GASS"), 0);
ETA(R,ES,"NELEOUT") = max( EX(R,ES,"NELE"), 0);
ETA(R,ES,"NELEINP") = max(-EX(R,ES,"NELE"), 0);
ETA(R,ES,"ELECOUT") = max( EX(R,ES,"ELEC"), 0);
ETA(R,ES,"ELECINP") = max(-EX(R,ES,"ELEC"), 0);
ETA(R,ES,"OILEXP")  = max( EX(R,ES,"OILT"), 0);
ETA(R,ES,"OILIMP")  = max(-EX(R,ES,"OILT"), 0);
ETA(R,ES,"CARBOUT") = max( EX(R,ES,"CRTS"), 0);
ETA(R,ES,"CARBINP") = max(-EX(R,ES,"CRTS"), 0);
ETA(R,ES,"YOUT")    = max( EX(R,ES,"DOME"), 0);
ETA(R,ES,"YINP")    = max(-EX(R,ES,"DOME"), 0);
ETA(R,ES,"KINP")    = max(-EX(R,ES,"KSPC"), 0);

$onText
$MODEL:CRTM_S

$SECTORS:
   Y(R)                            ! OTHER OUTPUT
   B(R)                            ! BASIC MATERIALS OUTPUT
   E(ES,R)$(not FIXED(ES,R))       ! ENERGY SECTOR OUTPUT

$COMMODITIES:
   PWY             ! OTHER OUTPUT PRICE
   PWB             ! WORLD PRICE OF BASIC MATERIALS
   PWOIL           ! WORLD PRICE OF OIL
   PGAS(R)         ! REGIONAL PRICE OF GAS
   PELEC(R)        ! REGIONAL ELECTRIC PRICE
   PNELE(R)        ! REGIONAL NON-ELECTRIC PRICE
   PVA(R)          ! REGIONAL PRICE OF VALUE-ADDED
   PBR(R)          ! REGIONAL PRICE OF BASIC MATERIALS RESOURCE

   PU(ES,R)$UPPER(ES,R)      ! ENERGY SUPPLY UPPER BOUND
   PL(ES,R)$LOWER(ES,R)      ! ENERGY SUPPLY LOWER BOUND
   PK(ES,R)$ETA(R,ES,"KINP") ! ENERGY SUPPLY SPECIFIC FACTOR
   PWC$(smax(R,CRTS_T(R)))   ! WORLD PRICE OF CARBON RIGHTS
   PC(R)$CRTS_N(R)           ! REGIONAL CARBON EMISSION PRICE

$CONSUMERS:
   RA(R)   ! REPRESENTATIVE AGENT

* Generate report variables for inputs and demands:
$REPORT:
   V:W(R)    D:PWY        DEMAND:RA(R)
   V:BC(R)   I:PWB        PROD:Y(R)
   V:EY(R)   I:PELEC(R)   PROD:Y(R)
   V:NY(R)   I:PNELE(R)   PROD:Y(R)
   V:EB(R)   I:PELEC(R)   PROD:B(R)
   V:NB(R)   I:PNELE(R)   PROD:B(R)

* Non-basic production:
$PROD:Y(R) s:ESUBC(R) a:1
   O:PWY        Q:Y0(R)
   I:PNELE(R)   Q:NY0(R)  a:
   I:PELEC(R)   Q:EY0(R)  a:
   I:PVA(R)     Q:VY0(R)
   I:PWB        Q:BY0(R)

* Basic materials production:
$PROD:B(R) s:1 a:ESUBB(R) b(a):1
   O:PWB        Q:B0(R)
   I:PBR(R)     Q:RB0(R)
   I:PNELE(R)   Q:NB0(R)  b:
   I:PELEC(R)   Q:EB0(R)  b:
   I:PVA(R)     Q:VB0(R)  a:

* Energy activities:
$PROD:E(ES,R)$(not FIXED(ES,R)) s:0 a:1

* Energy inputs and outputs:
   O:PGAS(R)    Q:ETA(R,ES,"GASOUT")
   O:PNELE(R)   Q:ETA(R,ES,"NELEOUT")
   O:PELEC(R)   Q:ETA(R,ES,"ELECOUT")

   I:PGAS(R)    Q:ETA(R,ES,"GASINP")
   I:PNELE(R)   Q:ETA(R,ES,"NELEINP")
   I:PELEC(R)   Q:ETA(R,ES,"ELECINP")

   O:PWOIL      Q:ETA(R,ES,"OILEXP")
   I:PWOIL      Q:ETA(R,ES,"OILIMP")

* Carbon requirements (international and domestic):
   O:PC(R)$CRTS_N(R)   Q:ETA(R,ES,"CARBOUT")
   I:PC(R)$CRTS_N(R)   Q:ETA(R,ES,"CARBINP")
   O:PWC$CRTS_T(R)     Q:ETA(R,ES,"CARBOUT")
   I:PWC$CRTS_T(R)     Q:ETA(R,ES,"CARBINP")

* Upper and lower bounds:
   I:PU(ES,R)$UPPER(ES,R)  Q:1
   O:PL(ES,R)$LOWER(ES,R)  Q:1

* Other inputs:
   O:PWY        Q:ETA(R,ES,"YOUT")
   I:PWY        Q:ETA(R,ES,"YINP")   a:$ETA(R,ES,"KINP")
   I:PK(ES,R)   Q:ETA(R,ES,"KINP")   a:$ETA(R,ES,"YINP")

$DEMAND:RA(R)
* All regions consume the non-energy good:
   D:PWY      Q:W0(R)

* Value-added endowment:
   E:PVA(R)   Q:VA0(R)

* Basic materials resource endowment:
   E:PBR(R)   Q:RB0(R)

* Upper and lower bounds on energy sector activities:
   E:PU(ES,R)$UPPER(ES,R)   Q:UBND(ES,R)
   E:PL(ES,R)$LOWER(ES,R)   Q:(-LBND(ES,R))

* Specific capital:
   E:PK(ES,R)   Q:(ETA(R,ES,"KINP")*LEVL(ES,R))

* Carbon emission rights:
   E:PWC     Q:CRTS_T(R)
   E:PC(R)   Q:CRTS_N(R)

* Fixed ETA activities:
   E:PGAS(R)         Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"GASOUT")))
   E:PNELE(R)        Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"NELEOUT")))
   E:PELEC(R)        Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"ELECOUT")))
   E:PGAS(R)         Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"GASINP")))
   E:PNELE(R)        Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"NELEINP")))
   E:PELEC(R)        Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"ELECINP")))
   E:PWOIL           Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"OILEXP")))
   E:PWOIL           Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"OILIMP")))
   E:PC(R)$CRTS_N(R) Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"CARBOUT")))
   E:PC(R)$CRTS_N(R) Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"CARBINP")))
   E:PWC$CRTS_T(R)   Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"CARBOUT")))
   E:PWC$CRTS_T(R)   Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"CARBINP")))
   E:PWY             Q:(sum(ES$FIXED(ES,R),  LEVL(ES,R)*ETA(R,ES,"YOUT")))
   E:PWY             Q:(sum(ES$FIXED(ES,R), -LEVL(ES,R)*ETA(R,ES,"YINP")))
$offText
$sysInclude mpsgeset CRTM_S

E.l(ES,R)  =  LEVL(ES,R);
PU.l(ES,R) = -EX(R,ES,"UBND");
PL.l(ES,R) = -EX(R,ES,"LBND");

* CHECK BENCHMARK WITH NO CARBON RESTRICTIONS:
CRTS_N(R) = 0;
CRTS_T(R) = 0;

CRTM_S.iterLim = 0;
$include CRTM_S.GEN
solve CRTM_S using mcp;

* LOOP OVER CO2 LEVELS:
loop(LVL$CO2LEVEL(LVL),
*  SET THE LEVEL OF EMISSIONS:
   CRTS_N(R) = 0;
   CRTS_T(R) = 0;

   loop(R$(CARBLIM(R,"LEVEL") < inf),
      if(CARBLIM(R,"TRADE"), CRTS_T(R) = CARBLIM(R,"LEVEL")*CO2LEVEL(LVL);
      else                   CRTS_N(R) = CARBLIM(R,"LEVEL")*CO2LEVEL(LVL););
   );

*  DEFINE A NUMERAIRE:
   PWY.fx = 1;

*  GENERATE AND SOLVE:
   CRTM_S.iterLim = 2000;
$  include CRTM_S.GEN
   solve CRTM_S using mcp;

*  EXTRACT THE SOLUTION VALUES:
   RESULTS("CPU","--",LVL)    = CRTM_S.resUsd;
   RESULTS("CONTOL","--",LVL) = CRTM_S.objVal;
   RESULTS("NITER","--",LVL)  = CRTM_S.iterUsd;

   CO2EMIT(R)       = -sum(ES, EX(R,ES,"CRTS")*E.l(ES,R));
   CO2EMIT("TOTAL") =  sum(R, CO2EMIT(R));

   RESULTS("CO2EXP",R,LVL) = ((CO2EMIT(R) - CRTS_T(R))*PWC.l*1000)$CRTS_T(R);
   RESULTS("CO2PCT",R,LVL) = 100*(CO2EMIT(R) - EMIT0(R))/EMIT0(R);
   RESULTS("CO2PCT","TOTAL",LVL) =  100*(CO2EMIT("TOTAL") - EMIT0("TOTAL"))/EMIT0("TOTAL");
   RESULTS("CO2TAX",R,LVL)       = 1000*(PC.l(R)$CRTS_N(R) + PWC.l$CRTS_T(R));
   RESULTS("LEAKAGE","--",LVL)   = 0;
   RESULTS("LEAKAGE","--",LVL)$sum(R$(CARBLIM(R,"LEVEL") < inf), EMIT0(R) - CO2EMIT(R))
      = 100*(1 - (EMIT0("TOTAL") - CO2EMIT("TOTAL"))
      / sum(R$(CARBLIM(R,"LEVEL") < inf), EMIT0(R) - CO2EMIT(R)));
   RESULTS("BMATOUTP",R,LVL)     = 100*(B.l(R) - 1);
   RESULTS("POIL",R,LVL)         = PNELE.l(R)*PO(R,"FUTURE");
   RESULTS("POIL","WORLD",LVL)   = PWOIL.l*PO("USA","FUTURE");
   RESULTS("EV",R,LVL)           = 100*(W.l(R) - W0(R))/W0(R);
);

option  RESULTS:1:2:1;
display RESULTS;

$onText
* THE FOLLOWING CODE IS NOT USED FOR THE GAMS LIBRARY VERSION

* APPEND THE SOLUTION TO THE REPORT FILE:
File REP / crtm-s.rep /;

* APPEND TO THIS FILE:
REP.AP = 1;

* SCIENTIFIC FORMAT WITH 17 COLUMN NUMBERS, 8 DECIMALS
REP.NR =  2;
REP.NW = 17;
REP.ND =  8;

* NO PADDING ON LABELS:
REP.LW = 0;
put REP;

* DUMP RESULTS FOR AGGREGATION IN THE REPORT PROGRAM:
loop((SC,LVL)$CO2LEVEL(LVL),
   put SC.TL'.CONTOL.TOTAL.',  LVL.TL, @32, RESULTS("CONTOL","--",LVL)/;
   put SC.TL '.NITER.TOTAL.',  LVL.TL, @32, RESULTS("NITER","--",LVL)/;
   put SC.TL,'.CPU.TOTAL.'  ,  LVL.TL, @32, RESULTS("CPU","--",LVL)  /;
   put SC.TL,'.CO2PCT.TOTAL.', LVL.TL, @32, RESULTS("CO2PCT","TOTAL",LVL)/;
   put SC.TL,'.LEAKAGE.TOTAL.',LVL.TL, @32, RESULTS("LEAKAGE","--",LVL)/;
   put SC.TL,'.POIL.WORLD.',   LVL.TL, @32, RESULTS("POIL","WORLD",LVL)/;
   loop(R,
      put SC.TL,'.CO2EXP.',R.TL,'.', LVL.TL, @32, RESULTS("CO2EXP",R,LVL)/;
      put SC.TL,'.CO2PCT.',R.TL,'.', LVL.TL, @32, RESULTS("CO2PCT",R,LVL)/;
      put SC.TL,'.CO2TAX.',R.TL,'.', LVL.TL, @32, RESULTS("CO2TAX",R,LVL)/;
      put SC.TL,'.BMATOUTP.'R.TL,'.',LVL.TL, @32, RESULTS("BMATOUTP",R,LVL)/;
      put SC.TL,'.POIL.',R.TL,'.',   LVL.TL, @32, RESULTS("POIL",R,LVL)/;
   );
);
$offText