'**************************************************************************************************************************
'VAR specification, estimation, simulation, bootstrap and collection of responses of the variables after the shock
'**************************************************************************************************************************

PAGESELECT TimeSeries 
COEF(1000) C1
COEF(1000) C2
COEF(1000) C3
COEF(1000) C4
COEF(1000) C5
COEF(1000) C6
COEF(1000) C7
COEF(1000) C8

%MODEL = "TAX_UP" 		'this is the name of the model that we analyse in this specific program

'defining !m is needed to rename the residuals afterwards
!m=0
FOR %IDC  {%LIST}
		!m=!m+1
NEXT
IF !m>9 then 
		!m=9
ENDIF

SMPL !START !YEAR 

'create storage matrices for each variable in the VAR and for the state-indicator
FOR %IDC  {%LIST}
		FOR %VAR {%VARS} 
				MATRIX(!HORZ,!REPS) s_{%VAR}_{%IDC} = NA
		NEXT 
		MATRIX(!HORZ,!REPS) fs_baseline_{%IDC} = NA
		MATRIX(!HORZ,!REPS) fs_alt_{%IDC} = NA
		MATRIX(!HORZ,!REPS) fs_dev_{%IDC} = NA
NEXT

SCALAR a_fail=0					'this counts bootstrap repetitions
SCALAR a_counter=0

RNDSEED(type=mt) 123456 		'setting the seed

'set the systems
%SYS="sys_"+%MODEL
%SYS2="sys_"+%MODEL+"2"

'generating the series for estimation and simulation
FOR %IDC  {%LIST}
		SMPL @ALL
		GENR fs_s{%IDC} = fs_{%IDC}
		GENR y_pc_s{%IDC} = y_pc{%IDC}
		GENR t_s{%IDC} = t_{%IDC}	
		GENR g_s{%IDC} = g_{%IDC}
		GENR imf_tot_ut_s{%IDC} = imf_tot_ut{%IDC}
		GENR imf_tot_at_s{%IDC} = imf_tot_at{%IDC}
		GENR imf_tot_at1_s{%IDC} = imf_tot_at1{%IDC}
		GENR imf_tot_at2_s{%IDC} = imf_tot_at2{%IDC}
		'GENR imf_tot_at3_s{%IDC} = imf_tot_at3{%IDC}
		'GENR imf_tot_at4_s{%IDC} = imf_tot_at4{%IDC}
		'GENR imf_tot_at5_s{%IDC} = imf_tot_at5{%IDC}
		GENR imf_eb_s{%IDC} = imf_eb{%IDC}
		GENR imf_tb_s{%IDC} = imf_tb{%IDC}
		GENR imf_tax_ut_s{%IDC} = imf_tax_ut{%IDC}
		GENR imf_tax_att_s{%IDC} = imf_tax_att{%IDC}
		GENR imf_tax_att1_s{%IDC} = imf_tax_att1{%IDC}
		GENR imf_tax_att2_s{%IDC} = imf_tax_att2{%IDC}
'		GENR imf_tax_att3_s{%IDC} = imf_tax_att3{%IDC}
'		GENR imf_tax_att4_s{%IDC} = imf_tax_att4{%IDC}
'		GENR imf_tax_att5_s{%IDC} = imf_tax_att5{%IDC}
		GENR imf_spnd_ut_s{%IDC} = imf_spnd_ut{%IDC}
		GENR imf_spnd_att_s{%IDC} = imf_spnd_att{%IDC}
		GENR imf_spnd_att1_s{%IDC} = imf_spnd_att1{%IDC}
		GENR imf_spnd_att2_s{%IDC} = imf_spnd_att2{%IDC}
'		GENR imf_spnd_att3_s{%IDC} = imf_spnd_att3{%IDC}
'		GENR imf_spnd_att4_s{%IDC} = imf_spnd_att4{%IDC}
'		GENR imf_spnd_att5_s{%IDC} = imf_spnd_att5{%IDC}
NEXT

'generate time dummies
FOR %YEAR {%LIST_YEARS}
		GENR dummy_s{%YEAR} = dummy_{%YEAR}
NEXT

'DELETE {%SYS}*
SYSTEM {%SYS}
!J= 0
!I=200
!K=0

'append output 
FOR %IDC {%LIST}
	{%SYS}.APPEND y_pc_s{%IDC} = C1(1+!I) + C1(1+!J)*y_pc_s{%IDC}(-1)*fs_s{%IDC} + C1(2+!J)*y_pc_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C1(3+!J)*t_s{%IDC}(-1)*fs_s{%IDC} + C1(4+!J)*t_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C1(5+!J)*g_s{%IDC}(-1)*fs_s{%IDC} + C1(6+!J)*g_s{%IDC}(-1)*(1-fs_s{%IDC}) _

+C1(7+!J)*imf_tot_ut_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC} + C1(8+!J)*imf_tot_ut_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _
+C1(9+!J)*imf_tot_at_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC} + C1(10+!J)*imf_tot_at_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _
+C1(11+!J)*imf_tot_at1_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC} + C1(12+!J)*imf_tot_at1_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _
+C1(11+!J)*imf_tot_at2_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC} + C1(12+!J)*imf_tot_at2_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _

+C1(13+!J)*imf_tot_ut_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC} + C1(14+!J)*imf_tot_ut_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _
+C1(15+!J)*imf_tot_at_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC} + C1(16+!J)*imf_tot_at_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _
+C1(17+!J)*imf_tot_at1_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC} + C1(18+!J)*imf_tot_at1_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _
+C1(17+!J)*imf_tot_at2_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC} + C1(18+!J)*imf_tot_at2_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _

+ C1(50+!J)*dummy_s1982 + C1(51+!J)*dummy_s1983 + C1(52+!J)*dummy_s1984 + C1(53+!J)*dummy_s1985 + C1(54+!J)*dummy_s1986 + C1(55+!J)*dummy_s1987 + C1(56+!J)*dummy_s1988 + C1(57+!J)*dummy_s1989 + C1(58+!J)*dummy_s1990 + C1(59+!J)*dummy_s1991 + C1(60+!J)*dummy_s1992 + C1(61+!J)*dummy_s1993 + C1(62+!J)*dummy_s1994 + C1(63+!J)*dummy_s1995 + C1(64+!J)*dummy_s1996 + C1(65+!J)*dummy_s1997 + C1(66+!J)*dummy_s1998 + C1(67+!J)*dummy_s1999 + C1(68+!J)*dummy_s2000 + C1(69+!J)*dummy_s2001 + C1(70+!J)*dummy_s2002 + C1(71+!J)*dummy_s2003 + C1(72+!J)*dummy_s2004 + C1(72+!J)*dummy_s2005 + C1(73+!J)*dummy_s2006 + C1(74+!J)*dummy_s2007 + C1(75+!J)*dummy_s2008 + C1(76+!J)*dummy_s2009 + C1(77+!J)*dummy_s2010 + C1(78+!J)*dummy_s2011 + C1(79+!J)*dummy_s2012 + C1(80+!J)*dummy_s2013 + C1(81+!J)*dummy_s2014

