'***************************************************************
'*    FORWARD SIMULATION OF  TRUNCATED MA	   *
'***************************************************************
PAGESELECT TIMESERIES 
coef(1000) C1
coef(1000) C2
coef(1000) C3
coef(1000) C4
!year_s= 2013
!year_e = 2007  
!start = 1981   

'set variables

%MODEL = "AP_SD2" 		'  EB_AT  	EB_ATHD   EB_ATLD  EB_STY
%LIST_YEARS = "1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007"'  
%LIST ="AUS AUT BEL CAN  DNK ESP FRA GBR IRL ITA JPN PRT USA DEU"
'%LIST ="AUS AUT BEL CAN  DNK FRA GBR IRL JPN PRT USA DEU"  'ESP  ITA

smpl !start !year_s 
'%VAR_to_PLOT="y_pc" 'to be commented if run from repl_baseline
'set the systems
%sys="sys_"+%VAR_to_PLOT+%MODEL

'generating the series
FOR %IDC  {%LIST}
		SMPL @ALL
		GENR IMF_TAX_UT_S{%idc} = IMF_TAX_UT{%idc}
		GENR IMF_SPND_UT_S{%idc} = IMF_SPND_UT{%idc}
		GENR IMF_TAX_ATT_S{%idc} = IMF_TAX_ATT{%idc}
		GENR IMF_SPND_ATT_S{%idc} = IMF_SPND_ATT{%idc}
		GENR IMF_TAX_ATT1_S{%idc} = IMF_TAX_ATT1{%idc}
		GENR IMF_SPND_ATT1_S{%idc} = IMF_SPND_ATT1{%idc}
		GENR IMF_TAX_ATT2_S{%idc} = IMF_TAX_ATT2{%idc}
		GENR IMF_SPND_ATT2_S{%idc} = IMF_SPND_ATT2{%idc}
NEXT

FOR %YEAR {%LIST_YEARS}
		GENR DUMMY_S{%YEAR} = DUMMY_{%YEAR}
NEXT

system {%sys}
!J= 0
!I=50
!K=0
FOR %IDC {%LIST}
		{%sys}.append {%VAR_to_PLOT}{%IDC}  =C1(2+!J)*IMF_TAX_UT_S{%IDC}+ C1(3+!J)*IMF_SPND_UT_S{%IDC} + C1(4+!J)*IMF_TAX_ATT_S{%IDC}+ C1(5+!J)*IMF_SPND_ATT_S{%IDC} + C1(6+!J)*IMF_TAX_UT_S{%IDC}(-1)+ C1(7+!J)*IMF_SPND_UT_S{%IDC}(-1) + C1(8+!J)*IMF_TAX_ATT_S{%IDC}(-1) + C1(9+!J)*IMF_SPND_ATT_S{%IDC}(-1)+ C1(10+!J)*IMF_TAX_UT_S{%IDC}(-2)+ C1(11+!J)*IMF_SPND_UT_S{%IDC}(-2) + C1(12+!J)*IMF_TAX_ATT_S{%IDC}(-2)+ C1(13+!J)*IMF_SPND_ATT_S{%IDC}(-2)+ C1(14+!J)*IMF_TAX_UT_S{%IDC}(-3)+ C1(15+!J)*IMF_SPND_UT_S{%IDC}(-3)+ C1(16+!J)*IMF_TAX_ATT_S{%IDC}(-3)+ C1(17+!J)*IMF_SPND_ATT_S{%IDC}(-3)+ C1(18+!J)*IMF_TAX_ATT1_S{%IDC}+ C1(19+!J)*IMF_SPND_ATT1_S{%IDC}+ C1(20+!J)*IMF_TAX_ATT2_S{%IDC}+ C1(21+!J)*IMF_SPND_ATT2_S{%IDC} +C1(26+!J)*dummy_s1983+ C1(27+!J)*dummy_s1984+ C1(28+!J)*dummy_s1985+ C1(29+!J)*dummy_s1986+ C1(30+!J)*dummy_s1987+ C1(31+!J)*dummy_s1988+ C1(32+!J)*dummy_s1989+ C1(33+!J)*dummy_s1990+ C1(34+!J)*dummy_s1991+ C1(35+!J)*dummy_s1992+ C1(36+!J)*dummy_s1993+ C1(37+!J)*dummy_s1994+ C1(38+!J)*dummy_s1995+ C1(39+!J)*dummy_s1996+ C1(40+!J)*dummy_s1997+ C1(41+!J)*dummy_s1998+ C1(42+!J)*dummy_s1999+ C1(43+!J)*dummy_s2000+ C1(44+!J)*dummy_s2001+ C1(45+!J)*dummy_s2002+ C1(46+!J)*dummy_s2003+ C1(47+!J)*dummy_s2004+ C1(48+!J)*dummy_s2005 + C1(49+!J)*dummy_s2006 + C1(50+!J)*dummy_s2007+C1(1+!I) 
'+ C2(24+!J)*IMF_TOT_ATT4_S{%IDC}*IMF_TB_S{%IDC} + C(25+!J)*IMF_TOT_ATT4_S{%IDC}*IMF_EB_S{%IDC} '+ C(26+!J)*IMF_TOT_ATT5_S{%IDC}*IMF_TB_S{%IDC} + C(27+!J)*IMF_TOT_ATT5_S{%IDC}*IMF_EB_S{%IDC}    + C(24+!J)*dummy_s1981    C1(22+!J)*IMF_TOT_ATT3_S{%IDC}*IMF_TB_S{%IDC} + C1(23+!J)*IMF_TOT_ATT3_S{%IDC}*IMF_EB_S{%IDC} +
		!I=!I+1
		'!K=!K+7	
		'!J = !J +7 '***  	'if skipped, then panel restrictions are imposed on the GVAR  
NEXT


smpl !start !year_e
{%sys}.sur 

'********************************************************************************
'  STOCHASTIC FORWARD SIMULATION
'********************************************************************************
model model
model.merge {%sys}
'***** SCENARIO

	model.stochastic(i=b, r=1000, s=!START+1 !YEAR_e, f=.2, b=.95,c=F)
	model.solveopt(s=b)
	'model.append assign @all  _0m 'to be activated only if sol=det) 
	smpl !year_e+2 !year_s  
	model.solve
	
	'Store FE
	!I=50
	FOR %IDC {%LIST}
		genr FE{%idc}={%sys}.C1(!I+1)
		!I=!I+1
	next


