* -------------- ANAR1 parameter declaration & assignments ----------------

$ontext
 Calibration proceeds by the blocks of equations
 each block contains all the related parameter declarations and assignments

 All permutations for the model and model calibration are selected in
       EITHER     dat_c_f_r_10.inc
       OR         data_c_f_r_10.xls

$offtext
* ######## NORMALISED PRICE BLOCK

PARAMETERS
 PE0(c,r)       Domestic price of exports by commodity c
 PER0(c,w,r)    Domestic price of exports of comm'y c to region w and wm

 PD0(c,r)       Consumer price for domestic supply of commodity c

 PM0(c,r)       Domestic price of competitive imports c
 PML0(c,r)      Dom price of imports of comm'y c from region with small shares
 PMS0(c,r)      Dom price of imports of comm'y c from region with large shares
 PMR0(w,c,r)    Domestic price of imports of comm'y c from region w and wm

 PT0(c,r)       Price of margin services c

 PX0(a,r)       Composite price of output by activity a
 PXC0(c,r)      Producer price of composite domestic output

 ER0(r)         Exchange rate

   ;

* #### Assignments

 PE0(c,r)                     = 1.0 ;
 PER0(c,w,r)                  = 1.0 ;

 PD0(c,r)                     = 1.0 ;

 PM0(c,r)                     = 1.0 ;
 PML0(c,r)                    = 1.0 ;
 PMS0(c,r)                    = 1.0 ;
 PMR0(w,c,r)                  = 1.0 ;

 PT0(c,r)                     = 1.0 ;

 PX0(a,r)$SAMG("total",a,r)   = 1.0 ;

 PXC0(c,r)                    = 1.0 ;

 ER0(r)                       = 1.0 ;

* ######## TRADE BLOCK

* #### Exports Block

PARAMETERS
* ## Initial values for variables
 PWE0(c,w,r)        World price of exports of comm'y c to region w

 QER0(c,w,r)        Exports of comm'y c to region w
 QE0(c,r)           Total exports of comm'y
 QD0(c,r)           Domestic demand for commodity c

* ## Parameters for CET functions
* CET in normal form

 mod_elaste(c,r)  Level 1 CET elasticities used in the model
 mod_elastre(c,r) Level 2 CET elasticities used in the model

 atr(c,r)         Shift param for CET over exports by aggregate region

 gammar(c,w,r)    Share parameter for CET over exports by region & aggregate

 rhoe(c,r)        Elast parameter for CET over exports by aggregate region

 at(c,r)          Shift parameter for CET function
 gamma(c,r)       Share parameter for CET function

 rhot(c,r)        Elasticity parameter for Output CET function

   ;

* #### Assignments

* ## Initial values for variables

 QER0(c,w,r)$cer(c,w,r)      = (SAMG(c,w,r)
                                  - SUM(ter$map_w_ter(w,ter), SAMG(ter,c,r)))
                                         /PER0(c,w,r) ;

* note that QEO is a CET of QER0 by region and PER0(c,wm,r) = 1
* as assigned earlier

 QE0(c,r)$PE0(c,r)       = SUM(w, PER0(c,w,r)*QER0(c,w,r))/PE0(c,r) ;

 PWE0(c,w,r)$QER0(c,w,r)     = (SAMG(c,w,r)/ER0(r))/QER0(c,w,r) ;

* QD0 = QXC0 - QE0
 QD0(c,r)      = (SUM(a,SAMG(a,c,r))/PXC0(c,r)) - QE0(c,r) ;

* ## Parameters for CET functions

$ontext
Choice of elasticities for Export transformation
  Selection controlled by value of mod_cont("cetelast")
   a) IF mod_cont("cetelast") = 1
        ALL elasticities for CET are from Excel

   b) IF mod_cont("cetelast") = 2
        Elast'ies for CET are from GTAP

$offtext

IF (mod_cont("cetelast") = 1,

 mod_elastre(c,r) = ELASTRE(c,r) ;

  ) ;

IF (mod_cont("cetelast") = 2,

 mod_elastre(c,r)   = ELASTRMG(c,r)/mod_cont("cetscal") ;

 mod_elastre(c,r)$(mod_elastre(c,r) GT 0.85 and mod_elastre(c,r) LE 1.0) = 0.85 ;
 mod_elastre(c,r)$(mod_elastre(c,r) GT 1.0 and mod_elastre(c,r) LT 1.15) = 1.15 ;

  ) ;

 rhoe(c,r)         = ((1/mod_elastre(c,r)) + 1) ;

$ontext
 Calibrate CET functions with an arbitrary number of trade partners
 AND explicitly exclude the globe because it has a homogeneous export
$offtext

* level 1

 gammar(c,w,r)$(cer(c,w,r) AND rgn(r))
                = (PER0(c,w,r)*QER0(c,w,r)**(1-rhoe(c,r)) ) /
                SUM(wp$cer(c,wp,r), PER0(c,wp,r)*QER0(c,wp,r)**(1-rhoe(c,r)) );

 atr(c,r)$(QE0(c,r) AND rgn(r))
                = QE0(c,r)/SUM(w, gammar(c,w,r)*QER0(c,w,r)
                           **(rhoe(c,r)) )**(1/(rhoe(c,r))) ;


*## FOR EXPORTS-DOMESTIC COMPOSITE

$ontext
Choice of elasticities for Export transformation
  Selection controlled by value of mod_cont("cetelast")
   a) IF mod_cont("cetelast") = 1
        ALL elasticities for CET are from Excel

   b) IF mod_cont("cetelast") = 2
        Elast'ies for CET are from GTAP

$offtext

IF (mod_cont("cetelast") = 1,

 mod_elaste(c,r)  = ELASTE(c,r) ;

  ) ;

IF (mod_cont("cetelast") = 2,

 mod_elaste(c,r)   = ELASTMG(c,r)/mod_cont("cetscal") ;

 mod_elaste(c,r)$(mod_elaste(c,r) GT 0.85 and mod_elaste(c,r) LE 1.0) = 0.85 ;
 mod_elaste(c,r)$(mod_elaste(c,r) GT 1.0 and mod_elaste(c,r) LT 1.15) = 1.15 ;

  ) ;

 rhot(c,r)$(cd(c,r) AND ce(c,r))    = (1/mod_elaste(c,r)) + 1 ;

 gamma(c,r)$(cd(c,r) AND ce(c,r))
              = 1/(1+PD0(c,r)/PE0(c,r)*(QE0(c,r)/QD0(c,r))**(rhot(c,r)-1));

* Using QXC0 = (SUM(a,SAMG(a,c,r))/PXC0(c,r))
 at(c,r)$(cd(c,r) AND ce(c,r))
              = (SUM(a,SAMG(a,c,r))/PXC0(c,r))/(gamma(c,r)*QE0(c,r)
                           **rhot(c,r) + (1-gamma(c,r))*
                       QD0(c,r)**rhot(c,r))**(1/rhot(c,r));

* #### Imports Block

PARAMETERS
* ## Initial values for variables
 PWM0(w,c,r)      World cif price of imports of comm'y c from region w
 PWMFOB0(w,c,r)   Imports of comm'y c from region w valued at fob prices

 QMR0(w,c,r)      Imports of comm'y c to region w
 QM0(c,r)         Total imports of comm'y
 QML0(c,r)        Supply of composite import from large share regions
 QMS0(c,r)        Supply of composite import from large share regions
 QQ0(c,r)         Supply of composite commodity c

 QT0(w,c,r)       Margin services on total imports from region w