'+C1(11+!J)*imf_tot_at3_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC}+C1(12+!J)*imf_tot_at3_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _ 
'+C1(11+!J)*imf_tot_at4_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC}+C1(12+!J)*imf_tot_at4_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _
'+C1(11+!J)*imf_tot_at5_s{%IDC}*fs_s{%IDC}*imf_eb_s{%IDC}+C1(12+!J)*imf_tot_at5_s{%IDC}*(1-fs_s{%IDC})*imf_eb_s{%IDC} _
'+C1(17+!J)*imf_tot_at3_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC}+C1(18+!J)*imf_tot_at3_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _
'+C1(17+!J)*imf_tot_at4_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC}+C1(18+!J)*imf_tot_at4_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _
'+C1(17+!J)*imf_tot_at5_s{%IDC}*fs_s{%IDC}*imf_tb_s{%IDC}+C1(18+!J)*imf_tot_at5_s{%IDC}*(1-fs_s{%IDC})*imf_tb_s{%IDC} _

		!I=!I+1 

NEXT

'append taxes
!J= 0
!I=200
!K=0
FOR %IDC {%LIST}
	{%SYS}.APPEND t_s{%IDC} = C2(1+!I) + C2(1+!J)*y_pc_s{%IDC}(-1)*fs_s{%IDC} + C2(2+!J)*y_pc_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C2(3+!J)*t_s{%IDC}(-1)*fs_s{%IDC} + C2(4+!J)*t_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C2(5+!J)*g_s{%IDC}(-1)*fs_s{%IDC} + C2(6+!J)*g_s{%IDC}(-1)*(1-fs_s{%IDC}) _

+C2(7+!J)*imf_tax_ut_s{%IDC} _
+C2(8+!J)*imf_tax_att_s{%IDC} _

+ C2(50+!J)*dummy_s1982 + C2(51+!J)*dummy_s1983 + C2(52+!J)*dummy_s1984 + C2(53+!J)*dummy_s1985 + C2(54+!J)*dummy_s1986 + C2(55+!J)*dummy_s1987 + C2(56+!J)*dummy_s1988 + C2(57+!J)*dummy_s1989 + C2(58+!J)*dummy_s1990 + C2(59+!J)*dummy_s1991 + C2(60+!J)*dummy_s1992 + C2(61+!J)*dummy_s1993 + C2(62+!J)*dummy_s1994 + C2(63+!J)*dummy_s1995 + C2(64+!J)*dummy_s1996 + C2(65+!J)*dummy_s1997 + C2(66+!J)*dummy_s1998 + C2(67+!J)*dummy_s1999 + C2(68+!J)*dummy_s2000 + C2(69+!J)*dummy_s2001 + C2(70+!J)*dummy_s2002 + C2(71+!J)*dummy_s2003 + C2(72+!J)*dummy_s2004 + C2(72+!J)*dummy_s2005 + C2(73+!J)*dummy_s2006 + C2(74+!J)*dummy_s2007 + C2(75+!J)*dummy_s2008 + C2(76+!J)*dummy_s2009 + C2(77+!J)*dummy_s2010 + C2(78+!J)*dummy_s2011 + C2(79+!J)*dummy_s2012 + C2(80+!J)*dummy_s2013 + C2(81+!J)*dummy_s2014

		!I=!I+1

NEXT

'append spending
!J= 0
!I=200
!K=0
FOR %IDC {%LIST}
	{%SYS}.APPEND g_s{%IDC} = C3(1+!I) + C3(1+!J)*y_pc_s{%IDC}(-1)*fs_s{%IDC} + C3(2+!J)*y_pc_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C3(3+!J)*t_s{%IDC}(-1)*fs_s{%IDC} + C3(4+!J)*t_s{%IDC}(-1)*(1-fs_s{%IDC}) _
+C3(5+!J)*g_s{%IDC}(-1)*fs_s{%IDC} + C3(6+!J)*g_s{%IDC}(-1)*(1-fs_s{%IDC}) _

+C3(7+!J)*imf_spnd_ut_s{%IDC} _
+C3(8+!J)*imf_spnd_att_s{%IDC} _

+ C3(50+!J)*dummy_s1982 + C3(51+!J)*dummy_s1983 + C3(52+!J)*dummy_s1984 + C3(53+!J)*dummy_s1985 + C3(54+!J)*dummy_s1986 + C3(55+!J)*dummy_s1987 + C3(56+!J)*dummy_s1988 + C3(57+!J)*dummy_s1989 + C3(58+!J)*dummy_s1990 + C3(59+!J)*dummy_s1991 + C3(60+!J)*dummy_s1992 + C3(61+!J)*dummy_s1993 + C3(62+!J)*dummy_s1994 + C3(63+!J)*dummy_s1995 + C3(64+!J)*dummy_s1996 + C3(65+!J)*dummy_s1997 + C3(66+!J)*dummy_s1998 + C3(67+!J)*dummy_s1999 + C3(68+!J)*dummy_s2000 + C3(69+!J)*dummy_s2001 + C3(70+!J)*dummy_s2002 + C3(71+!J)*dummy_s2003 + C3(72+!J)*dummy_s2004 + C3(72+!J)*dummy_s2005 + C3(73+!J)*dummy_s2006 + C3(74+!J)*dummy_s2007 + C3(75+!J)*dummy_s2008 + C3(76+!J)*dummy_s2009 + C3(77+!J)*dummy_s2010 + C3(78+!J)*dummy_s2011 + C3(79+!J)*dummy_s2012 + C3(80+!J)*dummy_s2013 + C3(81+!J)*dummy_s2014

		!I=!I+1

NEXT


