* macclos.inc

DISPLAY "#### START: macclos.inc";    

*!! to do: delete taxratesim


* GOVRECRULE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++

*!! not yet: trgovngov
*!! need an equation to define shii

LOOP(trgovrow,
  IF(govrecrulesim(sim,trgovrow) EQ 1,
    TRNSFRSCAL.FX('trgovrow',t) = TRNSFRSCAL0('trgovrow',t);
    trnsfrb(insgov,insrow,t)$(NOT govrecindexsim(sim,trgovrow,t)) = trnsfrb0(insgov,insrow,t);
    trnsfrb(insgov,insrow,t)$govrecindexsim(sim,trgovrow,t)       = trnsfrb00(insgov,insrow)*govrecindexsim(sim,trgovrow,t)/SUM(tmin, govrecindexsim(sim,trgovrow,tmin));
    GOVRECGDP.LO(trgovrow,t) = -INF;
    GOVRECGDP.UP(trgovrow,t) = +INF;
  );
  IF(govrecrulesim(sim,trgovrow) EQ 2,
    TRNSFRSCAL.LO('trgovrow',t) = -INF;
    TRNSFRSCAL.UP('trgovrow',t) = +INF;
    GOVRECGDP.FX(trgovrow,t)$(NOT govrecgdpsim(sim,trgovrow,t)) = GOVRECGDP0(trgovrow,t);
    GOVRECGDP.FX(trgovrow,t)$govrecgdpsim(sim,trgovrow,t)       = govrecgdpsim(sim,trgovrow,t)*GOVRECGDP00(trgovrow)/SUM(tmin, govrecgdpsim(sim,trgovrow,tmin));
  );
);  

LOOP(taxdir,
  IF(govrecrulesim(sim,taxdir) EQ 1,
    TYSCAL.FX(t) = TYSCAL0(t);
    tyb(insdng,t)$(NOT taxratesim(sim,taxdir,insdng,'dummy',t)) = tyb0(insdng,t);
    tyb(insdng,t)$taxratesim(sim,taxdir,insdng,'dummy',t)       = tyb00(insdng)*taxratesim(sim,taxdir,insdng,'dummy',t)/SUM(tmin, taxratesim(sim,taxdir,insdng,'dummy',tmin));
    GOVRECGDP.LO(taxdir,t) = -INF;
    GOVRECGDP.UP(taxdir,t) = +INF;
  );
  IF(govrecrulesim(sim,taxdir) EQ 2,
    TYSCAL.LO(t) = -INF;
    TYSCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxdir,t)$(NOT govrecgdpsim(sim,taxdir,t)) = GOVRECGDP0(taxdir,t);
    GOVRECGDP.FX(taxdir,t)$(govrecgdpsim(sim,taxdir,t)) = govrecgdpsim(sim,taxdir,t)*GOVRECGDP00(taxdir)/SUM(tmin, govrecgdpsim(sim,taxdir,tmin));
  );
);  

LOOP(taxact,
  IF(govrecrulesim(sim,taxact) EQ 1,
    TASCAL.FX(t) = TASCAL0(t);  
    tab(a,t)$(NOT taxratesim(sim,taxact,a,'dummy',t)) = tab0(a,t);
    tab(a,t)$taxratesim(sim,taxact,a,'dummy',t)       = tab00(a)*taxratesim(sim,taxact,a,'dummy',t)/SUM(tmin, taxratesim(sim,taxact,a,'dummy',tmin));
    GOVRECGDP.LO(taxact,t) = -INF;
    GOVRECGDP.UP(taxact,t) = +INF;
  );
  IF(govrecrulesim(sim,taxact) EQ 2,
    TASCAL.LO(t) = -INF;
    TASCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxact,t)$(NOT govrecgdpsim(sim,taxact,t)) = GOVRECGDP0(taxact,t);
    GOVRECGDP.FX(taxact,t)$(govrecgdpsim(sim,taxact,t)) = govrecgdpsim(sim,taxact,t)*GOVRECGDP00(taxact)/SUM(tmin, govrecgdpsim(sim,taxact,tmin));
  );
);  

LOOP(taxco2,
  IF(govrecrulesim(sim,taxco2) EQ 1,
    TCO2SCAL.FX(t) = TCO2SCAL0(t);  
    tco2b(a,t)$(NOT taxratesim(sim,taxco2,a,'dummy',t)) = tco2b0(a,t);
    tco2b(a,t)$taxratesim(sim,taxco2,a,'dummy',t)       = tco2b00(a)*taxratesim(sim,taxco2,a,'dummy',t)/SUM(tmin, taxratesim(sim,taxco2,a,'dummy',tmin));
    GOVRECGDP.LO(taxco2,t) = -INF;
    GOVRECGDP.UP(taxco2,t) = +INF;
  );
  IF(govrecrulesim(sim,taxco2) EQ 2,
    TCO2SCAL.LO(t) = -INF;
    TCO2SCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxco2,t)$(NOT govrecgdpsim(sim,taxco2,t)) = GOVRECGDP0(taxco2,t);
    GOVRECGDP.FX(taxco2,t)$(govrecgdpsim(sim,taxco2,t)) = govrecgdpsim(sim,taxco2,t)*GOVRECGDP00(taxco2)/SUM(tmin, govrecgdpsim(sim,taxco2,tmin));
  );


);


