* ======= Experiment file ================================================
* ----- DESCRIPTION OF EXPERIMENT -----
$ontext


$offtext
$ontext
 This file sets up and runs experiments on a model. It has a standard structure
 which is described below.

NB: 1) THE USER NEEDS TO SET (SECTION 3) AND IMPLEMENT THE SHOCKS (SECTION 5)
    2) THE USER SHOULD MAKE SURE THAT THE NAME OF THE OUTPUT FILEs - IN GDX -
       ARE THOSE DESIRED.
             DEFAULT NAMES ARE IMPOSED IN THE VARIOUS RESULT MODULES
                     - THESE CAN BE CHANGED BY THE USER.

 Structure
          1. Declare and Assign Simulation Set
          2. Define Result Parameters
          3. Setting up the sim shocks
                 3a. Declaring Parameters for Shocks
                 3b. Assigning Parameters for Shocks
          4. Setting up the Closures
                 4a. Declaring Parameters for Closure
                 4b. Assigning Parameters for Closure
          5. Runnin the experiments
                 5a. clos loop begins
                 5b. sim loop begins
                 5c. Implementing sim shocks
          6. Solve statement
          7. Storing results
          8. Terminating sim loop
          9. Terminating clos loop

The experiment code consists of a number of files; the relationships between
these files is illustrated below.

 glb_2.gms                                master programme file
     |
    .
     .
      .
       .
     |
     | 16. POLICY EXPERIMENTS
     |
     |<----- anar1_expt_**.inc          Experiment files
                 |
                 |<----- anar1_resparm.inc     Declare results params
                 |
                 |<----- anar1_varinit2.inc    Reinitialise variables
                 |<----- anar1_reset.inc       Reset closure variables
                 |
                 |<----- anar1_***1.inc        Alternative closures
                 |<----- anar1_cl***..inc                 .
                 |<----- anar1_cl***..inc                 .
                 |<----- anar1_cl***n.inc        Alternative closures
                 |
                 |
                 |<----- anar1_resassign.inc   Assigning results params
                 |
                 |
      |
      |<----- glb_299_anal.inc         Result Analyses sub routine
      |          |
                 |
                 |<----- anar1_reslevel.inc    Levels results saved
                 |
                 |<----- anar1_resmacro.inc    Macroeconomic results
                 |
                 |<----- glb_2.inc     Welfare results
                 |
                 |<----- anar1_resstruct.inc   Structural results
                 |
                 |<----- anar1_resindex.inc    Price index results
                 |
                 |<----- anar1_resperc.inc     Proportionate results

$offtext

* ------- 1. Declare and Assign Simulation Set ---------------------------

* By including a "base case" in the SIM set a comparator is produced

SETS
* Sets for simulations

 sim          simulations
 simc(sim)    CURRENT simulations - those actually run
 simr(sim)    REPORTED simulations - those run that are saved
 clos         closures
 elst         elasticities

* Sub Sets used in experiments

 l(f)         Labour Factors
 ls(l)        Skilled Labour Factors
 lu(l)        Unskilled Labour Factors
 k(f)         Capital Factors
 lnd(f)       Land factors

* Sub sets used in closures

 rerfx(r)     Regions where the exchange rate is fixed
 rerfxn(r)    Regions where the external balance is fixed

* Additional sets to control study specific experiments

 rsad(r)      Regions in SADC

 wsad(w)      Regions in SADC
 wsadn(w)     Regions NOT in SADC

* Sets used in reports

 ppric        Set of price variables
 qqunt        Set of quantity variables


  ;

ALIAS(l,lp),
     (cagr,cagrp),(cnat,cnatp),(cfd,cfdp),(cind,cindp),(cser,cserp),
     (aagr,aagrp),(anat,anatp),(afd,afdp),(aind,aindp),(aser,aserp),
     (l,lp),(ls,lsp),(lu,lup),(k,kp),(lnd,lndp),
     (rsad,rsadp),(wsad,wsadp),(wsadn,wsadnp)
   ;