'SYSTEM FOR BOOTSTRAP - USES THE VALUES OBTAINED AFTER HAVING SOLVED THE PREVIOUS SYSTEM
'****************************************************************************************************************************
'DELETE {%SYS2}*
SYSTEM {%SYS2}
!J= 0
!I=200
!K=0

'append output
FOR %IDC {%LIST}
	{%SYS2}.APPEND y_pc_s{%IDC}_0m = C4(1+!I) + C4(1+!J)*y_pc_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C4(2+!J)*y_pc_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C4(3+!J)*t_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C4(4+!J)*t_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C4(5+!J)*g_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C4(6+!J)*g_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _

+C4(7+!J)*imf_tot_ut_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC} + C4(8+!J)*imf_tot_ut_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
+C4(9+!J)*imf_tot_at_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC} + C4(10+!J)*imf_tot_at_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
+C4(11+!J)*imf_tot_at1_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC} + C4(12+!J)*imf_tot_at1_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
+C4(11+!J)*imf_tot_at2_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC} + C4(12+!J)*imf_tot_at2_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _

+C4(13+!J)*imf_tot_ut_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC} + C4(14+!J)*imf_tot_ut_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _
+C4(15+!J)*imf_tot_at_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC} + C4(16+!J)*imf_tot_at_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _
+C4(17+!J)*imf_tot_at1_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC} + C4(18+!J)*imf_tot_at1_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _
+C4(17+!J)*imf_tot_at2_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC} + C4(18+!J)*imf_tot_at2_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _

+ C4(50+!J)*dummy_s1982 + C4(51+!J)*dummy_s1983 + C4(52+!J)*dummy_s1984 + C4(53+!J)*dummy_s1985 + C4(54+!J)*dummy_s1986 + C4(55+!J)*dummy_s1987 + C4(56+!J)*dummy_s1988 + C4(57+!J)*dummy_s1989 + C4(58+!J)*dummy_s1990 + C4(59+!J)*dummy_s1991 + C4(60+!J)*dummy_s1992 + C4(61+!J)*dummy_s1993 + C4(62+!J)*dummy_s1994 + C4(63+!J)*dummy_s1995 + C4(64+!J)*dummy_s1996 + C4(65+!J)*dummy_s1997 + C4(66+!J)*dummy_s1998 + C4(67+!J)*dummy_s1999 + C4(68+!J)*dummy_s2000 + C4(69+!J)*dummy_s2001 + C4(70+!J)*dummy_s2002 + C4(71+!J)*dummy_s2003 + C4(72+!J)*dummy_s2004 + C4(72+!J)*dummy_s2005 + C4(73+!J)*dummy_s2006 + C4(74+!J)*dummy_s2007 + C4(75+!J)*dummy_s2008 + C4(76+!J)*dummy_s2009 + C4(77+!J)*dummy_s2010 + C4(78+!J)*dummy_s2011 + C4(79+!J)*dummy_s2012 + C4(80+!J)*dummy_s2013 + C4(81+!J)*dummy_s2014

'+C4(11+!J)*imf_tot_at3_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC}+C4(12+!J)*imf_tot_at3_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
'+C4(11+!J)*imf_tot_at4_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC}+C4(12+!J)*imf_tot_at4_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
'+C4(11+!J)*imf_tot_at5_s{%IDC}*fs_s{%IDC}_0m*imf_eb_s{%IDC}+C4(12+!J)*imf_tot_at5_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_eb_s{%IDC} _
'+C4(17+!J)*imf_tot_at3_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC}+C4(18+!J)*imf_tot_at3_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _
'+C4(17+!J)*imf_tot_at4_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC}+C4(18+!J)*imf_tot_at4_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _
'+C4(17+!J)*imf_tot_at5_s{%IDC}*fs_s{%IDC}_0m*imf_tb_s{%IDC}+C4(18+!J)*imf_tot_at5_s{%IDC}*(1-fs_s{%IDC}_0m)*imf_tb_s{%IDC} _

		!I=!I+1

NEXT

'append taxes
!J= 0
!I=200
!K=0
FOR %IDC {%LIST}
	{%SYS2}.APPEND t_s{%IDC}_0m = C5(1+!I) + C5(1+!J)*y_pc_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C5(2+!J)*y_pc_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C5(3+!J)*t_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C5(4+!J)*t_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C5(5+!J)*g_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C5(6+!J)*g_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _

+C5(7+!J)*imf_tax_ut_s{%IDC} _
+C5(8+!J)*imf_tax_att_s{%IDC} _

+ C5(50+!J)*dummy_s1982 + C5(51+!J)*dummy_s1983 + C5(52+!J)*dummy_s1984 + C5(53+!J)*dummy_s1985 + C5(54+!J)*dummy_s1986 + C5(55+!J)*dummy_s1987 + C5(56+!J)*dummy_s1988 + C5(57+!J)*dummy_s1989 + C5(58+!J)*dummy_s1990 + C5(59+!J)*dummy_s1991 + C5(60+!J)*dummy_s1992 + C5(61+!J)*dummy_s1993 + C5(62+!J)*dummy_s1994 + C5(63+!J)*dummy_s1995 + C5(64+!J)*dummy_s1996 + C5(65+!J)*dummy_s1997 + C5(66+!J)*dummy_s1998 + C5(67+!J)*dummy_s1999 + C5(68+!J)*dummy_s2000 + C5(69+!J)*dummy_s2001 + C5(70+!J)*dummy_s2002 + C5(71+!J)*dummy_s2003 + C5(72+!J)*dummy_s2004 + C5(72+!J)*dummy_s2005 + C5(73+!J)*dummy_s2006 + C5(74+!J)*dummy_s2007 + C5(75+!J)*dummy_s2008 + C5(76+!J)*dummy_s2009 + C5(77+!J)*dummy_s2010 + C5(78+!J)*dummy_s2011 + C5(79+!J)*dummy_s2012 + C5(80+!J)*dummy_s2013 + C5(81+!J)*dummy_s2014

		!I=!I+1

NEXT

'append spending
!J= 0
!I=200
!K=0
FOR %IDC {%LIST}
	{%SYS2}.APPEND g_s{%IDC}_0m = C6(1+!I) + C6(1+!J)*y_pc_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C6(2+!J)*y_pc_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C6(3+!J)*t_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C6(4+!J)*t_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _
+C6(5+!J)*g_s{%IDC}_0m(-1)*fs_s{%IDC}_0m + C6(6+!J)*g_s{%IDC}_0m(-1)*(1-fs_s{%IDC}_0m) _