LOOP(taxcom,
  IF(govrecrulesim(sim,taxcom) EQ 1,
    TQSCAL.FX(t) = TQSCAL0(t);  
    tqb(c,t)$(NOT taxratesim(sim,taxcom,c,'dummy',t)) = tqb0(c,t);
    tqb(c,t)$taxratesim(sim,taxcom,c,'dummy',t)       = tqb00(c)*taxratesim(sim,taxcom,c,'dummy',t)/SUM(tmin, taxratesim(sim,taxcom,c,'dummy',tmin));
    GOVRECGDP.LO(taxcom,t) = -INF;
    GOVRECGDP.UP(taxcom,t) = +INF;
  );
  IF(govrecrulesim(sim,taxcom) EQ 2,
    TQSCAL.LO(t) = -INF;
    TQSCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxcom,t)$(NOT govrecgdpsim(sim,taxcom,t)) = GOVRECGDP0(taxcom,t);
    GOVRECGDP.FX(taxcom,t)$(govrecgdpsim(sim,taxcom,t))     = govrecgdpsim(sim,taxcom,t)*GOVRECGDP00(taxcom)/SUM(tmin, govrecgdpsim(sim,taxcom,tmin));
  );
);  

    
LOOP(taxfact,
  IF(govrecrulesim(sim,taxfact) EQ 1,
    TFACTSCAL.FX(taxfact,t) = TFACTSCAL0(taxfact,t);
    tfactb(f,a,t)$(NOT taxratesim(sim,taxfact,f,a,t)) = tfactb0(f,a,t);
    tfactb(f,a,t)$taxratesim(sim,taxfact,f,a,t)       = tfactb00(f,a)*taxratesim(sim,taxfact,f,a,t)/SUM(tmin, taxratesim(sim,taxfact,f,a,tmin));
    GOVRECGDP.LO(taxfact,t) = -INF;
    GOVRECGDP.UP(taxfact,t) = +INF;
  );
  IF(govrecrulesim(sim,taxfact) EQ 2,
    TFACTSCAL.LO(taxfact,t) = -INF;
    TFACTSCAL.UP(taxfact,t) = +INF;
    GOVRECGDP.FX(taxfact,t)$(NOT govrecgdpsim(sim,taxfact,t)) = GOVRECGDP0(taxfact,t);
    GOVRECGDP.FX(taxfact,t)$(govrecgdpsim(sim,taxfact,t)) = govrecgdpsim(sim,taxfact,t)*GOVRECGDP00(taxfact)/SUM(tmin, govrecgdpsim(sim,taxfact,tmin));
  );
);  
    
    
* import tariff rate for commodity c    
LOOP(taximp,
  IF(govrecrulesim(sim,taximp) EQ 1,
    TMSCAL.FX(taximp,t) = TMSCAL0(taximp,t);
    tmb(c,r,t)$(NOT taxratesim(sim,taximp,c,r,t)) = tmb0(c,r,t);      
    tmb(c,r,t)$taxratesim(sim,taximp,c,r,t)       = tmb00(c,r)*taxratesim(sim,taximp,c,r,t)/SUM(tmin, taxratesim(sim,taximp,c,r,tmin));      
    GOVRECGDP.LO(taximp,t) = -INF;
    GOVRECGDP.UP(taximp,t) = +INF;
  );
  IF(govrecrulesim(sim,taximp) EQ 2,
    TMSCAL.LO(taximp,t) = -INF;
    TMSCAL.UP(taximp,t) = +INF;
    GOVRECGDP.FX(taximp,t)$(NOT govrecgdpsim(sim,taximp,t)) = GOVRECGDP0(taximp,t);
    GOVRECGDP.FX(taximp,t)$(govrecgdpsim(sim,taximp,t)) = govrecgdpsim(sim,taximp,t)*GOVRECGDP00(taximp)/SUM(tmin, govrecgdpsim(sim,taximp,tmin));
  );
);  
    
LOOP(taxexp,
  IF(govrecrulesim(sim,taxexp) EQ 1,
    TESCAL.FX(taxexp,t) = TESCAL0(taxexp,t);
    teb(c,r,t)$(NOT taxratesim(sim,taxexp,c,r,t)) = teb0(c,r,t);      
    teb(c,r,t)$taxratesim(sim,taxexp,c,r,t)       = teb00(c,r)*taxratesim(sim,taxexp,c,r,t)/SUM(tmin, taxratesim(sim,taxexp,c,r,tmin));      
    GOVRECGDP.LO(taxexp,t) = -INF;
    GOVRECGDP.UP(taxexp,t) = +INF;
  );
  IF(govrecrulesim(sim,taxexp) EQ 2,
    TESCAL.LO(taxexp,t) = -INF;
    TESCAL.UP(taxexp,t) = +INF;
    GOVRECGDP.FX(taxexp,t)$(NOT govrecgdpsim(sim,taxexp,t)) = GOVRECGDP0(taxexp,t);
    GOVRECGDP.FX(taxexp,t)$(govrecgdpsim(sim,taxexp,t)) = govrecgdpsim(sim,taxexp,t)*GOVRECGDP00(taxexp)/SUM(tmin, govrecgdpsim(sim,taxexp,tmin));
  );
);  
  