* Convert Excel workbook data to GDX here
$CALL "GDXXRW i=data_expt_test.xlsx o=expt_in.gdx INDEX=LAYOUT!A4"

* Loading sets from GDX data file

$GDXIN expt_in.GDX

$LOADdc rerfx
$LOADdc sim simc simr clos elst

$LOADdc ppric qqunt

$GDXIN

* Assigning membership to simc - default is all sim

* simc(sim)    = YES ;

* Assigning set members by reference to other sets

 rerfxn(r)     = not rerfx(r) ;
 rerfxn("glo") = no ;

* rluex(r)      = not rluen(r) ;


* Additional sets to control study specific experiments


DISPLAY sim, simc, simr, clos, elst,
        rerfx, rerfxn,
        ppric, qqunt
 ;

* ------- 2. Define Result Parameters ------------------------------------
* This section defines the result parameter that are used to store model
* results between experiments and sims.

* ------------------- RESULTS IN LEVELS -----------------------------------

* Declaring parameters for levels (and proportionate change) results

$INCLUDE anar1_resparm.inc

* ------- 3. Setting up the sim shocks -----------------------------------

* ------- 3a. Declaring Parameters for Shocks ----------------------------

Parameter
* Standard parameters for tax instrument shocks
 TESIM(c,w,r,sim)      Export taxes on exported comm'y c from r to w
 TMSIM(w,c,r,sim)      Ad valorem Tariff rates on imported comm'y c from w by r
 TMSSIM(w,c,r,sim)     Specific Tariff rates on imported comm'y c from w by r
 TSSIM(c,r,sim)        Sales tax rates
 TVSIM(c,r,sim)        VAT tax rates
 TXSIM(a,r,sim)        Indirect tax rates
 TYFSIM(f,r,sim)       Direct tax rates on factor income
 TYHSIM(h,r,sim)       Direct tax rates on households
 TFSIM(f,a,r,sim)      Tax rates on factor use

* Standard parameters for efficiency rate shocks
 ADXSIM(a,r,sim)       Shift parameter for CES production functions for QX in r
 ADVASIM(a,r,sim)      Shift parameter for CES production functions for QVA
 ADFAGSIM(f2ag,a,r,sim)  Shift parameter for CES production functions for FD
 ADFDSIM(f,a,r,sim)    Shift parameter for factor and activity specific efficiency

* Standard parameters for factor demand and supply shocks
 FDSIM(f,a,r,sim)      Demand for factor f by activity a in r
 FSSIM(f,r,sim)        Supply of factor f in r

* Shocks data


  ;

* ------- 3b. Assigning Parameters for Shocks ----------------------------

* ------ Defining the shock parameters

*Display popn ;

*----- 1. Setting tax rate shocks

*--- Ad valorem Tariff rates
 TMSIM(w,c,r,sim)           = TM0(w,c,r) ;

* Test case simulations
 TMSIM(w,c,r,"sim01")       = TM0(w,c,r) * 0.5 ;
 TMSIM(w,c,r,"sim04")       = TM0(w,c,r) * 0.5 ;
 TMSIM(w,c,r,"sim05")       = TM0(w,c,r) * 0.5 ;

*--- Specific Tariff rates
 TMSSIM(w,c,r,sim)          = TMS0(w,c,r) ;

* Test case simulations
 TMSSIM(w,c,r,"sim02")      = TMS0(w,c,r) * 0.5 ;
 TMSSIM(w,c,r,"sim04")      = TMS0(w,c,r) * 0.5 ;
 TMSSIM(w,c,r,"sim05")      = TMS0(w,c,r) * 0.5 ;

*--- Export tax rates
 TESIM(c,w,r,sim)           = TE0(c,w,r) ;

* Test case simulations
 TESIM(c,w,r,"sim03")       = TE0(c,w,r) * 0.0 ;
 TESIM(c,w,r,"sim05")       = TE0(c,w,r) * 0.0 ;