+C6(7+!J)*imf_spnd_ut_s{%IDC} _
+C6(8+!J)*imf_spnd_att_s{%IDC} _

+ C6(50+!J)*dummy_s1982 + C6(51+!J)*dummy_s1983 + C6(52+!J)*dummy_s1984 + C6(53+!J)*dummy_s1985 + C6(54+!J)*dummy_s1986 + C6(55+!J)*dummy_s1987 + C6(56+!J)*dummy_s1988 + C6(57+!J)*dummy_s1989 + C6(58+!J)*dummy_s1990 + C6(59+!J)*dummy_s1991 + C6(60+!J)*dummy_s1992 + C6(61+!J)*dummy_s1993 + C6(62+!J)*dummy_s1994 + C6(63+!J)*dummy_s1995 + C6(64+!J)*dummy_s1996 + C6(65+!J)*dummy_s1997 + C6(66+!J)*dummy_s1998 + C6(67+!J)*dummy_s1999 + C6(68+!J)*dummy_s2000 + C6(69+!J)*dummy_s2001 + C6(70+!J)*dummy_s2002 + C6(71+!J)*dummy_s2003 + C6(72+!J)*dummy_s2004 + C6(72+!J)*dummy_s2005 + C6(73+!J)*dummy_s2006 + C6(74+!J)*dummy_s2007 + C6(75+!J)*dummy_s2008 + C6(76+!J)*dummy_s2009 + C6(77+!J)*dummy_s2010 + C6(78+!J)*dummy_s2011 + C6(79+!J)*dummy_s2012 + C6(80+!J)*dummy_s2013 + C6(81+!J)*dummy_s2014

		!I=!I+1

NEXT

'estimation
SMPL !START !YEAR
{%SYS}.LS

'residuals' collection (this is needed for the bootstrap)
DELETE resid1* resid2* resid3* resid4* resid6* resid7* resid8* resid9* resid0*
{%SYS}.MAKERESIDS(n=gres)
FOR !i = 1 TO !m
		SERIES resid{!i} = resid0{!i}
		DELETE resid0{!i}
NEXT

SCALAR temp_res = 0
FOR %VAR  {%VARS}
		FOR %IDC {%LIST} 
				temp_res = temp_res + 1
				!p = temp_res
				GENR res_{%VAR}_{%IDC} = resid{!p}
		NEXT
NEXT
delete temp_res*

'create fake g series for AUT before 1996 and g,y,t for DEU before 1992 (we don't have these values and they are needed to solve the model - they do not enter into estimation)
SMPL 1979 1995
g_saut = 0
SMPL 1979 1991
y_pc_sdeu = 0
t_sdeu = 0
g_sdeu = 0
SMPL 1979 1993
fs_sdeu = 0


'BOOTSTRAP (SMALL SAMPLE CORRECTION)   
'****************************************************
SMPL !START !YEAR
'create a model object from the first system above
MODEL model
model.MERGE {%SYS}

'adding shifts to the variables for bootstrap in the model (uses the residuals collected above)
FOR %IDC {%LIST}
 		FOR %VAR {%VARS} 
  				model.ADDASSIGN {%VAR}{%IDC} 
	 	NEXT
NEXT

'here start the bootstrap's repetitions