* ## Parameters for Armington/CES functions
* CET in normal form
 mod_elastm(c,r)  Level 1 CES elasticities used in the model
 mod_elastrm(c,r) Level 2 CES elasticities used in the model

 acr(c,r)         Shift parameter for Armington CES over imports by aggregate region

 deltar(w,c,r)    Share parameter for Armington CES over imports by region & aggregate

 rhom(c,r)        Elast parameter for Armington CES over imports by aggregate region

 ac(c,r)          Shift parameter for Armington CES function

 delta(c,r)       Share parameter for Armington CES function

 rhoc(c,r)        Elasticity parameter for Armington CES function

* ## Parameters for Leontief functions

 ioqmlqm(c,r)     Share of QML in QM
 ioqmrqms(w,c,r)  Share of QMR in QMS
 ioqmsqm(c,r)     Share of QMS in QM

* ## Parameters for Trade margins
 margcor(w,c,cp,r)  Margin c per unit of r's import of commodity cp from region w

   ;

* #### Assignments

* ## Initial values for variables

 PWMFOB0(w,c,r)   = SUM((rp,wp)
                       $(MAPW_R(w,rp)
                        $MAPR_W(r,wp)),PWE0(c,wp,rp)) ;

 QMR0(w,c,r)$PWMFOB0(w,c,r)  = SAMG(w,c,r)/PWMFOB0(w,c,r) ;

 PMR0(w,c,r)$QMR0(w,c,r) = (SAMG(w,c,r)
                                + SUM(tmr$map_w_tmr(w,tmr),SAMG(tmr,c,r))
                                + SUM(tmrs$map_w_tmrs(w,tmrs),SAMG(tmrs,c,r))
                                + SUM(cp$ct(cp,r), IMPMARG(w,cp,c,r)) )
                               /QMR0(w,c,r) ;

 QML0(c,r)    = SUM(w$cmrl(w,c,r), PMR0(w,c,r)*QMR0(w,c,r)) ;

 QMS0(c,r)   = SUM(w$cmrs(w,c,r), PMR0(w,c,r)*QMR0(w,c,r)) ;

 QM0(c,r)$PM0(c,r)       = SUM(w, PMR0(w,c,r)*QMR0(w,c,r))/PM0(c,r) ;

*  QML0(c,r)   = QM0(c,r) - QMS0(c,r) ;

* Nested CES
* note that PMR0(c,w,r) = 1, as assigned earlier)
* note that QM0 is a CES of QMR by aggregate regions

Parameter
 QM02(c,r)   alternate calculation
 QM03(c,r)
;

 QM03(C,R)                = QML0(C,R) + QMS0(C,R) ;
 QM02(c,r)$PM0(c,r)       = SUM(w, PMR0(w,c,r)*QMR0(w,c,r))/PM0(c,r) ;

 QM0(c,r)$PM0(c,r)
             = ((PMS0(c,r)*QMS0(c,r)) + (PML0(c,r)*QML0(c,r)))/PM0(c,r) ;

Display QM0, QM02, QM03 ;

parameter QM02chk(c,r)
          qm03chk(c,r)
;

QM02chk(c,r) = QM02(c,r) - QM0(c,r) ;
QM03chk(c,r) = QM03(c,r) - QM0(c,r) ;

display qm02chk, QM03CHK ;

 PWM0(w,c,r)$QMR0(w,c,r)
             = (SAMG(w,c,r)+ SUM(cp$ct(cp,r), IMPMARG(w,cp,c,r)) )/
                               ER0(r)/QMR0(w,c,r) ;

 QQ0(c,r)                    = QD0(c,r) + QM0(c,r) ;

* ## Parameters for Armington/CES functions

$ontext
Choice of elasticities for Import substitution
  Selection controlled by value of mod_cont("ceselast")
   a) IF mod_cont("ceselast") = 1
        ALL elasticities for ARMINGTON are from Excel

   b) IF mod_cont("ceselast") = 2
        Elast'ies for ARMINGTON are from Excel - elastm and elastrm
$offtext

IF (mod_cont("armelast") = 1,

 mod_elastrm(c,r)   = ELASTRM(c,r) ;

  ) ;

IF (mod_cont("armelast") = 2,

 mod_elastrm(c,r)   = ELASTRMG(c,r)/mod_cont("armscal") ;

 mod_elastrm(c,r)$(mod_elastrm(c,r) GT 0.85 and mod_elastrm(c,r) LE 1.0) = 0.85 ;
 mod_elastrm(c,r)$(mod_elastrm(c,r) GT 1.0 and mod_elastrm(c,r) LT 1.15) = 1.15 ;

  ) ;

 rhom(c,r)         = ((1/mod_elastrm(c,r)) - 1) ;

* Level 2
* calibrate CES with an arbitrary number of trade partners

 deltar(w,c,r)$cmrl(w,c,r)
                 = (PMR0(w,c,r)*QMR0(w,c,r)**(1+rhom(c,r)) )
                    /SUM(wp$cmrl(wp,c,r), PMR0(wp,c,r)*QMR0(wp,c,r)
                     **(1+rhom(c,r)) ) ;

 acr(c,r)$QML0(c,r)   = QML0(c,r)/SUM(wp$cmrl(wp,c,r), deltar(wp,c,r)*QMR0(wp,c,r)
                                 **(-rhom(c,r)) )**(-1/rhom(c,r)) ;


* ## Parameters for Leontief functions

 ioqmlqm(c,r)$cm(c,r)          = QML0(c,r)/QM0(c,r) ;

 ioqmrqms(w,c,r)$cmrs(w,c,r)    = QMR0(w,c,r)/QMS0(c,r) ;

 ioqmsqm(c,r)$cm(c,r)          = QMS0(c,r)/QM0(c,r) ;


Parameter
deltarCHK(c,r)
ioqmrqmsCHK(c,r)
ioqmCHK(c,r) ;

 deltarCHK(c,r)    = SUM(w,deltar(w,c,r)) ;

 ioqmrqmsCHK(c,r)     = SUM(w,ioqmrqms(w,c,r)) ;

 ioqmCHK(c,r)         = ioqmlqm(c,r) + ioqmsqm(c,r) ;

Display  deltarCHK, ioqmrqmsCHK, ioqmCHK ;

*#### CALIBRATION OF SHIFT AND SHARE PARAMETERS FOR TRADE ####

*## FOR IMPORTS-DOMESTIC COMPOSITE

$ontext
Choice of elasticities for Import substitution
  Selection controlled by value of mod_cont("ceselast")
   a) IF mod_cont("ceselast") = 1
        ALL elasticities for ARMINGTON are from Excel

   b) IF mod_cont("ceselast") = 2
        Elast'ies for ARMINGTON are from Excel - elastm and elastrm

$offtext

IF (mod_cont("armelast") = 1,

* rhoc(c,r)$(cx(c,r) AND cm(c,r))    = (1/ELASTM(c,r)) - 1 ;
 mod_elastm(c,r)       = ELASTM(c,r) ;

  ) ;