*--- Sales tax rates
 TSSIM(c,r,sim)             = TS0(c,r) ;

*--- VAT tax rates
 TVSIM(c,r,sim)             = TV0(c,r) ;

*--- Production tax rates
 TXSIM(a,r,sim)             = TX0(a,r) ;

*--- Factor Use Taxes
 TFSIM(f,a,r,sim)           = TF0(f,a,r) ;

*--- Household Income Taxes
 TYHSIM(h,r,sim)            = TYH0(h,r) ;

*--- Factor Income Taxes
 TYFSIM(f,r,sim)            = TYF0(f,r) ;

*----- 2. Setting efficiency rate shocks

*--- Top level Hicks neutral efficiency parameter
 ADXSIM(a,r,sim)            = ADX0(a,r) ;

* Test case simulations
 ADXSIM(a,r,"sim06")        = ADX0(a,r) * 1.025 ;

*--- Aggregate value added Hicks neutral efficiency parameter
 ADVASIM(a,r,sim)           = ADVA0(a,r) ;

* Test case simulations
 ADVASIM(a,r,"sim07")       = ADVA0(a,r) * 1.025 ;
 ADVASIM(a,r,"sim09")       = ADVA0(a,r) * 1.025 ;

*--- Aggregate labour Hicks neutral efficiency parameter
 ADFAGSIM(f2ag,a,r,sim)     = adfag(f2ag,a,r) ;

*--- Individual factor efficiency parameter
 ADFDSIM(f,a,r,sim)         = adfd0(f,a,r) ;

* Test case simulations
 ADFDSIM(k,a,r,"sim08")     = adfd0(k,a,r) * 1.05 ;
 ADFDSIM(k,a,r,"sim09")     = adfd0(k,a,r) * 1.05 ;


*----- 3. Setting factor supply & demand shocks
*--- factor supply shocks
 FSSIM(f,r,sim)             = FS0(f,r) ;

* Test case simulations
 FSSIM(f,r,"sim10")         = FS0(f,r) * 1.05 ;

*--- Factor demand shocks
 FDSIM(f,a,r,sim)           = FD0(f,a,r) ;

* Test case simulations


*---- 4. Shocks data


* Displaying shock parameters

Display TESIM, TMSIM, TMSSIM, TSSIM, TVSIM, TXSIM, TYFSIM, TYHSIM, TFSIM,
        ADXSIM, ADVASIM, ADFAGSIM, ADFDSIM,
        FSSIM, FDSIM
  ;

Execute_Unload  'results/anar1_shocks.gdx',
        TESIM, TMSIM, TMSSIM, TSSIM, TVSIM, TXSIM, TYFSIM, TYHSIM, TFSIM,
        ADXSIM, ADVASIM, ADFAGSIM, ADFDSIM,
        FSSIM, FDSIM
   ;

* ------- 4. Setting up the Closures --------------------------------------


* ------- 4a. Declaring Parameters for Closure ----------------------------

Parameter

 closure(clos)    values that control choice of closure

  ;


* ------- 4b. Assigning Parameters for Closure ----------------------------

* Assign values to select closure INCLUDE file
 closure("clbase")   = 1 ;
* closure("clos02")   = 2 ;
* closure("clos03")   = 3 ;
* closure("clos04")   = 4 ;

* ------- 5. Runnin the experiments ---------------------------------------

* ------- 5a. elst loop begins --------------------------------------------