FOR !j=1 TO !REPS						'counting the number of executed repetitions
		a_counter = a_counter + 1	

		'resampling residuals
		SMPL !START !YEAR
		DELETE g1*
		GROUP g1
		FOR %IDC {%LIST}
				FOR %VAR {%VARS} 
						g1.add res_{%VAR}_{%IDC}
				NEXT 
		NEXT
		'generating fake residuals for DEU and AUT not available data  
		SMPL 1996 !YEAR
		SCALAR sigma = @var(res_g_s_aut)
		SMPL !START 1995
		res_g_s_aut = (sigma^0.5)*nrnd  
		FOR %VAR {%VARS}
				SMPL 1992 !YEAR
				SCALAR sigma=@var(res_{%VAR}_deu)
				SMPL !START 1991
				res_{%VAR}_deu=(sigma^0.5)*nrnd  
		NEXT
   
		SMPL !START !YEAR
		g1.RESAMPLE(block = 2,dropna)
		'generate the shifts for the variables 
		FOR %IDC {%LIST}
				FOR %VAR {%VARS} 
						series {%VAR}{%IDC}_a=res_{%VAR}_{%IDC}_b
						'delete res_{%VAR}_{%IDC}_b
				NEXT 
		NEXT

		'solving the model obtained from the first system
		model.STOCHASTIC(i=b, d=T, v=t, r=100, s=!START+1 !YEAR, f=.2, b=.83,c=F)
		model.SOLVEOPT(s=m)
		'model.APPEND assign @all  _0m 'to be activated only if sol=det) 
		SMPL !START  !YEAR
		model.SOLVE

		'generate F(s) series and distribution for each bootstrap repetition (we compute it from y_pc_0m)
				FOR %IDC {%LIST}
						INCLUDE fs_0m
				NEXT

		'drop values for AUT and DEU before estimation of second system (these data are not available a priori - even though they are computed when solving the model)
		SMPL 1979 1995
		g_saut_0m = NA
		SMPL 1979 1991
		y_pc_sdeu_0m = NA
		t_sdeu_0m = NA
		g_sdeu_0m = NA
		SMPL 1979 1993
		fs_sdeu_0m = NA

		'estimate second system
		SMPL !START !YEAR 
		{%SYS2}.LS

		'create fake g_0m series for AUT before 1996 and y_pc_0m, t_0m, g_0m for DEU before 1992 (needed to solve the second model)
		SMPL 1979 1995
		g_saut_0m = 0
		SMPL 1979 1991
		y_pc_sdeu_0m = 0
		t_sdeu_0m = 0
		g_sdeu_0m = 0
		SMPL 1979 1993
		fs_sdeu_0m = 0

		SMPL @ALL
		MODEL model_2
		model_2.MERGE {%SYS2}
		'add to model_2 the evolution equation of F(s) to get its IRF
		FOR %IDC {%LIST}
				model_2.APPEND fs_s{%IDC}_0m = (exp(-gamma_{%IDC}_0m*((y_pc_s{%IDC}_0m(-2) + y_pc_s{%IDC}_0m(-1) - 2*mean_{%IDC}_0m)*0.5)/sd_{%IDC}_0m))/(1 + (exp(-gamma_{%IDC}_0m*((y_pc_s{%IDC}_0m(-2) + y_pc_s{%IDC}_0m(-1) - 2*mean_{%IDC}_0m)*0.5)/sd_{%IDC}_0m)))
				model_2.INNOV fs_s{%IDC}_0m i		'it is an identity 
		NEXT

		'SCENARIO 
		model_2.APPEND assign @all  _ALT
		model_2.SCENARIO(n, a=_1) "Alternative"
		model_2.SCENARIO "Alternative"

		FOR %YEAR {%LIST_YEARS}
				SMPL @ALL
				GENR dummy_s{%YEAR}_1 = dummy_s{%YEAR}
		NEXT
	
		FOR %IDC  {%LIST}
				SMPL @ALL
				GENR imf_tot_ut_s{%IDC}_1 = imf_tot_ut_s{%IDC}
				GENR imf_tot_at_s{%IDC}_1 = imf_tot_at_s{%IDC}
				GENR imf_tot_at1_s{%IDC}_1 = imf_tot_at1_s{%IDC}
				GENR imf_tot_at2_s{%IDC}_1 = imf_tot_at2_s{%IDC}
				'GENR imf_tot_at3_s{%IDC}_1 = imf_tot_at3_s{%IDC}
				'GENR imf_tot_at4_s{%IDC}_1 = imf_tot_at4_s{%IDC}
				'GENR imf_tot_at5_s{%IDC}_1 = imf_tot_at5_s{%IDC}
				GENR imf_eb_s{%IDC}_1 = imf_eb_s{%IDC}
				GENR imf_tb_s{%IDC}_1 = imf_tb_s{%IDC}
				GENR imf_tax_ut_s{%IDC}_1 = imf_tax_ut_s{%IDC}
				GENR imf_tax_att_s{%IDC}_1 = imf_tax_att_s{%IDC}
				GENR imf_tax_att1_s{%IDC}_1 = imf_tax_att1_s{%IDC}
				GENR imf_tax_att2_s{%IDC}_1 = imf_tax_att2_s{%IDC}
				'GENR imf_tax_att3_s{%IDC}_1 = imf_tax_att3_s{%IDC}
				'GENR imf_tax_att4_s{%IDC}_1 = imf_tax_att4_s{%IDC}
				'GENR imf_tax_att5_s{%IDC}_1 = imf_tax_att5_s{%IDC}
				GENR imf_spnd_ut_s{%IDC}_1 = imf_spnd_ut_s{%IDC}
				GENR imf_spnd_att_s{%IDC}_1 = imf_spnd_att_s{%IDC}
				GENR imf_spnd_att1_s{%IDC}_1 = imf_spnd_att1_s{%IDC}
				GENR imf_spnd_att2_s{%IDC}_1 = imf_spnd_att2_s{%IDC}
				'GENR imf_spnd_att3_s{%IDC}_1 = imf_spnd_att3_s{%IDC}
				'GENR imf_spnd_att4_s{%IDC}_1 = imf_spnd_att4_s{%IDC}
				'GENR imf_spnd_att5_s{%IDC}_1 = imf_spnd_att5_s{%IDC}
				GENR fs_s{%IDC}_1 = fs_s{%IDC}

				'setting output, taxes and spending so that F(s) starts from expansion in simulation
				SMPL !YEAR_S !YEAR_S
 				y_pc_saus_0m = @ELEM(y_pcaus, "1997")
 				y_pc_saut_0m = @ELEM(y_pcaut, "1999")
				 y_pc_sbel_0m = @ELEM(y_pcbel, "1988")
				 y_pc_sdnk_0m = @ELEM(y_pcdnk, "1999")
				 y_pc_sdeu_0m = @ELEM(y_pcdeu, "1999")
				 y_pc_sfra_0m = @ELEM(y_pcfra, "1999")
				 y_pc_sesp_0m = @ELEM(y_pcesp, "1999")
				 y_pc_sgbr_0m = @ELEM(y_pcgbr, "1986")
				 y_pc_sirl_0m = @ELEM(y_pcirl, "1999")
				 y_pc_sita_0m = @ELEM(y_pcita, "1987")
				 y_pc_sjpn_0m = @ELEM(y_pcjpn, "1989")
				 y_pc_sprt_0m = @ELEM(y_pcprt, "1987")
				 y_pc_susa_0m = @ELEM(y_pcusa, "1999")
				 y_pc_scan_0m = @ELEM(y_pccan, "1999")
				 y_pc_sfin_0m = @ELEM(y_pcfin, "1999")
				 y_pc_sswe_0m = @ELEM(y_pcswe, "1999")
				SMPL !YEAR_S+1 !YEAR_S+1
 				y_pc_saus_0m = @ELEM(y_pcaus, "1998")
 				y_pc_saut_0m = @ELEM(y_pcaut, "2000")
				 y_pc_sbel_0m = @ELEM(y_pcbel, "1989")
				 y_pc_sdnk_0m = @ELEM(y_pcdnk, "2000")
				 y_pc_sdeu_0m = @ELEM(y_pcdeu, "2000")
				 y_pc_sfra_0m = @ELEM(y_pcfra, "2000")
				 y_pc_sesp_0m = @ELEM(y_pcesp, "2000")
				 y_pc_sgbr_0m = @ELEM(y_pcgbr, "1987")
				 y_pc_sirl_0m = @ELEM(y_pcirl, "2000")
				 y_pc_sita_0m = @ELEM(y_pcita, "1988")
				 y_pc_sjpn_0m = @ELEM(y_pcjpn, "1990")
				 y_pc_sprt_0m = @ELEM(y_pcprt, "1988")
				 y_pc_susa_0m = @ELEM(y_pcusa, "2000")
				 y_pc_scan_0m = @ELEM(y_pccan, "2000")
				 y_pc_sfin_0m = @ELEM(y_pcfin, "2000")
				 y_pc_sswe_0m = @ELEM(y_pcswe, "2000")
				SMPL !YEAR_S !YEAR_S
 				t_saus_0m = @ELEM(t_aus, "1997")
 				t_saut_0m = @ELEM(t_aut, "1999")
				 t_sbel_0m = @ELEM(t_bel, "1988")
				 t_sdnk_0m = @ELEM(t_dnk, "1999")
				 t_sdeu_0m = @ELEM(t_deu, "1999")
				 t_sfra_0m = @ELEM(t_fra, "1999")
				 t_sesp_0m = @ELEM(t_esp, "1999")
				 t_sgbr_0m = @ELEM(t_gbr, "1986")
				 t_sirl_0m = @ELEM(t_irl, "1999")
				 t_sita_0m = @ELEM(t_ita, "1987")
				 t_sjpn_0m = @ELEM(t_jpn, "1989")
				 t_sprt_0m = @ELEM(t_prt, "1987")
				 t_susa_0m = @ELEM(t_usa, "1999")
				 t_scan_0m = @ELEM(t_can, "1999")
				 t_sfin_0m = @ELEM(t_fin, "1999")
				 t_sswe_0m = @ELEM(t_swe, "1999")
				SMPL !YEAR_S+1 !YEAR_S+1
 				t_saus_0m = @ELEM(t_aus, "1998")
 				t_saut_0m = @ELEM(t_aut, "2000")
				 t_sbel_0m = @ELEM(t_bel, "1989")
				 t_sdnk_0m = @ELEM(t_dnk, "2000")
				 t_sdeu_0m = @ELEM(t_deu, "2000")
				 t_sfra_0m = @ELEM(t_fra, "2000")
				 t_sesp_0m = @ELEM(t_esp, "2000")
				 t_sgbr_0m = @ELEM(t_gbr, "1987")
				 t_sirl_0m = @ELEM(t_irl, "2000")
				 t_sita_0m = @ELEM(t_ita, "1988")
				 t_sjpn_0m = @ELEM(t_jpn, "1990")
				 t_sprt_0m = @ELEM(t_prt, "1988")
				 t_susa_0m = @ELEM(t_usa, "2000")
				 t_scan_0m = @ELEM(t_can, "2000")
				 t_sfin_0m = @ELEM(t_fin, "2000")
				 t_sswe_0m = @ELEM(t_swe, "2000")
				SMPL !YEAR_S !YEAR_S
 				g_saus_0m = @ELEM(g_aus, "1997")
 				g_saut_0m = @ELEM(g_aut, "1999")
				 g_sbel_0m = @ELEM(g_bel, "1988")
				 g_sdnk_0m = @ELEM(g_dnk, "1999")
				 g_sdeu_0m = @ELEM(g_deu, "1999")
				 g_sfra_0m = @ELEM(g_fra, "1999")
				 g_sesp_0m = @ELEM(g_esp, "1999")
				 g_sgbr_0m = @ELEM(g_gbr, "1986")
				 g_sirl_0m = @ELEM(g_irl, "1999")
				 g_sita_0m = @ELEM(g_ita, "1987")
				 g_sjpn_0m = @ELEM(g_jpn, "1989")
				 g_sprt_0m = @ELEM(g_prt, "1987")
				 g_susa_0m = @ELEM(g_usa, "1999")
				 g_scan_0m = @ELEM(g_can, "1999")
				 g_sfin_0m = @ELEM(g_fin, "1999")
				 g_sswe_0m = @ELEM(g_swe, "1999")
				SMPL !YEAR_S+1 !YEAR_S+1
 				g_saus_0m = @ELEM(g_aus, "1998")
 				g_saut_0m = @ELEM(g_aut, "2000")
				 g_sbel_0m = @ELEM(g_bel, "1989")
				 g_sdnk_0m = @ELEM(g_dnk, "2000")
				 g_sdeu_0m = @ELEM(g_deu, "2000")
				 g_sfra_0m = @ELEM(g_fra, "2000")
				 g_sesp_0m = @ELEM(g_esp, "2000")
				 g_sgbr_0m = @ELEM(g_gbr, "1987")
				 g_sirl_0m = @ELEM(g_irl, "2000")
				 g_sita_0m = @ELEM(g_ita, "1988")
				 g_sjpn_0m = @ELEM(g_jpn, "1990")
				 g_sprt_0m = @ELEM(g_prt, "1988")
				 g_susa_0m = @ELEM(g_usa, "2000")
				 g_scan_0m = @ELEM(g_can, "2000")
				 g_sfin_0m = @ELEM(g_fin, "2000")
				 g_sswe_0m = @ELEM(g_swe, "2000")

				'set alternative scenario
			 	SMPL !YEAR+1 !YEAR_S+1+!HORZ
				imf_tot_ut_s{%IDC}_1 =0
				imf_tot_ut_s{%IDC} =0
				imf_tot_at_s{%IDC}_1 = 0
				imf_tot_at_s{%IDC} = 0
				imf_tot_at1_s{%IDC}_1=0
				imf_tot_at1_s{%IDC}=0
				imf_tot_at2_s{%IDC}_1=0
				imf_tot_at2_s{%IDC}=0
				'imf_tot_at3_s{%IDC}_1=0
				'imf_tot_at3_s{%IDC}=0
				'imf_tot_at4_s{%IDC}_1=0
				'imf_tot_at4_s{%IDC}=0
				'imf_tot_at5_s{%IDC}_1=0
				'imf_tot_at5_s{%IDC}=0
				imf_eb_s{%IDC}_1 = 0
				imf_eb_s{%IDC} = 0
				imf_tb_s{%IDC}_1 = 0
				imf_tb_s{%IDC} = 0
				 imf_tax_ut_s{%IDC}_1 =0
				 imf_tax_ut_s{%IDC} =0
				 imf_tax_att_s{%IDC}_1 = 0
				 imf_tax_att_s{%IDC} = 0
				 imf_tax_att1_s{%IDC}_1=0
				 imf_tax_att1_s{%IDC}=0
				 imf_tax_att2_s{%IDC}_1=0
				 imf_tax_att2_s{%IDC}=0
				'imf_tax_att3_s{%IDC}_1=0
				'imf_tax_att3_s{%IDC}=0
				'imf_tax_att4_s{%IDC}_1=0
				'imf_tax_att4_s{%IDC}=0
				'imf_tax_att5_s{%IDC}_1=0
				'imf_tax_att5_s{%IDC}=0
				 imf_spnd_ut_s{%IDC}_1 =0
				 imf_spnd_ut_s{%IDC} =0
				 imf_spnd_att_s{%IDC}_1 = 0
				 imf_spnd_att_s{%IDC} = 0
				 imf_spnd_att1_s{%IDC}_1=0
				 imf_spnd_att1_s{%IDC}=0
				 imf_spnd_att2_s{%IDC}_1=0
				 imf_spnd_att2_s{%IDC}=0
				'imf_spnd_att3_s{%IDC}_1=0
				'imf_spnd_att3_s{%IDC}=0
				'imf_spnd_att4_s{%IDC}_1=0
				'imf_spnd_att4_s{%IDC}=0
				'imf_spnd_att5_s{%IDC}_1=0
				'imf_spnd_att5_s{%IDC}=0

				'impulse
				SMPL !YEAR_S+2 !YEAR_S+1+!HORZ
				imf_tb_s{%IDC}_1 = 1

				'model the correlations between shocks
				smpl !YEAR_S+2 !YEAR_S+2
				imf_tot_ut_s{%IDC}_1 = 1/(1 + sys_style_gt1.@COEFS(2) + sys_style_gt2.@COEFS(2) + sys_style_tt1.@COEFS(2) + sys_style_tt2.@COEFS(2))
				imf_tot_at1_s{%IDC}_1 = (sys_style_gt1.@COEFS(2) + sys_style_tt1.@COEFS(2))*imf_tot_ut_s{%IDC}_1
				imf_tot_at2_s{%IDC}_1 = (sys_style_gt2.@COEFS(2) + sys_style_tt2.@COEFS(2))*imf_tot_ut_s{%IDC}_1

				imf_tax_ut_s{%IDC}_1 = sys_style_tt.@COEFS(2)*imf_tot_ut_s{%IDC}_1
				'imf_tax_att_s{%IDC}_1 = 0
				imf_tax_att1_s{%IDC}_1 = sys_style_tt1.@COEFS(2)*imf_tot_ut_s{%IDC}_1	
				imf_tax_att2_s{%IDC}_1 = sys_style_tt2.@COEFS(2)*imf_tot_ut_s{%IDC}_1	
				'imf_tax_att3_s{%IDC}_1 = 0
				'imf_tax_att4_s{%IDC}_1 = 0
				'imf_tax_att5_s{%IDC}_1 = 0
				imf_spnd_ut_s{%IDC}_1 = sys_style_gt.@COEFS(2)*imf_tot_ut_s{%IDC}_1		
				'imf_spnd_att_s{%IDC}_1 = 0
				imf_spnd_att1_s{%IDC}_1 = sys_style_gt1.@COEFS(2)*imf_tot_ut_s{%IDC}_1
				imf_spnd_att2_s{%IDC}_1 = sys_style_gt2.@COEFS(2)*imf_tot_ut_s{%IDC}_1
				'imf_spnd_att3_s{%IDC}_1 = 0
				'imf_spnd_att4_s{%IDC}_1 = 0
				'imf_spnd_att5_s{%IDC}_1 = 0

				smpl !YEAR_S+3 !YEAR_S+3
				imf_tot_at1_s{%IDC}_1 = imf_tot_at2_s{%IDC}_1(-1)
                     imf_tot_at_s{%IDC}_1 = imf_tot_at1_s{%IDC}_1(-1)
				imf_tax_att_s{%IDC}_1 = imf_tax_att1_s{%IDC}_1(-1)
				imf_tax_att1_s{%IDC}_1 = imf_tax_att2_s{%IDC}_1(-1)
				'imf_tax_att2_s{%IDC}_1 = 0
				'imf_tax_att3_s{%IDC}_1 = 0
				'imf_tax_att4_s{%IDC}_1 = 0
				'imf_tax_att5_s{%IDC}_1 = 0
				imf_spnd_att_s{%IDC}_1 = imf_spnd_att1_s{%IDC}_1(-1)
				imf_spnd_att1_s{%IDC}_1 = imf_spnd_att2_s{%IDC}_1(-1)
				'imf_spnd_att2_s{%IDC}_1 = 0
				'imf_spnd_att3_s{%IDC}_1 = 0
				'imf_spnd_att4_s{%IDC}_1 = 0
				'imf_spnd_att5_s{%IDC}_1 = 0

				smpl !YEAR_S+4 !YEAR_S+4
				imf_tot_at_s{%IDC}_1 = imf_tot_at1_s{%IDC}_1(-1)
				imf_tax_att_s{%IDC}_1 = imf_tax_att1_s{%IDC}_1(-1)
				'imf_tax_att1_s{%IDC}_1 = 0
				'imf_tax_att2_s{%IDC}_1 = 0
				'imf_tax_att3_s{%IDC}_1 = 0
				'imf_tax_att4_s{%IDC}_1 = 0
				'imf_tax_att5_s{%IDC}_1 = 0
				imf_spnd_att_s{%IDC}_1 = imf_spnd_att1_s{%IDC}_1(-1)
				'imf_spnd_att1_s{%IDC}_1 = 0
				'imf_spnd_att2_s{%IDC}_1 = 0
				'imf_spnd_att3_s{%IDC}_1 = 0
				'imf_spnd_att4_s{%IDC}_1 = 0
				'imf_spnd_att5_s{%IDC}_1 = 0

				SMPL !YEAR+1 !YEAR_S+1+!HORZ
				model_2.OVERRIDE(m) imf_spnd_ut_s{%IDC} imf_spnd_att_s{%IDC} imf_spnd_att1_s{%IDC} imf_spnd_att2_s{%IDC} imf_spnd_att3_s{%IDC} imf_tax_ut_s{%IDC} imf_tax_att_s{%IDC} imf_tax_att1_s{%IDC} imf_tax_att2_s{%IDC} imf_tax_att3_s{%IDC} imf_tot_ut_s{%IDC} imf_tot_at_s{%IDC} imf_tot_at1_s{%IDC} imf_tot_at2_s{%IDC} imf_tb_s{%IDC}
		NEXT		

				'solving model_2
				model_2.SCENARIO(C) "Baseline"
				model_2.STOCHASTIC(i=b, d=T, v=t, r=100, s=!START+1 !YEAR, f=.1, b=.83,c=F)
				model_2.SOLVEOPT(s=m,d=d, A=T)
				SMPL !YEAR_S+2 !YEAR_S+!HORZ+1
				model_2.SOLVE

				'saving the responses of the VAR variables in the matrices defined at the beginning - if cumulated IR are needed uncomment this
				FOR %IDC {%LIST}
		 				FOR %VAR {%VARS} 
		 						SMPL !YEAR_S+2 !YEAR_S+2
								GENR {%VAR}{%IDC}_0m_1_altm_c = {%VAR}{%IDC}_0m_1_altm
		 						SMPL !YEAR_S+3 !YEAR_S+!HORZ+1
								SERIES {%VAR}{%IDC}_0m_1_altm_c = {%VAR}{%IDC}_0m_1_altm_c(-1) + {%VAR}{%IDC}_0m_1_altm
		 				NEXT
		 				SMPL !YEAR_S+2 !YEAR_S+!HORZ+1 
		 				FOR %VAR {%VARS} 
	 							'STOMNA( {%VAR}{%IDC}_0m_1_altm,temp) 'In the case of spread
								'activate if cumulated IR are needed
								STOMNA({%VAR}{%IDC}_0m_1_altm_c,temp) 
	 							COLPLACE(S_{%VAR}_{%IDC},temp,!j)
	 					NEXT 
						SMPL !YEAR_s+2 !YEAR_s+!horz+1 
						STOMNA(fs_s{%IDC}_0m_altm, tempbase)
						COLPLACE(fs_baseline_{%IDC}, tempbase, !j)
						STOMNA(fs_s{%IDC}_0m_1m, tempalt)
						COLPLACE(fs_alt_{%IDC}, tempalt, !j)
						STOMNA(fs_s{%IDC}_0m_1_altm, tempdev)
						COLPLACE(fs_dev_{%IDC}, tempdev, !j)
			NEXT