IF (mod_cont("armelast") = 2,

* rhoc(c,r)$(cx(c,r) AND cm(c,r))    = (1/ELASTMG(c,r)) - 1 ;
 mod_elastm(c,r)       = ELASTMG(c,r)/mod_cont("armscal") ;

 mod_elastm(c,r)$(mod_elastm(c,r) GT 0.85 and mod_elastm(c,r) LE 1.0) = 0.85 ;
 mod_elastm(c,r)$(mod_elastm(c,r) GT 1.0 and mod_elastm(c,r) LT 1.15) = 1.15 ;

  ) ;


 rhoc(c,r)$(cx(c,r) AND cm(c,r))    = (1/mod_elastm(c,r)) - 1 ;

* generalized calibration of CES, allows an arbitrary number of arguments

 delta(c,r)$(cd(c,r) AND cm(c,r)) = (PM0(c,r)*QM0(c,r)**(1+rhoc(c,r)) )
                                     /(PM0(c,r)*QM0(c,r)**(1+rhoc(c,r))
                                     + PD0(c,r)*QD0(c,r)**(1+rhoc(c,r))) ;

 ac(c,r)$(cd(c,r) AND cm(c,r)) = QQ0(c,r)/(delta(c,r)*QM0(c,r)**(-rhoc(c,r))
                                        +(1-delta(c,r))*QD0(c,r)
                                  **(-rhoc(c,r)))**(-1/rhoc(c,r)) ;

Parameter qqcalib(c,r)
          qqdif(c,r) ;

qqcalib(c,r) = ac(c,r)* (delta(c,r)*QM0(c,r)**(-rhoc(c,r))
                                        +(1-delta(c,r))*QD0(c,r)
                                  **(-rhoc(c,r)))**(-1/rhoc(c,r));
qqdif(c,r) = qqcalib(c,r) - qq0(c,r) ;
display qqdif;


* ## Parameters for Trade margins

 QT0(w,c,r)$CT(c,r)          = SUM(cp, IMPMARG(w,c,cp,r))/PT0(c,r) ;

 margcor(w,c,cp,r)$QMR0(w,cp,r)
              = IMPMARG(w,c,cp,r)/PT0(c,r)/QMR0(w,cp,r) ;

* ######## COMMODITY PRICE BLOCK

PARAMETERS

* ## Initial values for variables

 PQS0(c,r)        Supply price of composite commodity c
 PQD0(c,r)        Consumer price of composite commodity c

  ;

* #### Assignments

* ## Initial values for variables

 PQS0(c,r)    = 1 ;

 PQD0(c,r)$QQ0(c,r)
              = (SAMG(c,"TOTAL",r)
                 - SUM(w, SAMG(c,w,r)) - SAMG("VATTAX",c,r) )/QQ0(c,r) ;

* ######## NUMERAIRE PRICE BLOCK

PARAMETERS

* ## Initial values for variables

 CPI0(r)         Consumer price index - Region numeraires
 PPI0(r)         Producer (domestic) price index - Region numeraires
 ERPI0           Exchange rate index - Global numeraire

* ## Price index weights

 comtotsh(c,r)    Share of commodity c in total commodity demand
 vddtotsh(c,r)    Share of value of domestic output for the domestic market

 tradtotsh(ref)   Share of total Exports by reference regions

  ;

* #### Assignments

* ## Initial values for variables

Parameter
 tv02(c,r)    VAT rates for initialisation ;

 tv02(c,r)$(SUM(h,SAMG(c,h,r)) - SAMG("VATTAX",c,r))
             = SAMG("VATTAX",c,r)/(SUM(h,SAMG(c,h,r)) - SAMG("VATTAX",c,r)) ;

 CPI0(r)$(SUM((c,h),SAMG(c,h,r)))
          = SUM(c,SUM(h,SAMG(c,h,r))/(SUM((cp,hp),SAMG(cp,hp,r)))
                                     *PQD0(c,r)*(1+tv02(c,r))) ;

 PPI0(r)$(SUM((ap,cp),SAMG(ap,cp,r)))
         = SUM(c,(SUM(a,SAMG(a,c,r))/SUM((ap,cp),SAMG(ap,cp,r)))*PD0(c,r)) ;

* tradtotsh(ref)          = SUM((c,w),SAMG(c,w,ref))
*                                /SUM((cp,wp,refp),SAMG(cp,wp,refp)) ;

 ERPI0   = SUM(ref,(SUM((c,w),SAMG(c,w,ref))
                /SUM((cp,wp,refp),SAMG(cp,wp,refp)))*ER0(ref)) ;

* ## Price index weights

* comtotsh and weights used to compute CPI0 (done above this line) must be identical

* note that the CPI weights are based on household expenditure shares ONLY

 comtotsh(c,r)$(SUM((cp,hp),SAMG(cp,hp,r)))
              = SUM(h,SAMG(c,h,r))/(SUM((cp,hp),SAMG(cp,hp,r))) ;

* alternate 1 - CPI weights based on final demand expenditure shares

* comtotsh(c)   = (SUM(h,SAM(c,h)) + SAM(c,"govt") + SAM(c,"kap"))
*                 /(SUM((cp,hp),SAM(cp,hp))
*                  + SUM(cp,SAM(cp,"govt"))
*                  + SUM(cp,SAM(cp,"kap")))  ;

* alternate 2 - CPI weights based on volume shares of domestic output

* comtotsh(c)   = QD0(c)/SUM(cp,QD0(cp)) ;

* PPI weights are based on the value of domestic output for the domestic market

 vddtotsh(c,r)$(SUM((ap,cp),SAMG(ap,cp,r)))
                = SUM(a,SAMG(a,c,r))/SUM((ap,cp),SAMG(ap,cp,r)) ;

* ERPI weights are based on shares of total trade by reference regions

* alternate 1 - ERPI weights based on export (fob) shares

 tradtotsh(ref)          = SUM((c,w),SAMG(c,w,ref))
                                /SUM((cp,wp,refp),SAMG(cp,wp,refp)) ;

* alternate 2 - ERPI weights based on import (cif) shares


* ######## PRODUCTION BLOCK

PARAMETERS

 PX0(a,r)       Composite price of output by activity a

* ## Initial values for variables

* CES aggregation functions for Level 1 of production nest

 PVA0(a,r)      Value added price for activity a in r
 PINT0(a,r)     Price of aggregate intermediate input

 QX0(a,r)       Domestic production by activity a in r
 QVA0(a,r)      Quantity of aggregate value added for level 1 production

* Leontief aggregation functions for Level 1 of production nest

 QINT0(a,r)     Agg quantity of intermediates used by activity a in r

* CES aggregation functions for Level 2 of production nest

 WF0(ff,r)       Price of factor f in r
 WFDIST0(ff,a,r) Sectoral proportion for factor prices in r
 FD0(ff,a,r)     Demand for factor f by activity a in r
 FS0(ff,r)       Supply of factor f in r

* Unemployment

 unemp_rate(f,r) Unemployment rates
 UNEMP0(f,r)     Unemployed labor

* Intermediate Input Demand

 QINTD0(c,r)    Demand for intermediate inputs by commodity in r

* Commodity Output

 QXC0(c,r)      Domestic production by commodity c in r

* Technology Parameters and Adjustment factors

 ADXADJ0(r)     Scaling Factor for Shift parameter on CES functions for QX
 DADX0(r)       Partial scaling factor for Shift parameter on CES functions for QX

 ADVAADJ0(r)    Scaling Factor for Shift parameter on CES functions for QVA
 DADVA0(r)      Partial scaling factor for Shift parameter on CES functions for QVA

 ADFDfADJ0(f)   Factor Scaling Factor for flow parameter on ADFD
 ADFDaADJ0(a)   Activity Scaling Factor for flow parameter on ADFD
 ADFDrADJ0(r)   Region Scaling Factor for flow parameter on ADFD