LOOP(taxfac,
  IF(govrecrulesim(sim,taxfac) EQ 1,
    TFSCAL.FX(t) = TFSCAL0(t);
    tfb(f,t)$(NOT taxratesim(sim,taxfac,f,'dummy',t)) = tfb0(f,t);
    tfb(f,t)$taxratesim(sim,taxfac,f,'dummy',t)       = tfb00(f)*taxratesim(sim,taxfac,f,'dummy',t)/SUM(tmin, taxratesim(sim,taxfac,f,'dummy',tmin));
    GOVRECGDP.LO(taxfac,t) = -INF;
    GOVRECGDP.UP(taxfac,t) = +INF;
  );
  IF(govrecrulesim(sim,taxfac) EQ 2,
    TFSCAL.LO(t) = -INF;
    TFSCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxfac,t)$(NOT govrecgdpsim(sim,taxfac,t)) = GOVRECGDP0(taxfac,t);
    GOVRECGDP.FX(taxfac,t)$(govrecgdpsim(sim,taxfac,t)) = govrecgdpsim(sim,taxfac,t)*GOVRECGDP00(taxfac)/SUM(tmin, govrecgdpsim(sim,taxfac,tmin));
  );
  
);  

LOOP(taxvatc,
  IF(govrecrulesim(sim,taxvatc) EQ 1,
    TVACSCAL.FX(t) = TVACSCAL0(t);
    tvacb(c,ac,t)$(NOT taxratesim(sim,taxvatc,c,ac,t)) = tvacb0(c,ac,t);      
    tvacb(c,ac,t)$taxratesim(sim,taxvatc,c,ac,t)       = tvacb00(c,ac)*taxratesim(sim,taxvatc,c,ac,t)/SUM(tmin, taxratesim(sim,taxvatc,c,ac,tmin));      
    GOVRECGDP.LO(taxvatc,t) = -INF;
    GOVRECGDP.UP(taxvatc,t) = +INF;
  );
  IF(govrecrulesim(sim,taxvatc) EQ 2,
    TVACSCAL.LO(t) = -INF;
    TVACSCAL.UP(t) = +INF;
    GOVRECGDP.FX(taxvatc,t)$(NOT govrecgdpsim(sim,taxvatc,t)) = GOVRECGDP0(taxvatc,t);
    GOVRECGDP.FX(taxvatc,t)$(govrecgdpsim(sim,taxvatc,t))     = govrecgdpsim(sim,taxvatc,t)*GOVRECGDP00(taxvatc)/SUM(tmin, govrecgdpsim(sim,taxvatc,tmin));
  );
);  


* net foreign financing
LOOP(netforfingov,
  IF(govrecrulesim(sim,netforfingov) EQ 1,
*    NFFG.FX(t) = NFFG0(t);
    NFFG.FX(t)$(NOT govrecindexsim(sim,netforfingov,t)) = NFFG0(t);
*    NFFG.FX(t)$govrecindexsim(sim,netforfingov,t)       = NFFG00*govrecindexsim(sim,netforfingov,t)/SUM(tmin, govrecindexsim(sim,netforfingov,tmin));
    NFFG.FX(t)$govrecindexsim(sim,netforfingov,t)       = NFFG0(t)*govrecindexsim(sim,netforfingov,t);
    GOVRECGDP.LO(netforfingov,t) = -INF;
    GOVRECGDP.UP(netforfingov,t) = +INF;
  );
  IF(govrecrulesim(sim,netforfingov) EQ 2,
    NFFG.LO(t) = -INF;
    NFFG.UP(t) = +INF;
    GOVRECGDP.FX(netforfingov,t)$(NOT govrecgdpsim(sim,netforfingov,t)) = GOVRECGDP0(netforfingov,t);
    GOVRECGDP.FX(netforfingov,t)$govrecgdpsim(sim,netforfingov,t)       = govrecgdpsim(sim,netforfingov,t)*GOVRECGDP00(netforfingov)/SUM(tmin, govrecgdpsim(sim,netforfingov,tmin));
  );
);  

* net domestic financing
LOOP(netdomfin,
  IF(govrecrulesim(sim,netdomfin) EQ 1,
    RNDFG.FX(t) = RNDFG0(t);
    RNDFG.FX(t)$(NOT govrecindexsim(sim,netdomfin,t)) = RNDFG0(t);
    RNDFG.FX(t)$govrecindexsim(sim,netdomfin,t)       = RNDFG00*govrecindexsim(sim,netdomfin,t)/SUM(tmin, govrecindexsim(sim,netdomfin,tmin));
    GOVRECGDP.LO(netdomfin,t) = -INF;
    GOVRECGDP.UP(netdomfin,t) = +INF;
  );
  IF(govrecrulesim(sim,netdomfin) EQ 2,
    RNDFG.LO(t) = -INF;
    RNDFG.UP(t) = +INF;
    GOVRECGDP.FX(netdomfin,t)$(NOT govrecgdpsim(sim,netdomfin,t)) = GOVRECGDP0(netdomfin,t);
    GOVRECGDP.FX(netdomfin,t)$govrecgdpsim(sim,netdomfin,t)       = govrecgdpsim(sim,netdomfin,t)*GOVRECGDP00(netdomfin)/SUM(tmin, govrecgdpsim(sim,netdomfin,tmin));
  );
);  




* GOVSPNDRULE +++++++++++++++++++++++++++++++++++++++++++++++++++++++

