'***************************************************************
'*    FORWARD SIMULATION OF  TRUNCATED MA	   *
'***************************************************************
PAGESELECT TIMESERIES 
coef(1000) C1
coef(1000) C2
coef(1000) C3
coef(1000) C4


'set variables

%MODEL = "CP_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_TOT_UT_S{%idc} = IMF_TOT_UT{%idc}
		GENR IMF_TOT_ATT_S{%idc} = IMF_TOT_ATT{%idc}
		GENR IMF_TOT_ATT1_S{%idc} = IMF_TOT_ATT1{%idc}
		GENR IMF_TOT_ATT2_S{%idc} = IMF_TOT_ATT2{%idc}
		'GENR IMF_TOT_ATT3_S{%idc} = IMF_TOT_ATT3{%idc}
		'GENR IMF_TOT_ATT4_S{%idc} = IMF_TOT_ATT4{%idc}
		'GENR IMF_TOT_ATT5_S{%idc} = IMF_TOT_ATT5{%idc}
		GENR IMF_TB_S{%IDC} = IMF_TB{%idc}
		GENR IMF_EB_S{%IDC} = IMF_EB{%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(1+!J)*IMF_TOT_UT_S{%IDC}*IMF_TB_S{%IDC} _
+ C1(2+!J)*IMF_TOT_UT_S{%IDC}*IMF_EB_S{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y_s1986 _
+ C1(25+!J)*dummy_s1987 _
+ C1(26+!J)*dummy_s1988 _
+ C1(27+!J)*dummy_s1989 _
+ C1(28+!J)*dummy_s1990 _
+ C1(29+!J)*dummy_s1991 _
+ C1(30+!J)*dummy_s1992 _
+ C1(31+!J)*dummy_s1993 _
+ C1(32+!J)*dummy_s1994 _
+ C1(33+!J)*dummy_s1995 _
+ C1(34+!J)*dummy_s1996 _
+ C1(35+!J)*dummy_s1997 _
+ C1(36+!J)*dummy_s1998 _
+ C1(37+!J)*dummy_s1999 _
+ C1(38+!J)*dummy_s2000 _
+ C1(39+!J)*dummy_s2001 _
+ C1(40+!J)*dummy_s2002 _
+ C1(41+!J)*dummy_s2003 _
+ C1(42+!J)*dummy_s2004 _
+ C1(43+!J)*dummy_s2005 _
+ C1(44+!J)*dummy_s2006 _
+ C1(45+!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) 

	model.scenario(n,a=_1) "Alternative1"
	model.scenario(n,a=_2) "Alternative2"
	
	
	FOR %IDC {%LIST}
		SMPL @ALL
		GENR IMF_EB_S{%IDC}_1 = IMF_EB_S{%IDC}
		GENR IMF_TB_S{%IDC}_1 = IMF_TB_S{%IDC}
		GENR IMF_EB_S{%IDC}_2 = IMF_EB_S{%IDC}
		GENR IMF_TB_S{%IDC}_2 = IMF_TB_S{%IDC}

		smpl !year_e !year_s
		model.scenario "Alternative1"
		IMF_EB_S{%IDC}_1=1
		IMF_TB_S{%IDC}_1=0
		model.override(m) IMF_EB_S{%idc} IMF_TB_S{%idc}

		model.scenario "Alternative2"
		IMF_EB_S{%IDC}_2=0
		IMF_TB_S{%IDC}_2=1
		model.override(m) IMF_EB_S{%idc} IMF_TB_S{%idc}

	NEXT

	smpl !year_e+!nyears !year_s 
	
 	model.scenario "Baseline"
	model.solve
	
	model.scenario "Alternative1"
	model.solve

	model.scenario "Alternative2"
	model.solve

	'Store FE
	!I=50
	FOR %IDC {%LIST}
		genr FE{%idc}={%sys}.C1(!I+1)
		!I=!I+1
	next