NEXT

'END OF THE BOOTSTRAP
'************************************************************
'find bootstrap percentiles for each horizon for output, taxes, spending and F(s)
FOR %IDC {%LIST}
	FOR %VAR {%VARS} 	
		MATRIX(!HORZ,3) rsp_{%VAR}_{%MODEL}_{%IDC}
		DELETE rtmp*
		ROWVECTOR rtmp
			FOR !i=1 TO !HORZ
				rtmp = @ROWEXTRACT(S_{%VAR}_{%IDC},!i)
				rsp_{%VAR}_{%MODEL}_{%IDC}(!i,1) = @QUANTILE(rtmp,0.84)
				rsp_{%VAR}_{%MODEL}_{%IDC}(!i,2) = @QUANTILE(rtmp,0.50)
				rsp_{%VAR}_{%MODEL}_{%IDC}(!i,3) = @QUANTILE(rtmp,0.16)
			NEXT
	NEXT
	MATRIX(!HORZ,3) rsp_fsb_{%MODEL}_{%IDC}
	DELETE fsbase_rtmp*
	ROWVECTOR fsbase_rtmp
			FOR !i=1 TO !HORZ
				fsbase_rtmp = @ROWEXTRACT(fs_baseline_{%IDC},!i)
				rsp_fsb_{%MODEL}_{%IDC}(!i,1) = @QUANTILE(fsbase_rtmp,0.84)
				rsp_fsb_{%MODEL}_{%IDC}(!i,2) = @QUANTILE(fsbase_rtmp,0.50)
				rsp_fsb_{%MODEL}_{%IDC}(!i,3) = @QUANTILE(fsbase_rtmp,0.16)
			NEXT
	MATRIX(!HORZ,3) rsp_fsa_{%MODEL}_{%IDC}
	DELETE fsalt_rtmp*
	ROWVECTOR fsalt_rtmp
			FOR !i=1 TO !HORZ
				fsalt_rtmp = @ROWEXTRACT(fs_alt_{%IDC},!i)
				rsp_fsa_{%MODEL}_{%IDC}(!i,1) = @QUANTILE(fsalt_rtmp,0.84)
				rsp_fsa_{%MODEL}_{%IDC}(!i,2) = @QUANTILE(fsalt_rtmp,0.50)
				rsp_fsa_{%MODEL}_{%IDC}(!i,3) = @QUANTILE(fsalt_rtmp,0.16)
			NEXT
	MATRIX(!HORZ,3) rsp_fsd_{%MODEL}_{%IDC}
	DELETE fsdev_rtmp*
	ROWVECTOR fsdev_rtmp
			FOR !i=1 TO !HORZ
				fsdev_rtmp = @ROWEXTRACT(fs_dev_{%IDC},!i)
				rsp_fsd_{%MODEL}_{%IDC}(!i,1) = @QUANTILE(fsdev_rtmp,0.84)
				rsp_fsd_{%MODEL}_{%IDC}(!i,2) = @QUANTILE(fsdev_rtmp,0.50)
				rsp_fsd_{%MODEL}_{%IDC}(!i,3) = @QUANTILE(fsdev_rtmp,0.16)
			NEXT
	'create a unique matrix for fs
	MATRIX(!HORZ,4) rsp_fs_{%MODEL}_{%IDC}
	FOR !i=1 TO 3
		COLPLACE(rsp_fs_{%MODEL}_{%IDC}, @COLUMNEXTRACT(rsp_fsa_{%MODEL}_{%IDC},!i), !i+1)
	NEXT
	COLPLACE(rsp_fs_{%MODEL}_{%IDC}, @COLUMNEXTRACT(rsp_fsb_{%MODEL}_{%IDC},2), 1)