* CES aggregation functions for Level 1 of production nest

 mod_elastx(a,r) Level 1 CES elasticities used in the model

 ADX0(a,r)      Initial Shift parameter for CES production functions for QX in r
 adxb(a,r)      Base Shift parameter for CES production functions for QX in r
 dabadx(a,r)    Change in base shift parameter on functions for QX
 adx01(a,r)     0-1 par for flexing of shift parameter on functions for QX

 deltax(a,r)    Share parameter for CES production functions for QX in r
 rhox(a,r)      Elasticity parameter for CES production function for QX in r
 thetax(a,r)    Share of QVA in QX

* Leontief aggregation functions for Level 1 of production nest

 use(c,a,r)      use matrix transactions
 ioqx(c,a,r) use matrix coefficients

 ioqintqx(a,r)  Agg intermed quantity per unit QX for Level 1 Leontief agg
 ioqvaqx(a,r)   Agg value added quant per unit QX for Level 1 Leontief agg

* CES aggregation functions for Level 2 of production nest

 mod_elastva(a,r) Level 2 CES elasticities used in the model

 ADVA0(a,r)     Initial Shift parameter for CES production functions for QVA
 advab(a,r)     Base Shift parameter for CES production functions for QVA
 dabadva(a,r)   Change in base shift parameter on functions for QVA
 adva01(a,r)    0-1 par for flexing of shift parameter on functions for QVA

 deltava(ff,a,r) Share parameters for CES production functions for QVA
 rhova(a,r)    Elasticity parameter for CES production function for QVA
 thetava(f,a,r) Share of primary factor in QVA

 ADFD0(ff,a,r)   Initial Shift parameter for factor and activity specific efficiency
 adfdb(f,a,r)   Base Shift parameter for factor and activity specific efficiency
 dadfd(f,a,r)   Change in shift parameter for factor and activity specific efficiency

 adfag(ff,a,r)       Shift parameter for factor and activity specific efficiency
 ELASTFD(ff,a,r)     Production elasticities indexed on aggregate factors
 rhofd(ff,a,r)       Elasticity parameter for CES prodn fns for Aggregated FD
 deltafd(ff,ff,a,r)  CES Share parameters for Aggregated FD fag using ff by a
 deltafdchk(ff,a,r)

* Intermediate Input Demand

 ioqint(c,a,r) intermediate input output coefficients

* Activity Output

 ioqxcqx(a,c,r) Share of commodity c in output by activity a

  ;

* #### Assignments

* ## Initial values for variables

 QX0(a,r)$PX0(a,r)      = SAMG("TOTAL",a,r)/PX0(a,r) ;
 QXC0(c,r)$PXC0(c,r)    = SUM(a,SAMG(a,c,r))/PXC0(c,r) ;

*(SAMG(c,"TOTAL",r) - SUM(w, SAMG(c,w,r)) )/QQ0(c,r)

 QINT0(a,r)$SUM(c,SAMG(c,a,r))   = SUM(c,SAMG(c,a,r)/PQD0(c,r)) ;

 QVA0(a,r)              = SUM(f,SAMG(f,a,r)) ;

 PINT0(a,r)$(QINT0(a,r))
                        = SUM(c,(SAMG(c,a,r)/PQD0(c,r)/QINT0(a,r))
                                               * PQD0(c,r)) ;

 PVA0(a,r)$QVA0(a,r)    = ( SUM(f,SAMG(f,a,r))+ SUM(tff, SAMG(tff,a,r)) )
                            /QVA0(a,r) ;

 QINTD0(c,r)$SUM(a,SAMG(c,a,r))  = SUM(a,SAMG(c,a,r)/PQD0(c,r)) ;

 FD0(f,a,r)              = FACTUSE(f,a,r) ;
 FS0(f,r)                = SUM(a,FACTUSE(f,a,r)) ;

* Unemployment

 UNEMP0(f,r)             = 0.0 ;

* assert a value for unskilled labor, here 1% of working labor force
* then redefine the total factor supply as the total available
* factor supply, those working and those unemployed.
* Also, calibrate WF0 using the number working which now can be different
* than FS0, the number available to work

 unemp_rate(f,r)       = un_rate(r,f) ;

Display unemp_rate ;

 UNEMP0(f,r)$UEF(f,r)  = unemp_rate(f,r)*FS0(f,r) ;

 FS0(f,r)              = SUM(a,FACTUSE(f,a,r)) + UNEMP0(f,r) ;

 WF0(f,r)$SUM(a, FD0(f,a,r))
                       = SUM(a,SAMG(f,a,r))/SUM(a, FD0(f,a,r)) ;

 WFDIST0(f,a,r)$FD0(f,a,r)
                         = (SAMG(f,a,r)/FD0(f,a,r))/WF0(f,r) ;
 WFDIST0(f,a,r)$(FD0(f,a,r) EQ 0)
                         = 0.0 ;
* assign values for the un-natural factors

 FD0(fag,a,r)  = SUM(f$map_fag_f(fag,f),FACTUSE(f,a,r))  ;

 FS0(fag,r)    = SUM(a,FD0(fag,a,r)) ;

 WF0(fag,r)$(FS0(fag,r)) = 1.0 ;


 WFDIST0(fag,a,r)$FD0(fag,a,r)
             = SUM(f$map_fag_f(fag,f),SAMG(f,a,r))/FD0(fag,a,r)/WF0(fag,r) ;

 WFDIST0(fag,a,r)$(FD0(fag,a,r) EQ 0) = 0.0 ;

 QINTD0(c,r)$PQD0(c,r)    = SUM(a,SAMG(c,a,r)/PQD0(c,r)) ;

* Technology Parameters and Adjustment factors

 ADXADJ0(r)       = 1.0 ;
 DADX0(r)         = 0.0 ;

 ADVAADJ0(r)      = 1.0 ;
 DADVA0(r)        = 0.0 ;

 ADFDfADJ0(f)     = 1.0 ;
 ADFDaADJ0(a)     = 1.0 ;
 ADFDrADJ0(r)     = 1.0 ;

* ADFD0(f,a,r)     = 1.0 ;

* CES aggregation functions for Level 1 of production nest

$ontext
Choice of elasticities for substitution at Level 1 Production Function
  Selection controlled by value of mod_cont("qxelast")
   a) IF mod_cont("qxelast") = 1
        ALL elasticities for Level 1 Production are from Excel - ELASTX

   b) IF mod_cont("qxelast") = 2
        Elast'ies for Level 1 Production are from GTAP - ELASTVAG/qxscal

$offtext

IF (mod_cont("qxelast") = 1,

 mod_elastx(a,r)   = ELASTX(a,r) ;

  ) ;