*LOOP(elst,


* ------- 5b. clos loop begins --------------------------------------------

LOOP(clos,

* First set .L values back to initial values for looping over diff closures

$INCLUDE anar1_varinit2.inc

* Second, free all variables that are involved in any closure rule

$INCLUDE anar1_reset.inc

* Third, select closure include files


IF(Closure(clos) = 1,

$INCLUDE anar1_cl_std.inc

$ontext
     anar1_cl_std.inc

Description
 Full employment, balanced macro with flexible external balances
 All tax rates fixed, i.e., no tax replacement

                     CONDITION                                 REGIONS

     FEX        - Exchange rate fixed                            GLO
                - KAPWOR fixed                                   rgn

     Investment - savings rates are fixed                        All

     Government - taxes rates fixed                              All
                - absorption share fixed                         All
                - KAPGOV fixed                                   All

     Factors    - Land sector - mobile & full                    All
                - Capital - mobile & full                        All
                - Unskilled labour - mobile & full               All
                - Skilled labour - mobile & full                 All

     Numeraire  - CPI                                            All

$offtext

 ) ;


*IF(Closure(clos) = 2,

*$INCLUDE anar1_2_cl_???_2.inc

$ontext
     anar1_2_cl_???_2.inc

Description
 ??????????

                     CONDITION                                 REGIONS

     FEX        - Exchange rate fixed                           rerfx
                - KAPWOR fixed                                  rerfxn

     Investment - investment volumes fixed                       All

     Government - absorption share fixed                         All
                - TYH flexible - Additive form                   All
                - CAPGOV fixed                                   All

     Factors    - Land sector - mobile & full                    All
                - Capital - mobile & full                        All
                - Unskilled labour - mobile & full               ALL
                - Skilled labour - mobile & full                 All

     Numeraire  - CPI                                            All
$offtext

* ) ;



* ------- 5c. sim loop begins ---------------------------------------------

LOOP(sim$simc(sim),

* ------- 5d. Implementing sim shocks -------------------------------------

*---- 1. Applying tax rate shocks

* Import duties

 tmb(w,c,r)    = TMSIM(w,c,r,sim) ;

 tmsb(w,c,r)   = TMSSIM(w,c,r,sim) ;

* Export taxes

 teb(c,w,r)    = TESIM(c,w,r,sim) ;

* Sales taxes

 tsb(c,r)      = TSSIM(c,r,sim) ;

* Value added taxes

 tvb(c,r)      = TVSIM(c,r,sim) ;

* Production taxes

 txb(a,r)      = TXSIM(a,r,sim) ;

* Factor Use taxes

 tfb(f,a,r)    = TFSIM(f,a,r,sim) ;

* Household Income taxes

 tyhb(h,r)     = TYHSIM(h,r,sim) ;

* Factor Income taxes

 tyfb(f,r)     = TYFSIM(f,r,sim) ;

*---- 2. Applying efficiency rate shocks

* Top level Hicks neutral efficiency parameter
 adxb(a,r)     = ADXSIM(a,r,sim) ;

* Aggregate value added Hicks neutral efficiency parameter
 advab(a,r)    = ADVASIM(a,r,sim) ;

* Aggregate labour Hicks neutral efficiency parameter
 adfag(f2ag,a,r)  = ADFAGSIM(f2ag,a,r,sim) ;

* Individual factor efficiency parameter
 adfdb(f,a,r)   = ADFDSIM(f,a,r,sim) ;

*---- 3. Applying factor demand and supply shocks
* factor supply shocks
* FS.FX(f,r)     = FSSIM(f,r,sim) ;

Display  tmb, tmsb, teb, tsb, tvb, txb, tfb, tyhb, tyfb,
         adxb, advab, adfag, adfdb
*         FS
  ;

* ------- 6. Solve statement ---------------------------------------------

 OPTION DECIMALS = 6 ;
 Options limrow=100,limcol=0;
 option iterlim = 15 ;

 Solve anar1 Using MCP ;

* ------- 7. Storing results ---------------------------------------------

* Assigning levels results to the result parameters for all variables

$INCLUDE anar1_resassign.inc


* ------- 8. Terminating sim loop ----------------------------------------

 ) ;


* ------- 9. Terminating clos loop ----------------------------------------

 ) ;

* ------- 10. Terminating elst loop ----------------------------------------

* ) ;

* ########### END OF ANAR1 EXPERIMENT FILE ################################