LOOP(trngovgov,
  IF(govspndrulesim(sim,trngovgov) EQ 1,
    trnsfrb(insdng,insgov,t)$(NOT govspndindexsim(sim,trngovgov,t)) = trnsfrb0(insdng,insgov,t);
    trnsfrb(insdng,insgov,t)$govspndindexsim(sim,trngovgov,t)       = trnsfrb00(insdng,insgov)*govspndindexsim(sim,trngovgov,t)/SUM(tmin, govspndindexsim(sim,trngovgov,tmin));
    TRNSFRSCAL.FX('trngovgov',t) = TRNSFRSCAL0('trngovgov',t);
    GOVSPNDGDP.LO(trngovgov,t) = -INF;
    GOVSPNDGDP.UP(trngovgov,t) = +INF;
    
  );
  IF(govspndrulesim(sim,trngovgov) EQ 2,
    TRNSFRSCAL.LO('trngovgov',t) = -INF;
    TRNSFRSCAL.UP('trngovgov',t) = +INF;
    GOVSPNDGDP.FX(trngovgov,t)$(NOT govspndgdpsim(sim,trngovgov,t)) = GOVSPNDGDP0(trngovgov,t);
    GOVSPNDGDP.FX(trngovgov,t)$govspndgdpsim(sim,trngovgov,t)       = govspndgdpsim(sim,trngovgov,t)*GOVSPNDGDP00(trngovgov)/SUM(tmin, govspndgdpsim(sim,trngovgov,tmin));
  );
);  


LOOP(trrowgov,
  IF(govspndrulesim(sim,trrowgov) EQ 1,
    trnsfrb(insrow,insgov,t)$(NOT govspndindexsim(sim,trrowgov,t)) = trnsfrb0(insrow,insgov,t);
    trnsfrb(insrow,insgov,t)$govspndindexsim(sim,trrowgov,t)       = trnsfrb00(insrow,insgov)*govspndindexsim(sim,trrowgov,t)/SUM(tmin, govspndindexsim(sim,trrowgov,tmin));
    TRNSFRSCAL.FX('trrowgov',t) = TRNSFRSCAL0('trrowgov',t);
    GOVSPNDGDP.LO(trrowgov,t) = -INF;
    GOVSPNDGDP.UP(trrowgov,t) = +INF;
  );
  IF(govspndrulesim(sim,trrowgov) EQ 2,
    TRNSFRSCAL.LO('trrowgov',t) = -INF;
    TRNSFRSCAL.UP('trrowgov',t) = +INF;
    GOVSPNDGDP.FX(trrowgov,t)$(NOT govspndgdpsim(sim,trrowgov,t)) = GOVSPNDGDP0(trrowgov,t);
    GOVSPNDGDP.FX(trrowgov,t)$govspndgdpsim(sim,trrowgov,t)       = govspndgdpsim(sim,trrowgov,t)*GOVSPNDGDP00(trrowgov)/SUM(tmin, govspndgdpsim(sim,trrowgov,tmin));
  );
);  

* given the modeling of domestic and foreign borrowing, savgov is not used
$ONTEXT
LOOP(savgov,
  IF(govspndrulesim(sim,savgov) EQ 1,
    RSURPG.FX(t)$(NOT govspndgrwsim(sim,savgov,t)) = RSURPG0(t);
    RSURPG.FX(t)$govspndgrwsim(sim,savgov,t)       = RSURPG0(t)*(1+govspndgrwsim(sim,savgov,t));
    GOVSPNDGDP.LO(savgov,t) = -INF;
    GOVSPNDGDP.UP(savgov,t) = +INF;
  );
  IF(govspndrulesim(sim,savgov) EQ 2,
    RSURPG.LO(t) = -INF;
    RSURPG.UP(t) = +INF;
    GOVSPNDGDP.FX(savgov,t)$(NOT govspndgdpsim(sim,savgov,t)) = GOVSPNDGDP0(savgov,t);
    GOVSPNDGDP.FX(savgov,t)$govspndgdpsim(sim,savgov,t)       = govspndgdpsim(sim,savgov,t)*GOVSPNDGDP00(savgov)/SUM(tmin, govspndgdpsim(sim,savgov,tmin));
    
  );
);  
$OFFTEXT

LOOP(congov,
  IF(govspndrulesim(sim,congov) EQ 1,
    qgb(c,t)$(NOT govspndindexsim(sim,congov,t)) = qgb0(c,t);
    qgb(c,t)$govspndindexsim(sim,congov,t)       = qgb00(c)*govspndindexsim(sim,congov,t)/SUM(tmin, govspndindexsim(sim,congov,tmin));
    QGSCAL.FX(t) = QGSCAL0(t);
    GOVSPNDGDP.LO(congov,t) = -INF;
    GOVSPNDGDP.UP(congov,t) = +INF;
  );
  IF(govspndrulesim(sim,congov) EQ 2,
    QGSCAL.LO(t) = -INF;
    QGSCAL.UP(t) = +INF;
    GOVSPNDGDP.FX(congov,t)$(NOT govspndgdpsim(sim,congov,t)) = GOVSPNDGDP0(congov,t);
    GOVSPNDGDP.FX(congov,t)$govspndgdpsim(sim,congov,t)       = govspndgdpsim(sim,congov,t)*GOVSPNDGDP00(congov)/SUM(tmin, govspndgdpsim(sim,congov,tmin));
    
  );
);  