IF (mod_cont("qxelast") = 2,

 mod_elastx(a,r)   = ELASTVAG(a,r)/mod_cont("qxscal") ;

 mod_elastx(a,r)$(mod_elastx(a,r) GT 0.95 and mod_elastx(a,r) LE 1.0) = 0.95 ;
 mod_elastx(a,r)$(mod_elastx(a,r) GT 1.0 and mod_elastx(a,r) LT 1.05) = 1.05 ;

  ) ;

 rhox(a,r)    = (1/mod_elastx(a,r)) - 1 ;

 deltax(a,r)$(QINT0(a,r))
               = (PVA0(a,r)*QVA0(a,r)**(1+rhox(a,r)) )
                   /(PVA0(a,r)*QVA0(a,r)**(1+rhox(a,r))
                      + PINT0(a,r)*QINT0(a,r)**(1+rhox(a,r))) ;

 ADX0(a,r)$deltax(a,r)
           = QX0(a,r)/(deltax(a,r)*QVA0(a,r)**(-rhox(a,r))
             +(1-deltax(a,r))*QINT0(a,r)**(-rhox(a,r)))**(-1/rhox(a,r)) ;

 adxb(a,r)       = ADX0(a,r) ;
 dabadx(a,r)     = 0.0 ;
 adx01(a,r)      = 0.0 ;

 thetax(a,r)$deltax(a,r)  = PVA0(a,r)*QVA0(a,r)/
                            (PINT0(a,r)*QINT0(a,r) + PVA0(a,r)*QVA0(a,r) ) ;

* Leontief aggregation functions for Level 1 of production nest

 use(c,a,r)$SAMG("TOTAL",a,r)
               = SAMG(c,a,r)/SAMG("TOTAL",a,r) ;

 ioqx(c,a,r)$(QX0(a,r) AND PQD0(c,r))
               = (SAMG(c,a,r)/PQD0(c,r))/QX0(a,r) ;

 ioqintqx(a,r)$QX0(a,r)   = QINT0(a,r)/QX0(a,r) ;

 ioqvaqx(a,r)$QX0(a,r)    = QVA0(a,r)/QX0(a,r) ;

* CES aggregation functions for Level 2 of production nest

$ontext
Choice of elasticities for substitution at Level 2 Production Function
  Selection controlled by value of mod_cont("qvaelast")
   a) IF mod_cont("qvaelast") = 1
        ALL elasticities for Level 2 Production are from Excel - ELASTVA

   b) IF mod_cont("qvaelast") = 2
        Elast'ies for Level 2 Production are from GTAP - ELASTVAG

$offtext

IF (mod_cont("qvaelast") = 1,

 mod_elastva(a,r)   = ELASTVA(a,r) ;

  ) ;

IF (mod_cont("qvaelast") = 2,

 mod_elastva(a,r)   = ELASTVAG(a,r) ;

 mod_elastva(a,r)$(mod_elastva(a,r) GT 0.95 and mod_elastva(a,r) LE 1.0) = 0.95 ;
 mod_elastva(a,r)$(mod_elastva(a,r) GT 1.0 and mod_elastva(a,r) LT 1.05) = 1.05 ;

  ) ;

 rhova(a,r)   = (1/mod_elastva(a,r)) - 1 ;

Parameter

 tf02(ff,a,r)  tf for calibration of production functions
  ;

 tf02(f,a,r)$SAMG(f,a,r)     = ((SUM(tff$map_f_tff(f,tff),SAMG(tff,a,r)))
                                 /SAMG(f,a,r)) ;

 tf02(fag,a,r)$SUM(f$map_fag_f(fag,f),SAMG(f,a,r)  )
                             =  SUM(f$map_fag_f(fag,f),SAMG(f,a,r)*tf02(f,a,r))/
                                SUM(f$map_fag_f(fag,f),SAMG(f,a,r)  ) ;

* share parameters WITH factor use taxes - tf0(f,a,r)

 deltava(f2,a,r)$FD0(f2,a,r)
          = (WFDIST0(f2,a,r)*WF0(f2,r)*(1+tf02(f2,a,r))*(FD0(f2,a,r))**(1+rhova(a,r)))
            /SUM(f2p,WFDIST0(f2p,a,r)*WF0(f2p,r)*(1+tf02(f2p,a,r))*(FD0(f2p,a,r))
             **(1+rhova(a,r))) ;

 ADVA0(a,r)$SUM(f2,FD0(f2,a,r))
          = QVA0(a,r)/(SUM(f2$(FD0(f2,a,r)),deltava(f2,a,r)*FD0(f2,a,r)
                 **(-rhova(a,r))))**(-1/rhova(a,r));

 advab(a,r)      = ADVA0(a,r) ;
 dabadva(a,r)    = 0.0 ;
 adva01(a,r)     = 0.0 ;

 thetava(f,a,r)$SAMG(f,a,r)
          = WFDIST0(f,a,r)*WF0(f,r)*(1+tf02(f,a,r))*(FD0(f,a,r))/
            SUM(fp,WFDIST0(fp,a,r)*WF0(fp,r)*(1+tf02(f,a,r))*FD0(fp,a,r)) ;

 ADFD0(ff,a,r)    = 1.0 ;
 adfdb(f,a,r)     = ADFD0(f,a,r) ;
 dadfd(f,a,r)     = 0.0 ;


* ELASTFD(fag,a,r) = 2 ;

 rhofd(fag,a,r)   = (1/ELASTFD(fag,a,r)) - 1 ;

 deltafd(f2ag,f3,a,r)$(map_f2ag_f3(f2ag,f3) AND rgn(r))
            = (WFDIST0(f3,a,r)*WF0(f3,r)*(1+tf02(f3,a,r))*(FD0(f3,a,r))
                       **(1+rhofd(f2ag,a,r)))
                        / SUM(f3p$map_f2ag_f3(f2ag,f3p),WFDIST0(f3p,a,r)*WF0(f3p,r)
                      *(1+tf02(f3p,a,r))*(FD0(f3p,a,r))**(1+rhofd(f2ag,a,r))) ;

 adfag(f,a,r) = 1 ;

 adfag(f2ag,a,r)$(SUM(f3$map_f2ag_f3(f2ag,f3), FD0(f3,a,r)))
                = FD0(f2ag,a,r)
                  /(SUM(f3$(FD0(f3,a,r) NE 0 ) ,deltafd(f2ag,f3,a,r)*FD0(f3,a,r)
                  **(-rhofd(f2ag,a,r))))**(-1/rhofd(f2ag,a,r)) ;

 deltafdCHK(f2ag,a,r)  = SUM(f3$map_f2ag_f3(f2ag,f3),deltafd(f2ag,f3,a,r)) ;

display adfag, deltafdCHK ;

* Intermediate Input Demand

 ioqint(c,a,r)$(QINT0(a,r) AND PQD0(c,r))
               = SAMG(c,a,r)/PQD0(c,r)/QINT0(a,r) ;

* Activity Output

 ioqxcqx(a,c,r)$acx(a,r)         = SAMG(a,c,r)/SUM(cp,SAMG(a,cp,r)) ;

* ######## FACTOR BLOCK

PARAMETERS

* ## Initial values for variables

 YF0(f,r)        Income to factor f
 YFDIST0(f,r)    Factor income for distribution after depreciation

* ## Savings Expenditures

 deprec(f,r)      depreciation rate by factor f on stock of factor f

* ## Transfer Expenditures

 hvash(h,f,r)     Share of income from factor f to household h

  ;

* #### Assignments

* ## Initial values for variables

 YF0(f,r)      = SAMG("TOTAL",f,r) ;
 YFDIST0(f,r)  = (SAMG("TOTAL",f,r) - SAMG("KAP",f,r) - SAMG("DIRTAX",f,r)) ;

* ## Savings Expenditures

 deprec(f,r)$SAMG("TOTAL",f,r)     = SAMG("KAP",f,r)/SAMG("TOTAL",f,r) ;