NEXT

'deleting variables that are not needed anymore
FOR %VAR {%VARS}
		FOR %IDC {%LIST}
				DELETE {%VAR}{%IDC}_*
				DELETE {%VAR}_{%IDC}_a*
				DELETE {%VAR}_s{%IDC}*
		NEXT
NEXT

FOR %IDC {%LIST}
		DELETE fs_s{%IDC}_*
		DELETE fs_s{%IDC}*
		DELETE sd_{%IDC}_0m
		DELETE recessions_{%IDC}_0m
		DELETE prob_rec_{%IDC}_0m
		DELETE prob_exp_{%IDC}_0m
		DELETE n_rec_{%IDC}_0m
		DELETE mean_{%IDC}_0m
		DELETE ma_y_{%IDC}_0m
		DELETE gamma_{%IDC}_0m
NEXT

DELETE  s_* rtmp fs_dev_* fs_baseline_* fs_alt_* rsp_fsa* rsp_fsb* fsdev_rtmp fsalt_rtmp fsbase_rtmp temp model* %SYS2 resid* res* imf_tax_ut_s* imf_tax_att_s* imf_tax_att1_s* imf_tax_att2_s* imf_tax_att3_s* imf_tax_att4_s* imf_tax_att5_s* imf_spnd_ut_s* imf_spnd_att_s* imf_spnd_att1_s* imf_spnd_att2_s* imf_spnd_att3_s* imf_spnd_att4_s* imf_spnd_att5_s* tot_shock_s* dummy_s* imf_tb_s* imf_eb_s* imf_tot_at1_s* imf_tot_at2_s* imf_tot_at_s* imf_tot_ut_s*  'rsp*