* in all cases, fix IADJ2(govz); will be flexed if govclos=5
IADJ2.FX('govz',t) = IADJ20('govz',t);
LOOP(fcapgz,
  IF(govspndrulesim(sim,fcapgz) EQ 1,
    IADJ.FX('govz',fcapg,t)$(NOT govspndindexsim(sim,fcapgz,t)) = IADJ0('govz',fcapg,t);
    IADJ.FX('govz',fcapg,t)$govspndindexsim(sim,fcapgz,t)       = IADJ00('govz',fcapg)*govspndindexsim(sim,fcapgz,t)/SUM(tmin, govspndindexsim(sim,fcapgz,tmin));
    
    GOVSPNDGDP.LO(fcapgz,t) = -INF;
    GOVSPNDGDP.UP(fcapgz,t) = +INF;
  );
  IF(govspndrulesim(sim,fcapgz) EQ 2,
    IADJ.LO('govz',fcapg,t) = -INF;
    IADJ.UP('govz',fcapg,t) = +INF;
    GOVSPNDGDP.FX(fcapgz,t)$(NOT govspndgdpsim(sim,fcapgz,t)) = GOVSPNDGDP0(fcapgz,t);
    GOVSPNDGDP.FX(fcapgz,t)$govspndgdpsim(sim,fcapgz,t)       = govspndgdpsim(sim,fcapgz,t)*GOVSPNDGDP00(fcapgz)/SUM(tmin, govspndgdpsim(sim,fcapgz,tmin));
    
  );
);  
LOOP(fcapngz2,
  IF(govspndrulesim(sim,fcapngz2) EQ 1,
    IADJ.FX('govz',fcapng,t)$(NOT govspndindexsim(sim,fcapngz2,t)) = IADJ0('govz',fcapng,t);
    IADJ.FX('govz',fcapng,t)$govspndindexsim(sim,fcapngz2,t)       = IADJ00('govz',fcapng)*govspndindexsim(sim,fcapngz2,t)/SUM(tmin, govspndindexsim(sim,fcapngz2,tmin));
    GOVSPNDGDP.LO(fcapngz2,t) = -INF;
    GOVSPNDGDP.UP(fcapngz2,t) = +INF;
  );
  IF(govspndrulesim(sim,fcapngz2) EQ 2,
    IADJ.LO('govz',fcapng,t) = -INF;
    IADJ.UP('govz',fcapng,t) = +INF;
    GOVSPNDGDP.FX(fcapngz2,t)$(NOT govspndgdpsim(sim,fcapngz2,t)) = GOVSPNDGDP0(fcapngz2,t);
    GOVSPNDGDP.FX(fcapngz2,t)$govspndgdpsim(sim,fcapngz2,t)       = govspndgdpsim(sim,fcapngz2,t)*GOVSPNDGDP00(fcapngz2)/SUM(tmin, govspndgdpsim(sim,fcapngz2,tmin));
    
  );
);  


LOOP(subcom,
  IF(govspndrulesim(sim,subcom) EQ 1,
    subcb(c,ac,t)$(NOT govspndindexsim(sim,subcom,t)) = subcb0(c,ac,t);
    subcb(c,ac,t)$govspndindexsim(sim,subcom,t)       = subcb00(c,ac)*govspndindexsim(sim,subcom,t)/SUM(tmin, govspndindexsim(sim,subcom,tmin));
    SUBCSCAL.FX(t) = SUBCSCAL0(t);
    GOVSPNDGDP.LO(subcom,t) = -INF;
    GOVSPNDGDP.UP(subcom,t) = +INF;
  );
  IF(govspndrulesim(sim,subcom) EQ 2,
    SUBCSCAL.LO(t) = -INF;
    SUBCSCAL.UP(t) = +INF;
    GOVSPNDGDP.FX(subcom,t)$(NOT govspndgdpsim(sim,subcom,t)) = GOVSPNDGDP0(subcom,t);
    GOVSPNDGDP.FX(subcom,t)$(govspndgdpsim(sim,subcom,t))     = govspndgdpsim(sim,subcom,t)*GOVSPNDGDP00(subcom)/SUM(tmin, govspndgdpsim(sim,subcom,tmin));
  );
);  


* NGOVPAYRULE +++++++++++++++++++++++++++++++++++++++++++++++++++++++

LOOP(trngovrow,
  IF(ngovpayrulesim(sim,trngovrow) EQ 1,
    TRNSFRSCAL.FX(trngovrow,t)$(NOT ngovpayindexsim(sim,trngovrow,t)) = TRNSFRSCAL0(trngovrow,t);
    TRNSFRSCAL.FX(trngovrow,t)$ngovpayindexsim(sim,trngovrow,t)       = TRNSFRSCAL0(trngovrow,t)*ngovpayindexsim(sim,trngovrow,t)/SUM(tmin, ngovpayindexsim(sim,trngovrow,tmin));
    NGOVPAYGDP.LO(trngovrow,t) = -INF;
    NGOVPAYGDP.UP(trngovrow,t) = +INF;
  );
  IF(ngovpayrulesim(sim,trngovrow) EQ 2,
    TRNSFRSCAL.LO(trngovrow,t) = -INF;
    TRNSFRSCAL.UP(trngovrow,t) = +INF;
    NGOVPAYGDP.FX(trngovrow,t)$(NOT ngovpaygdpsim(sim,trngovrow,t)) = NGOVPAYGDP0(trngovrow,t);
    NGOVPAYGDP.FX(trngovrow,t)$ngovpaygdpsim(sim,trngovrow,t)       = ngovpaygdpsim(sim,trngovrow,t)*NGOVPAYGDP00(trngovrow)/SUM(tmin, ngovpaygdpsim(sim,trngovrow,tmin));
  );
);  

*!! not yet available
*trrowfac

*!! not yet available
*trrowngov