* ## Transfer Expenditures

 hvash(h,f,r)$SAMG("TOTAL",f,r)    = SAMG(h,f,r)/
                    (SAMG("TOTAL",f,r) - SAMG("KAP",f,r) - SAMG("DIRTAX",f,r)) ;

* ######## HOUSEHOLD BLOCK

PARAMETERS

* ## Initial values for variables

 YH0(h,r)        Income to household h
 HEXP0(h,r)      Household consumption expenditure

 QCD0(c,h,r)     Household consumption by commodity c

* ## Transfer Expenditures

* ## Consumption Expenditures
* # Cobb Douglas Utility function

 comhav(c,h,r)    Household consumption shares

* # Stone-Geary Utility function

 sumelast(h,r)    Weighted sum of income elasticities
 yhelast(c,h,r)   (Normalised) household income elasticities
 beta(c,h,r)      Marginal budget shares
 hexps(h,r)       Subsistence consumption expenditure
 frisch(h,r)      Elasticity of the marginal utility of income
 qcdconst(c,h,r)  Volume of subsistence consumption

  ;

* #### Assignments

* ## Initial values for variables

 YH0(h,r)               = SAMG("TOTAL",h,r) ;

 HEXP0(h,r)             = SUM(c,SAMG(c,h,r)) ;
 QCD0(c,h,r)$PQD0(c,r)  = SAMG(c,h,r)/(PQD0(c,r)*(1+tv02(c,r))) ;

* ## Transfer Expenditures


* ## Consumption Expenditures
* # Cobb Douglas Utility function

 comhav(c,h,r)$HEXP0(h,r)   = SAMG(c,h,r)/SUM(cp,SAMG(cp,h,r)) ;

* # Stone-Geary Utility function
$ontext
 Weighted sum of the expenditures elasticities must equal one.
 Weights are average budget shares. Normalised elasticities will satisfy
 Engel aggregation
$offtext

 sumelast(h,r)   = SUM(c, comhav(c,h,r)*ELASTY(c,h,r)) ;

 yhelast(c,h,r)$sumelast(h,r)
               = ELASTY(c,h,r)/sumelast(h,r) ;

 yhelast(c,h,r)$(comhav(c,h,r) eq 0)  = 0 ;

 beta(c,h,r)     = yhelast(c,h,r)*comhav(c,h,r) ;

 frisch(h,r)     = ELASTF(r,h) ;

 qcdconst(c,h,r)$(PQD0(c,r) and frisch(h,r))
               = (HEXP0(h,r)/(PQD0(c,r)*(1+tv02(c,r))) )
                  *(comhav(c,h,r)+(beta(c,h,r)/frisch(h,r))) ;

 hexps(h,r)      = SUM(c,qcdconst(c,h,r) * PQD0(c,r)*(1+tv02(c,r))) ;

* ######## GOVERNMENT BLOCK

* #### Government Income Block

* ## Government Taxes

PARAMETERS
* ## Initial values for overall scaling variables
 TEADJ0(r)       Export subsidy Scaling Factor
 TMADJ0(r)       Ad valorem Tarrif rate Scaling Factor
 TMSADJ0(r)      Specific Tarrif rate Scaling Factor
 TSADJ0(r)       Sales tax rate scaling factor
 TVADJ0(r)       Value added tax rate scaling factor
 TXADJ0(r)       Indirect Tax Scaling Factor
 TYFADJ0(r)      Factor income Tax Scaling Factor
 TYHADJ0(r)      Income Tax Scaling Factor
 TFADJ0(r)       Factor Use Tax Scaling Factor

* ## Initial values for partial scaling variables
 DTE0(r)         Uniform Export tax rate scaling factor
 DTM0(r)         Uniform Tariff rate scaling factor
 DTMS0(r)        Uniform adjustment to Specific Tariff rates
 DTS0(r)         Uniform Sales tax rate scaling factor
 DTV0(r)         Uniform Value added tax rate scaling factor
 DTX0(r)         Uniform Indirect tax rate scaling factor
 DTYF0(r)        Uniform direct tax on factor rate scaling factor
 DTYH0(r)        Uniform direct tax on household rate scaling factor
 DTF0(r)         Uniform adjustment to factor use tax by activity

* ## Initial tax revenues
 MTAX0(r)        Ad valorem Tariff revenue
 MSTAX0(r)       Specific Import tariff revenue
 ETAX0(r)        Export tax revenue
 STAX0(r)        Sales tax revenue
 VTAX0(r)        Value added taxes
 ITAX0(r)        Indirect tax revenue
 FYTAX0(r)       Factor income tax revenue
 HTAX0(r)        Household income tax
 FTAX0(r)        Factor use tax revenue

* ## base tax rates

 teb(c,w,r)      Export tax rates on exports of comm'y c to region w
 tmb(w,c,r)      Ad valorem Tariff rates on comm'y imported from region w
 tmsb(w,c,r)     Specific Tariff rates on comm'y imported from region w
 tsb(c,r)        Base sales tax rate
 tvb(c,r)        Base Value added tax rates
 txb(a,r)        Base indirect tax rate on activity a
 tyfb(f,r)       Factor income tax rate
 tyhb(h,r)       Direct tax rate on household h
 tfb(ff,a,r)     Factor use tax rate

 TE0(c,w,r)      Export tax rates on exports of comm'y c to region w
 TM0(w,c,r)      Ad valorem Tariff rates on comm'y imported from region w
 TMS0(w,c,r)     Specific Tariff rates on imported comm'y c from w by r
 TS0(c,r)        Base sales tax rate
 TV0(c,r)        Base Value added tax rates
 TX0(a,r)        Base indirect tax rate on activity a
 TYF0(f,r)       Factor income tax rate
 TYH0(h,r)       Direct tax rate on household h
 TF0(ff,a,r)     Factor use tax rate

 tmreal(w,c,r)   Real tariff rates by commodity and region

* ## absolute changes in base tax rates

 dabte(c,w,r)    Change in base export taxes on comm'y from regn
 dabtm(w,c,r)    Change in base Ad valorem tariffs on comm'y imptd by regn
 dabtms(w,c,r)   Change in base Specific tariffs on comm'y imptd by regn
 dabts(c,r)      Change in base sales tax rate
 dabtv(c,r)      Change in base value added tax rate
 dabtx(a,r)      Change in base indirect tax rate
 dabtyf(f,r)     Change in base direct tax rate on factors
 dabtyh(h,r)     Change in base direct tax rate on households
 dabtf(ff,a,r)   Change in base factor us tax rate on activities

* ## partial changes in tax rates

 te01(c,w,r)     0-1 par for flexing of export taxes on comm'ies
 tm01(w,c,r)     0-1 par for flexing of Ad valorem Tariff rates on comm'ies
 tms01(w,c,r)    0-1 par for flexing of Specific Tariff rates on comm'ies
 ts01(c,r)       0-1 par for flexing of sales tax rates
 tv01(c,r)       0-1 par for flexing of value added tax rates
 tx01(a,r)       0-1 par for flexing of indirect tax rates
 tyf01(f,r)      0-1 par for flexing of direct tax rates on factors
 tyh01(h,r)      0-1 par for flexing of direct tax rates on h'holds
 tf01(ff,a,r)    0-1 par for flexing of factor use tax rates

  ;

* #### Assignments