LOOP(trfacrow,
  IF(ngovpayrulesim(sim,trfacrow) EQ 1,
    TRNSFRSCAL.FX(trfacrow,t)$(NOT ngovpayindexsim(sim,trfacrow,t)) = TRNSFRSCAL0(trfacrow,t);
*    TRNSFRSCAL.FX(trfacrow,t)$ngovpayindexsim(sim,trfacrow,t)       = TRNSFRSCAL00(trfacrow)*ngovpayindexsim(sim,trfacrow,t)/SUM(tmin, ngovpayindexsim(sim,trfacrow,tmin));
    trnsfrb(f,insrow,t)$ngovpayindexsim(sim,trfacrow,t)       = trnsfrb00(f,insrow)*ngovpayindexsim(sim,trfacrow,t)/SUM(tmin, ngovpayindexsim(sim,trfacrow,tmin));
    
    NGOVPAYGDP.LO(trfacrow,t) = -INF;
    NGOVPAYGDP.UP(trfacrow,t) = +INF;
  );
  IF(ngovpayrulesim(sim,trfacrow) EQ 2,
    TRNSFRSCAL.LO(trfacrow,t) = -INF;
    TRNSFRSCAL.UP(trfacrow,t) = +INF;
    NGOVPAYGDP.FX(trfacrow,t)$(NOT ngovpaygdpsim(sim,trfacrow,t)) = NGOVPAYGDP0(trfacrow,t);
    NGOVPAYGDP.FX(trfacrow,t)$ngovpaygdpsim(sim,trfacrow,t)       = ngovpaygdpsim(sim,trfacrow,t)*NGOVPAYGDP00(trfacrow)/SUM(tmin, ngovpaygdpsim(sim,trfacrow,tmin));
  );
);  


LOOP(savngov,
  IF(ngovpayrulesim(sim,savngov) EQ 1,
    MPSSCAL.FX(t)$(NOT ngovpayindexsim(sim,savngov,t)) = MPSSCAL0(t);
    MPSSCAL.FX(t)$ngovpayindexsim(sim,savngov,t)       = MPSSCAL0(t)*ngovpayindexsim(sim,savngov,t)/SUM(tmin, ngovpayindexsim(sim,savngov,tmin));
    NGOVPAYGDP.LO(savngov,t) = -INF;
    NGOVPAYGDP.UP(savngov,t) = +INF;
  );
  IF(ngovpayrulesim(sim,savngov) EQ 2,
    MPSSCAL.LO(t) = -INF;
    MPSSCAL.UP(t) = +INF;
    NGOVPAYGDP.FX(savngov,t)$(NOT ngovpaygdpsim(sim,savngov,t)) = NGOVPAYGDP0(savngov,t);
    NGOVPAYGDP.FX(savngov,t)$ngovpaygdpsim(sim,savngov,t)       = ngovpaygdpsim(sim,savngov,t)*NGOVPAYGDP00(savngov)/SUM(tmin, ngovpaygdpsim(sim,savngov,tmin));
    
  );
);  

 

* insdng net foreign financing
LOOP(netforfinngov,
  IF(ngovpayrulesim(sim,netforfinngov) EQ 1,
    NFFINSSCAL.FX(t) = NFFINSSCAL0(t);
    NGOVPAYGDP.LO(netforfinngov,t) = -INF;
    NGOVPAYGDP.UP(netforfinngov,t) = +INF;
  );
  IF(ngovpayrulesim(sim,netforfinngov) EQ 2,
    NFFINSSCAL.LO(t) = -INF;
    NFFINSSCAL.UP(t) = +INF;
    NGOVPAYGDP.FX(netforfinngov,t)$(NOT ngovpaygdpsim(sim,netforfinngov,t)) = NGOVPAYGDP0(netforfinngov,t);
    NGOVPAYGDP.FX(netforfinngov,t)$ngovpaygdpsim(sim,netforfinngov,t)       = ngovpaygdpsim(sim,netforfinngov,t)*NGOVPAYGDP00(netforfinngov)/SUM(tmin, ngovpaygdpsim(sim,netforfinngov,tmin));
  );
);  



* in all cases, fix IADJ2(ngovz); will be flexed depending on siclos
IADJ2.FX('ngovz',t) = IADJ20('ngovz',t);
LOOP(fcapngz,
  IF(ngovpayrulesim(sim,fcapngz) EQ 1,
    IADJ.FX('ngovz',fcapng,t)$(NOT ngovpayindexsim(sim,fcapngz,t)) = IADJ0('ngovz',fcapng,t);
    IADJ.FX('ngovz',fcapng,t)$ngovpayindexsim(sim,fcapngz,t)       = IADJ0('ngovz',fcapng,t)*ngovpayindexsim(sim,fcapngz,t)/SUM(tmin, ngovpayindexsim(sim,fcapngz,tmin));
    NGOVPAYGDP.LO(fcapngz,t) = -INF;
    NGOVPAYGDP.UP(fcapngz,t) = +INF;
  );
  IF(ngovpayrulesim(sim,fcapngz) EQ 2,
    IADJ.LO('ngovz',fcapng,t) = -INF;
    IADJ.UP('ngovz',fcapng,t) = +INF;
    NGOVPAYGDP.FX(fcapngz,t)$(NOT ngovpaygdpsim(sim,fcapngz,t)) = NGOVPAYGDP0(fcapngz,t);
    NGOVPAYGDP.FX(fcapngz,t)$ngovpaygdpsim(sim,fcapngz,t)       = ngovpaygdpsim(sim,fcapngz,t)*NGOVPAYGDP00(fcapngz)/SUM(tmin, ngovpaygdpsim(sim,fcapngz,tmin));
    
  );
);  