* ## Initial values for scaling variables
 TEADJ0(r)       = 1.0 ;
 TMADJ0(r)       = 1.0 ;
 TMSADJ0(r)      = 1.0 ;
 TSADJ0(r)       = 1.0 ;
 TVADJ0(r)       = 1.0 ;
 TXADJ0(r)       = 1.0 ;
 TYFADJ0(r)      = 1.0 ;
 TYHADJ0(r)      = 1.0 ;
 TFADJ0(r)       = 1.0 ;

* ## Initial values for partial scaling variables

 DTE0(r)         = 0.0 ;
 DTM0(r)         = 0.0 ;
 DTMS0(r)        = 0.0 ;
 DTS0(r)         = 0.0 ;
 DTV0(r)         = 0.0 ;
 DTX0(r)         = 0.0 ;
 DTYF0(r)        = 0.0 ;
 DTYH0(r)        = 0.0 ;
 DTF0(r)         = 0.0 ;

* ## Initial tax revenues
 MTAX0(r)       = SUM((c,w), SUM(tmr$map_w_tmr(w,tmr), SAMG(tmr,c,r))) ;
 MSTAX0(r)      = SUM((c,w), SUM(tmrs$map_w_tmrs(w,tmrs), SAMG(tmrs,c,r))) ;
 ETAX0(r)       = SUM((c,w), SUM(ter$map_w_ter(w,ter), SAMG(ter,c,r))) ;
 STAX0(r)       = SUM(c,SAMG("SALTAX",c,r)) ;
 VTAX0(r)       = SUM(c,SAMG("VATTAX",c,r)) ;
 ITAX0(r)       = SUM(a,SAMG("PRODTAX",a,r)) ;
 FYTAX0(r)      = SUM(f,SAMG("DIRTAX",f,r)) ;
 HTAX0(r)       = SUM(h,SAMG("DIRTAX",h,r)) ;
 FTAX0(r)       = SUM((f,a),SUM(tff$map_f_tff(f,tff),SAMG(tff,a,r))) ;

* ## tax rates

 TE0(c,w,r)$cer(c,w,r)        = SUM(ter$map_w_ter(w,ter), SAMG(ter,c,r))
                                 /SAMG(c,w,r) ;

 TM0(w,c,r)$cmr(w,c,r)        = SUM(tmr$map_w_tmr(w,tmr), SAMG(tmr,c,r))
                                 /(SAMG(w,c,r)
                                   + SUM(cp$ct(cp,r),IMPMARG(w,cp,c,r))) ;

 TMS0(w,c,r)$cmr(w,c,r)       = SUM(tmrs$map_w_tmrs(w,tmrs), SAMG(tmrs,c,r))
                                 /QMR0(w,c,r) ;

 TS0(c,r)$(SUM(a,SAMG(c,a,r)) + SUM(h,SAMG(c,h,r)) + SAMG(c,"GOVT",r)
                              + SAMG(c,"KAP",r) - SAMG("SALTAX",c,r)
                                        - SAMG("VATTAX",c,r))
                 = SAMG("SALTAX",c,r)/(SUM(a,SAMG(c,a,r))
                                       + SUM(h,SAMG(c,h,r))
                                       + SAMG(c,"GOVT",r)
                                       + SAMG(c,"KAP",r)
                                       - SAMG("SALTAX",c,r)
                                       - SAMG("VATTAX",c,r) ) ;


 TV0(c,r)$(SUM(h,SAMG(c,h,r)) - SAMG("VATTAX",c,r))
             = SAMG("VATTAX",c,r)/(SUM(h,SAMG(c,h,r)) - SAMG("VATTAX",c,r));

 TX0(a,r)$SAMG("TOTAL",a,r)
             = SAMG("PRODTAX",a,r)/SAMG("TOTAL",a,r) ;

 TYF0(f,r)$(SAMG("TOTAL",f,r) - SAMG("KAP",f,r))
             = SAMG("DIRTAX",f,r)/(SAMG("TOTAL",f,r) - SAMG("KAP",f,r)) ;

 TYH0(h,r)$SAMG("TOTAL",h,r)
             = SAMG("DIRTAX",h,r)/SAMG("TOTAL",h,r) ;

 TF0(f,a,r)$SAMG(f,a,r)     = SUM(tff$map_f_tff(f,tff),SAMG(tff,a,r))
                               /SAMG(f,a,r) ;

 TF0(fag,a,r)$SUM(f$map_fag_f(fag,f),SAMG(f,a,r)  )
                             =  SUM(f$map_fag_f(fag,f),SAMG(f,a,r)*tf0(f,a,r))/
                                SUM(f$map_fag_f(fag,f),SAMG(f,a,r)  ) ;

 tmreal(w,c,r)               = tm0(w,c,r)*PWM0(w,c,r)*ER0(r) ;

 teb(c,w,r)     = TE0(c,w,r) ;
 tmb(w,c,r)     = TM0(w,c,r) ;
 tmsb(w,c,r)    = TMS0(w,c,r) ;
 tsb(c,r)       = TS0(c,r) ;
 tvb(c,r)       = TV0(c,r) ;
 txb(a,r)       = TX0(a,r) ;
 tyfb(f,r)      = TYF0(f,r) ;
 tyhb(h,r)      = TYH0(h,r) ;
 tfb(ff,a,r)    = TF0(ff,a,r) ;

* ## absolute changes in base tax rates

 dabte(c,w,r)   = 0.0 ;
 dabtm(w,c,r)   = 0.0 ;
 dabtms(w,c,r)  = 0.0 ;
 dabts(c,r)     = 0.0 ;
 dabtv(c,r)     = 0.0 ;
 dabtx(a,r)     = 0.0 ;
 dabtyf(f,r)    = 0.0 ;
 dabtyh(h,r)    = 0.0 ;
 dabtf(ff,a,r)  = 0.0 ;

* ## partial changes in tax rates

 te01(c,w,r)    = 1.0 ;
 tm01(w,c,r)    = 1.0 ;
 tms01(w,c,r)   = 1.0 ;
 ts01(c,r)      = 1.0 ;
 tv01(c,r)      = 1.0 ;
 tx01(a,r)      = 1.0 ;
 tyf01(f,r)     = 1.0 ;
 tyh01(h,r)     = 1.0 ;
 tf01(ff,a,r)   = 1.0 ;

* #### Government Income and Expenditure Block

PARAMETERS
* ## Initial values for scaling variables

 QGDADJ0(r)      Government consumption demand scaling factor

* ## Initial values for variables

 YG0(r)          Government income
 QGD0(c,r)       Government consumption demand
 EG0(r)          Expenditure by government

* ## Transfer Expenditures

* ## Consumption Expenditures

 qgdconst(c,r)  Government demand volume
 qgdconst0(c,r) Initial Government demand volume

  ;

* #### Assignments

* ## Initial values for scaling variables

 QGDADJ0(r)  = 1.0 ;

* ## Initial values for variables

 YG0(r)                  = SAMG("TOTAL","GOVT",r) ;
 QGD0(c,r)$PQD0(c,r)     = SAMG(c,"GOVT",r)/PQD0(c,r) ;

 EG0(r)                  = YG0(r) - SAMG("kap","govt",r) ;

* ## Transfer Expenditures


* ## Consumption Expenditures

 qgdconst(c,r)$PQD0(c,r) = SAMG(c,"GOVT",r)/PQD0(c,r) ;

 qgdconst0(c,r)          = qgdconst(c,r) ;

* ######## KAPITAL BLOCK

PARAMETERS
* ## Initial values for scaling variables

 SADJ0(r)        Savings rate scaling factor
 IADJ0(r)        Investment scaling factor
 DSHH0(r)        Partial household savings rate scaling factor

* ## Initial values for variables

 INVEST0(r)      Total investment expenditure
 QINVD0(c,r)     Investment consumption by commodity c
 TOTSAV0(r)      Total savings

* ## base savings rates
 shh0(h,r)       Initial Household saving rates
 shhb(h,r)       Base Household saving rates

* ## absolute changes in base savings rates

 dabshh(h,r)     Change in base Household saving rates

* ## partial changes in savings rates
 shh01(h,r)      0-1 par for potential flexing of Household saving rates

* ## Consumption Expenditures

 qinvdconst(c,r)    Investment demand volume
 qinvdconst0(c,r)   Initial Investment demand volume

  ;

* #### Assignments

* ## Initial values for scaling variables

 SADJ0(r)      = 1.0 ;
 IADJ0(r)      = 1.0 ;

 DSHH0(r)      = 0.0 ;

* ## Initial values for variables

 QINVD0(c,r)$PQD0(c,r) = SAMG(c,"KAP",r)/PQD0(c,r) ;
 INVEST0(r)            = SAMG("TOTAL","KAP",r) ;
 TOTSAV0(r)            = SAMG("KAP","TOTAL",r) ;

* ## base savings rates

 shh0(h,r)$SAMG("TOTAL",h,r)
                      = SAMG("KAP",h,r)
                        /(SAMG("TOTAL",h,r) - SAMG("DIRTAX",h,r)) ;

 shhb(h,r)      = shh0(h,r) ;

* ## absolute changes in base savings rates

 dabshh(h,r)          = 0.0 ;

* ## partial changes in savings rates

 shh01(h,r)           = 0.0 ;

* ## Consumption Expenditures

 qinvdconst(c,r)$PQD0(c,r)   = SAMG(c,"KAP",r)/PQD0(c,r) ;
 qinvdconst0(c,r)            = qinvdconst(c,r) ;

* ######## FOREIGN INSTITUTIONS BLOCK

*PARAMETERS

* ## Initial values for variables

* ## Savings Expenditures

* ## Transfer Expenditures


* #### Assignments

* ## Initial values for variables


* ## Transfer Expenditures


* ######## MARKET CLEARING BLOCK

PARAMETERS
* ## Initial values for variables

* # Account Closure

 KAPGOV0(r)      Government Savings
 KAPWOR0(r)      Current account balance
 KAPREG0(w,r)    Bilateral current account balance

* # Absorption Closure

 VFDOMD0(r)      Value of final domestic demand
 INVESTSH0(r)    Value share of investment in total final dom demand
 VGDSH0(r)       Value share of Govt consump in total final dom demand

* ##### Macroeconomic Aggregates

 GDP0(r)         Gross Domestic Product by Expenditure definition

* # Slack

 WALRAS0(r)      Slack variable for Walras's Law
 KAPWORSYS0      Slack variable for global system for regions
 GLOBESLACK0     Slack variable for Globe

  ;

* #### Assignments

* ## Initial values for variables
* # Account Closure

 KAPGOV0(r)    = SAMG("KAP","GOVT",r) ;
 KAPWOR0(r)    = SUM(w, SAMG("KAP",w,r)) ;
 KAPREG0(w,r)  = SAMG("KAP",w,r) ;


* # Absorption Closure

 VFDOMD0(r)    = SUM((c,h),SAMG(c,h,r))
                  + SUM(c,SAMG(c,"GOVT",r))
                  + SUM(c,SAMG(c,"KAP",r)) ;

 INVESTSH0(r)$VFDOMD0(r)
               = SUM(c,SAMG(c,"KAP",r))/VFDOMD0(r) ;

 VGDSH0(r)$VFDOMD0(r)
               = SUM(c,SAMG(c,"GOVT",r))/VFDOMD0(r) ;

* ##### Macroeconomic Aggregates

 GDP0(r) = (SUM(c,PQD0(c,r) * (1+TV0(c,r)) * SUM(h,QCD0(c,h,r))))
                   + (SUM(c,PQD0(c,r) * (QGD0(c,r) + QINVD0(c,r))))
                   + (SUM(c,PE0(c,r) * QE0(c,r)))
                   - (SUM(c,PM0(c,r) * QM0(c,r))) ;

* # Slack

 WALRAS0(r)   = 0 ;
 KAPWORSYS0   = SUM(r, KAPWOR0(r))    ;
 GLOBESLACK0  = 0 ;


* ------ VARIOUS CHECKS FOR CALIBRATION OF PARAMETERS

 OPTION decimals = 6 ;

* TEST FOR ZEROES
PARAMETER
 TOTCON(r)           Total consumption
 TOTPROD(r)          Total production
 HCON(c,r)           Household consumption

 deltavacheck(a,r)   Check on deltava

 gammarchk(c,r)      Check on gammar

 checkcomtotsh(r)    Check on CPI weights

  ;

 TOTCON(r)           = SUM((c,h),SAMG(c,h,r)) ;
 TOTPROD(r)          = SUM((ap,cp),SAMG(ap,cp,r)) ;

 deltavacheck(a,r)   = SUM(f,deltava(f,a,r)) ;

 gammarchk(c,r)      = sum(w, gammar(c,w,r)) ;

 checkcomtotsh(r)    = SUM(c,comtotsh(c,r)) ;

 display deltavacheck,
         checkcomtotsh,
         gammarchk ;


* CALIBRATION CHECK

 PARAMETER
 QMCALIB(c,r)       CALIBRATED VALUE OF QM0
 QMDIFF(c,r)        DIFFERENCE BETWEEN CALIBRATED AND ACTUAL QM0
 QECALIB(c,r)       CALIBRATED VALUE OF QE0
 QEDIFF(c,r)        DIFFERENCE BETWEEN CALIBRATED AND ACTUAL QE0

;
$ontext
 QMCALIB(c,r) = acr(c,r)*SUM(w, deltar(w,c,r)*QMR0(w,c,r)
                        **(-rhom(c,r)) )**(-1/rhom(c,r)) ;

 QMDIFF(c,r)  = QMCALIB(c,r) - QM0(c,r) ;
$offtext

 QECALIB(c,r) = atr(c,r)*SUM(w, gammar(c,w,r)*QER0(c,w,r)
                        **(rhoe(c,r)) )**(1/rhoe(c,r)) ;

 QEDIFF(c,r)  = QECALIB(c,r) - QE0(c,r) ;


DISPLAY QEDIFF, qecalib;
*DISPLAY QMDIFF, qmcalib;
 ;

PARAMETER
 COMTAXM0(r)   M Taxes
 COMTAXE0(r)   E Taxes
 COMTAXS0(r)   S Taxes
 COMTAXT0(r)   Total Com Taxes
   ;

 COMTAXM0(r) = SUM((tmr,c),SAMG(tmr,c,r)) ;

 COMTAXE0(r) = SUM((ter,c),SAMG(ter,c,r)) ;

 COMTAXS0(r) = SUM((g,c),SAMG(g,c,r)) ;

 COMTAXT0(r) = SUM((tmr,c),SAMG(tmr,c,r))
                + SUM((ter,c),SAMG(ter,c,r))
                + SUM((g,c),SAMG(g,c,r)) ;

DISPLAY COMTAXM0, COMTAXE0, COMTAXS0, COMTAXT0 ;

 OPTION decimals = 3 ;

* -------------- end of anar1 parameter declaration & assignments ------