* foreign direct investment
LOOP(fdiz,
  IF(ngovpayrulesim(sim,fdiz) EQ 1,
    FDISCAL.FX(t) = FDISCAL0(t);
    NGOVPAYGDP.LO(fdiz,t) = -INF;
    NGOVPAYGDP.UP(fdiz,t) = +INF;
  );
  IF(ngovpayrulesim(sim,fdiz) EQ 2,
    FDISCAL.LO(t) = -INF;
    FDISCAL.UP(t) = +INF;
    NGOVPAYGDP.FX(fdiz,t)$(NOT ngovpaygdpsim(sim,fdiz,t)) = NGOVPAYGDP0(fdiz,t);
    NGOVPAYGDP.FX(fdiz,t)$ngovpaygdpsim(sim,fdiz,t)       = ngovpaygdpsim(sim,fdiz,t)*NGOVPAYGDP00(fdiz)/SUM(tmin, ngovpaygdpsim(sim,fdiz,tmin));
  );
);  

* investment by domestic non-gov inst in gov capital
IADJ.FX('ngovz',fcapg,t) = IADJ0('ngovz',fcapg,t);

$ONTEXT
LOOP(invgovz,
  IF(ngovpayrulesim(sim,invgovz) EQ 1,
    NGOVPAYGDP.LO(invgovz,t) = -INF;
    NGOVPAYGDP.UP(invgovz,t) = +INF;
  );
  IF(ngovpayrulesim(sim,invgovz) EQ 2,
    DKINSTSCAL.LO(t) = -INF;
    DKINSTSCAL.UP(t) = +INF;
    NGOVPAYGDP.FX(invgovz,t)$(NOT ngovpaygdpsim(sim,invgovz,t)) = NGOVPAYGDP0(invgovz,t);
    NGOVPAYGDP.FX(invgovz,t)$ngovpaygdpsim(sim,invgovz,t)       = ngovpaygdpsim(sim,invgovz,t)*NGOVPAYGDP00(invgovz)/SUM(tmin, ngovpaygdpsim(sim,invgovz,tmin));
  );
);  
$OFFTEXT


* foreign tourism receipts
LOOP(instrstz,
  IF(ngovpayrulesim(sim,instrstz) EQ 1,
  
    IF (sim0(sim),
      qtrstb(c,instrst,t)$(minstrstinstrstz(instrst,instrstz) AND NOT ngovpayindexsim(sim,instrstz,t)) = qtrstb0(c,instrst,t);
      qtrstb(c,instrst,t)$(minstrstinstrstz(instrst,instrstz) AND ngovpayindexsim(sim,instrstz,t))     = 
        qtrstb00(c,instrst)*ngovpayindexsim(sim,instrstz,t)/SUM(tmin, ngovpayindexsim(sim,instrstz,tmin));
    );
    
    QTRSTFSCAL.FX(instrst,t)$minstrstinstrstz(instrst,instrstz) = QTRSTFSCAL0(instrst,t);
    NGOVPAYGDP.LO(instrstz,t) = -INF;
    NGOVPAYGDP.UP(instrstz,t) = +INF;
  );
  IF(ngovpayrulesim(sim,instrstz) EQ 2,
    QTRSTFSCAL.LO(instrst,t)$minstrstinstrstz(instrst,instrstz) = -INF;
    QTRSTFSCAL.UP(instrst,t)$minstrstinstrstz(instrst,instrstz) = +INF;
    NGOVPAYGDP.FX(instrstz,t)$(NOT ngovpaygdpsim(sim,instrstz,t)) = NGOVPAYGDP0(instrstz,t);
    NGOVPAYGDP.FX(instrstz,t)$ngovpaygdpsim(sim,instrstz,t)       = ngovpaygdpsim(sim,instrstz,t)*NGOVPAYGDP00(instrstz)/SUM(tmin, ngovpaygdpsim(sim,instrstz,tmin));
  );
);  

    
* Numeraire +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

IF(numerairesim(sim) EQ 1,
  CPI.FX(t) = CPI0(t);
  DPI.LO(t) = -INF;
  DPI.UP(t) = +INF;
  DPI.L(t)  = DPI0(t);
);

IF(numerairesim(sim) EQ 2,
  DPI.FX(t) = DPI0(t);
  CPI.LO(t) = -INF;
  CPI.UP(t) = +INF;
  CPI.L(t)  = CPI0(t);
);

* Government ++++++++++++++++++++++++++++++++++++++++++++++++++++++++

* 1 = direct tax collection clears the government budget
IF(govclossim(sim,t) EQ 1,
  TYSCAL.LO(t) = -INF;
  TYSCAL.UP(t) = +INF;  
  GOVRECGDP.LO(taxdir,t) = -INF;
  GOVRECGDP.UP(taxdir,t) = +INF;
);

* 2 = net domestic financing clears the government budget
IF(govclossim(sim,t) EQ 2,
* flexed net domestic financing
  RNDFG.LO(t) = -INF;
  RNDFG.UP(t) = +INF;
  GOVRECGDP.LO(netdomfin,t) = -INF;
  GOVRECGDP.UP(netdomfin,t) = +INF;    
);

* 3 = net foreign financing clears the government budget
IF(govclossim(sim,t) EQ 3,
* flexed net foreign financing
  NFFG.LO(t) = -INF;  
  NFFG.UP(t) = +INF;  
  GOVRECGDP.LO(netforfingov,t) = -INF;
  GOVRECGDP.UP(netforfingov,t) = +INF;    
);

* 4 = government consumption clears the government budget
IF(govclossim(sim,t) EQ 4,
* flex government consumption 
  QGSCAL.LO(t) = -INF;
  QGSCAL.UP(t) = +INF;
  GOVSPNDGDP.LO(congov,t) = -INF;
  GOVSPNDGDP.UP(congov,t) = +INF;
);


* 5 = government investment clears the government budget
IF(govclossim(sim,t) EQ 5,
* note: corresponding govspndrulesim must be eq 1
* note: need only one endogenous variable; thus, added IADJ(govz)
  IADJ2.LO('govz',t) = -INF;
  IADJ2.UP('govz',t) = +INF;
  GOVSPNDGDP.LO(fcapgz,t) = -INF;
  GOVSPNDGDP.UP(fcapgz,t) = +INF;
);


* 6 = foreign transfers clear the government budget
IF(govclossim(sim,t) EQ 6,
* flex foreign transfers
  TRNSFRSCAL.LO('trgovrow',t) = -INF;
  TRNSFRSCAL.UP('trgovrow',t) = +INF;
  GOVRECGDP.LO(trgovrow,t) = -INF;
  GOVRECGDP.UP(trgovrow,t) = +INF;
);

* 7 = government transfers to insdng clear the government budget
IF(govclossim(sim,t) EQ 7,
* flex transfers to insdng
  TRNSFRSCAL.LO('trngovgov',t) = -INF;
  TRNSFRSCAL.UP('trngovgov',t) = +INF;
  GOVSPNDGDP.LO(trngovgov,t) = -INF;
  GOVSPNDGDP.UP(trngovgov,t) = +INF;
);

* 8 = commodity subsidies clear the government budget
IF(govclossim(sim,t) EQ 8,
* flex commodity subsidies
  SUBCSCAL.LO(t) = -INF;
  SUBCSCAL.UP(t) = +INF;
  GOVSPNDGDP.LO(subcom,t) = -INF;
  GOVSPNDGDP.UP(subcom,t) = +INF;
);

* 9 = commodity tax clears the government budget
IF(govclossim(sim,t) EQ 9,
* flex commodity subsidies
  TQSCAL.LO(t) = -INF;
  TQSCAL.UP(t) = +INF;
  GOVRECGDP.LO(taxcom,t) = -INF;
  GOVRECGDP.UP(taxcom,t) = +INF;
);

* 10 = activity tax clears the government budget
IF(govclossim(sim,t) EQ 10,
* flex commodity subsidies
  TASCAL.LO(t) = -INF;
  TASCAL.UP(t) = +INF;
  GOVRECGDP.LO(taxact,t) = -INF;
  GOVRECGDP.UP(taxact,t) = +INF;
);

* 11 = value-added tax clears the government budget
IF(govclossim(sim,t) EQ 11,
* flex commodity subsidies
  TVACSCAL.LO(t) = -INF;
  TVACSCAL.UP(t) = +INF;
  GOVRECGDP.LO(taxvatc,t) = -INF;
  GOVRECGDP.UP(taxvatc,t) = +INF;
);


* Rest of the World +++++++++++++++++++++++++++++++++++++++++++++++++

IF(rowclossim(sim) EQ 1,
* tipo de cambio flexible
  REXR.LO(t) = -INF; 
  REXR.UP(t) = +INF;
);

IF(rowclossim(sim) EQ 2,
* tipo de cambio flexible
  NFFINSSCAL.LO(t) = -INF;
  NFFINSSCAL.UP(t) = +INF;
);





* Savings-Investment ++++++++++++++++++++++++++++++++++++++++++++++++

IF(siclossim(sim) EQ 1,
* flex real non-gov investment
* note: need only one endogenous variable; thus, added IADJ2(ngovz)
  IADJ2.LO('ngovz',t) = -INF; 
  IADJ2.UP('ngovz',t) = +INF;
  NGOVPAYGDP.LO(fcapngz,t) = -INF;
  NGOVPAYGDP.UP(fcapngz,t) = +INF;  
);

IF(siclossim(sim) EQ 2,
* ahorro insdng flexible
  MPSSCAL.LO(t) = -INF;
  MPSSCAL.UP(t) = +INF;
  NGOVPAYGDP.LO(savngov,t) = -INF;
  NGOVPAYGDP.UP(savngov,t) = +INF;    
);  

* 3 = net foreign financing clears the savings-investment balance
IF(siclossim(sim) EQ 3,
* flexed insdng net foreign financing
  NFFINSSCAL.LO(t) = -INF;
  NFFINSSCAL.UP(t) = +INF;
  NGOVPAYGDP.LO(netforfinngov,t) = -INF;
  NGOVPAYGDP.UP(netforfinngov,t) = +INF;    
  
);


* 4 = government (real) net domestic financing clears the savings-investment balance
* cannot be selected when govclossim = 2
IF(siclossim(sim) EQ 4,
* flexed insdng net foreign financing
  RNDFG.LO(t) = -INF;
  RNDFG.UP(t) = +INF;
  GOVRECGDP.LO(netdomfin,t) = -INF;
  GOVRECGDP.UP(netdomfin,t) = +INF;    
  
);


DISPLAY "#### END: macclos.inc";    
