'load data
'remember monthly dataset 1970:01 2002:12

read(d=t,name,label=1,skipcol=1) c:\unzipped\fmn-files\eu.txt 170

'forward-looking taylor rules plus assessing the joint significance of the instrumental variables
'one-sided fhlr factors and contemporaneous instruments

smpl 1983:01 1997:12

for %country bd fra ita spa

	if %country="bd" then
		%strum=" c usinfl bdgap(-1) bdinfl(-1) bdibk3m(-1) bdinft "
		equation tay{%country}_base.gmm bdibk3m=c(1)*(1-c(2))+c(3)*(1-c(2))*bdgap+c(4)*(1-c(2))*(bdinfl(+12)-bdinft)+c(2)*bdibk3m(-1) @ %strum
		equation tay{%country}_fh3sc.gmm bdibk3m=c(1)*(1-c(2))+c(3)*(1-c(2))*bdgap+c(4)*(1-c(2))*(bdinfl(+12)-bdinft)+c(2)*bdibk3m(-1) @ %strum bdfact_6os1 bdfact_6os2 bdfact_6os3
		equation tay{%country}_sw3sc.gmm bdibk3m=c(1)*(1-c(2))+c(3)*(1-c(2))*bdgap+c(4)*(1-c(2))*(bdinfl(+12)-bdinft)+c(2)*bdibk3m(-1) @ %strum bdfact_bp1 bdfact_bp2 bdfact_bp3
		equation instr{%country}_fh3sc.ls bdinfl(12) %strum bdfact_6os1 bdfact_6os2 bdfact_6os3
		equation instr{%country}_sw3sc.ls bdinfl(12) %strum bdfact_bp1 bdfact_bp2 bdfact_bp3
		equation instr{%country}_base.ls bdinfl(12) %strum 
	else %strum="c usinfl "+%country+"gap(-1) "+%country+"infl(-1) "+%country+"ibk3m(-1) bdibk3m(-1) bdinft "

		equation instr{%country}_base.ls {%country}infl(12) %strum 
		if %country="fra" then 
			equation tay{%country}_base.gmm fraibk3m=c(3)*(1-c(2))*fragap+c(4)*(1-c(2))*(frainfl(+12)-bdinft)+c(2)*fraibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum
			equation tay{%country}_fh6eu.gmm fraibk3m=c(3)*(1-c(2))*fragap+c(4)*(1-c(2))*(frainfl(+12)-bdinft)+c(2)*fraibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6
			equation tay{%country}_sw6eu.gmm fraibk3m=c(3)*(1-c(2))*fragap+c(4)*(1-c(2))*(frainfl(+12)-bdinft)+c(2)*fraibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum eufact4_bp1 eufact4_bp2 eufact4_bp3 eufact4_bp4 eufact4_bp5 eufact4_bp6
			equation instr{%country}_fh6eu.ls {%country}infl(12) %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6
			equation instr{%country}_sw6eu.ls {%country}infl(12) %strum eufact4_bp1 eufact4_bp2 eufact4_bp3 eufact4_bp4 eufact4_bp5 eufact4_bp6
		endif

		if %country="ita" then
			equation tay{%country}_base.gmm itaibk3m=c(3)*(1-c(2))*itagap+c(4)*(1-c(2))*(itainfl(+12)-bdinft)+c(2)*itaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum
			equation tay{%country}_fh3eu.gmm itaibk3m=c(3)*(1-c(2))*itagap+c(4)*(1-c(2))*(itainfl(+12)-bdinft)+c(2)*itaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3
			equation tay{%country}_sw3sc.gmm itaibk3m=c(3)*(1-c(2))*itagap+c(4)*(1-c(2))*(itainfl(+12)-bdinft)+c(2)*itaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum itafact_bp1 itafact_bp2 itafact_bp3
			equation instr{%country}_fh3eu.ls {%country}infl(12) %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 
			equation instr{%country}_sw3sc.ls {%country}infl(12) %strum itafact_bp1 itafact_bp2 itafact_bp3
		endif

		if %country="spa" then
			equation tay{%country}_base.gmm spaibk3m=c(3)*(1-c(2))*spagap+c(4)*(1-c(2))*(spainfl(+12)-bdinft)+c(2)*spaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum
			equation tay{%country}_fh6eu.gmm spaibk3m=c(3)*(1-c(2))*spagap+c(4)*(1-c(2))*(spainfl(+12)-bdinft)+c(2)*spaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6
			equation tay{%country}_sw6eu.gmm spaibk3m=c(3)*(1-c(2))*spagap+c(4)*(1-c(2))*(spainfl(+12)-bdinft)+c(2)*spaibk3m(-1)+c(5)*(1-c(2))*bdibk3m(-1) @ %strum eufact4_bp1 eufact4_bp2 eufact4_bp3 eufact4_bp4 eufact4_bp5 eufact4_bp6
			equation instr{%country}_fh6eu.ls {%country}infl(12) %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6
			equation instr{%country}_sw6eu.ls {%country}infl(12) %strum eufact4_bp1 eufact4_bp2 eufact4_bp3 eufact4_bp4 eufact4_bp5 eufact4_bp6
		endif
	endif
next



table(51,10) table_taylor
table(1,1) temp

'Germany

scalar nc=4

!r=1
for %meth base fh3sc sw3sc 

	if %meth ="base" then
		scalar instr=6
	else scalar instr=9
	endif

	scalar ro=taybd_{%meth}.@coefs(2)
	scalar ga=taybd_{%meth}.@coefs(3)
	scalar be=taybd_{%meth}.@coefs(4)
	scalar ro_se=taybd_{%meth}.@stderrs(2)
	scalar ga_se=taybd_{%meth}.@stderrs(3)
	scalar be_se=taybd_{%meth}.@stderrs(4)
	scalar radj=taybd_{%meth}.@rbar2
	scalar ser=taybd_{%meth}.@se
	scalar overid=taybd_{%meth}.@regobs*taybd_{%meth}.@jstat
	scalar overid_p=1-@cchisq(overid,instr-nc)
	
	!c=1

	for %coef ro ga be
		setcell(table_taylor,!r,!c,{%coef},"c",2)
		setcell(temp,1,1,{%coef}_se,"c",3)
		%entry=temp(1,1)
		setcell(table_taylor,!r+1,!c,"("+ %entry +")","c")
		!c=!c+1
	next

	setcell(table_taylor,!r,5,radj,"c",3)
	setcell(table_taylor,!r,6,ser,"c",3)
	setcell(table_taylor,!r,7,overid,"c",2)
	setcell(temp,1,1,overid_p,"c",2)
	%opstr=@left(@str(overid_p),4)
	setcell(table_taylor,!r+1,7,"("+ %opstr +")", "c")

	scalar radj=instrbd_{%meth}.@rbar2
	scalar ser=instrbd_{%meth}.@se

	if %meth="base" then
		scalar f=0
		scalar fp=0
		%fpval=@str(fp)
	else
		freeze(wald) instrbd_{%meth}.wald c(7)=0, c(8)=0, c(9)=0
		scalar f=@val(wald(6,2))
		scalar fp=@val(wald(6,4))
		%fpval=@str(fp)
		delete wald
	endif
	
	setcell(table_taylor,!r,8,radj,"c",3)
	setcell(table_taylor,!r,9,ser,"c",3)
	setcell(table_taylor,!r,10,f,"c",3)
	setcell(table_taylor,!r+1,10,"("+ %fpval +")", "c")
	!r=!r+2
next


'Other countries

scalar nc=3
	

for %country fra ita spa


	
	if %country="fra" then

	!r=8
		for %meth base fh6eu sw6eu

			if %meth="base" then
				scalar instr=7
			else scalar instr=13
			endif	

			scalar ro=tay{%country}_{%meth}.@coefs(2)
			scalar ga=tay{%country}_{%meth}.@coefs(1)
			scalar be=tay{%country}_{%meth}.@coefs(3)
			scalar ro_se=tay{%country}_{%meth}.@stderrs(2)
			scalar ga_se=tay{%country}_{%meth}.@stderrs(1)
			scalar be_se=tay{%country}_{%meth}.@stderrs(3)
			scalar radj=tay{%country}_{%meth}.@rbar2
			scalar ser=tay{%country}_{%meth}.@se
			scalar overid=tay{%country}_{%meth}.@regobs*tay{%country}_{%meth}.@jstat
			scalar overid_p=1-@cchisq(overid,instr-nc)

			!c=1

			for %coef ro ga be
				setcell(table_taylor,!r,!c,{%coef},"c",2)
				setcell(temp,1,1,{%coef}_se,"c",3)
				%entry=temp(1,1)
				setcell(table_taylor,!r+1,!c,"("+ %entry +")","c")
				!c=!c+1
			next

		freeze(wald_f) tay{%country}_{%meth}.wald c(5)=1
		scalar wald_stat=@val(wald_f(14,3))
		scalar wald_se=@val(wald_f(14,4))
		setcell(table_taylor,!r,4,wald_stat,"c",3)
		setcell(temp,1,1,wald_se,"c",3)
		%entry=temp(1,1)
		setcell(table_taylor,!r+1,4,"("+ %entry +")","c")			

		delete wald_f wald_stat wald_se
	
			setcell(table_taylor,!r,5,radj,"c",3)
			setcell(table_taylor,!r,6,ser,"c",3)
			setcell(table_taylor,!r,7,overid,"c",2)
			%opstr=@left(@str(overid_p),4)
			setcell(table_taylor,!r+1,7,"("+ %opstr +")", "c")

			scalar radj=instr{%country}_{%meth}.@rbar2
			scalar ser=instr{%country}_{%meth}.@se

			if %meth="base" then
				scalar f=0
				scalar fp=0
				%fpval=@str(fp)
			else
				freeze(wald) instr{%country}_{%meth}.wald c(7)=0, c(8)=0, c(9)=0, c(10)=0, c(11)=0, c(12)=0
				scalar f=@val(wald(6,2))
				scalar fp=@val(wald(6,4))
				%fpval=@str(fp)
				delete wald
			endif
	
			setcell(table_taylor,!r,8,radj,"c",3)
			setcell(table_taylor,!r,9,ser,"c",3)
			setcell(table_taylor,!r,10,f,"c",3)
			setcell(table_taylor,!r+1,10,"("+ %fpval +")", "c")
			!r=!r+2
		next
	endif

	if %country="ita" then

	!r=15
		for %meth base fh3eu sw3sc

			if %meth="base" then
				scalar instr=7
			else scalar instr=10
			endif	

			scalar ro=tay{%country}_{%meth}.@coefs(2)
			scalar ga=tay{%country}_{%meth}.@coefs(1)
			scalar be=tay{%country}_{%meth}.@coefs(3)
			scalar ro_se=tay{%country}_{%meth}.@stderrs(2)
			scalar ga_se=tay{%country}_{%meth}.@stderrs(1)
			scalar be_se=tay{%country}_{%meth}.@stderrs(3)
			scalar radj=tay{%country}_{%meth}.@rbar2
			scalar ser=tay{%country}_{%meth}.@se
			scalar overid=tay{%country}_{%meth}.@regobs*tay{%country}_{%meth}.@jstat
			scalar overid_p=1-@cchisq(overid,instr-nc)

			!c=1

			for %coef ro ga be
				setcell(table_taylor,!r,!c,{%coef},"c",2)
				setcell(temp,1,1,{%coef}_se,"c",3)
				%entry=temp(1,1)
				setcell(table_taylor,!r+1,!c,"("+ %entry +")","c")
				!c=!c+1
			next

		freeze(wald_f) tay{%country}_{%meth}.wald c(5)=1
		scalar wald_stat=@val(wald_f(14,3))
		scalar wald_se=@val(wald_f(14,4))
		setcell(table_taylor,!r,4,wald_stat,"c",3)
		setcell(temp,1,1,wald_se,"c",3)
		%entry=temp(1,1)
		setcell(table_taylor,!r+1,4,"("+ %entry +")","c")			

		delete wald_f wald_stat wald_se
	
			setcell(table_taylor,!r,5,radj,"c",3)
			setcell(table_taylor,!r,6,ser,"c",3)
			setcell(table_taylor,!r,7,overid,"c",2)
			%opstr=@left(@str(overid_p),4)
			setcell(table_taylor,!r+1,7,"("+ %opstr +")", "c")

			scalar radj=instr{%country}_{%meth}.@rbar2
			scalar ser=instr{%country}_{%meth}.@se

			if %meth="base" then
				scalar f=0
				scalar fp=0
				%fpval=@str(fp)
			else
				freeze(wald) instr{%country}_{%meth}.wald c(7)=0, c(8)=0, c(9)=0
				scalar f=@val(wald(6,2))
				scalar fp=@val(wald(6,4))
				%fpval=@str(fp)
				delete wald
			endif
			
			setcell(table_taylor,!r,8,radj,"c",3)
			setcell(table_taylor,!r,9,ser,"c",3)
			setcell(table_taylor,!r,10,f,"c",3)
			setcell(table_taylor,!r+1,10,"("+ %fpval +")", "c")
			!r=!r+2
		next
	endif

	if %country="spa" then

	!r=22
		for %meth base fh6eu sw6eu

			if %meth="base" then
				scalar instr=7
			else scalar instr=13
			endif	

			scalar ro=tay{%country}_{%meth}.@coefs(2)
			scalar ga=tay{%country}_{%meth}.@coefs(1)
			scalar be=tay{%country}_{%meth}.@coefs(3)
			scalar ro_se=tay{%country}_{%meth}.@stderrs(2)
			scalar ga_se=tay{%country}_{%meth}.@stderrs(1)
			scalar be_se=tay{%country}_{%meth}.@stderrs(3)
			scalar radj=tay{%country}_{%meth}.@rbar2
			scalar ser=tay{%country}_{%meth}.@se
			scalar overid=tay{%country}_{%meth}.@regobs*tay{%country}_{%meth}.@jstat
			scalar overid_p=1-@cchisq(overid,instr-nc)

			!c=1

			for %coef ro ga be
				setcell(table_taylor,!r,!c,{%coef},"c",2)
				setcell(temp,1,1,{%coef}_se,"c",3)
				%entry=temp(1,1)
				setcell(table_taylor,!r+1,!c,"("+ %entry +")","c")
				!c=!c+1
			next

		freeze(wald_f) tay{%country}_{%meth}.wald c(5)=1
		scalar wald_stat=@val(wald_f(14,3))
		scalar wald_se=@val(wald_f(14,4))
		setcell(table_taylor,!r,4,wald_stat,"c",3)
		setcell(temp,1,1,wald_se,"c",3)
		%entry=temp(1,1)
		setcell(table_taylor,!r+1,4,"("+ %entry +")","c")			

		delete wald_f wald_stat wald_se
	
			setcell(table_taylor,!r,5,radj,"c",3)
			setcell(table_taylor,!r,6,ser,"c",3)
			setcell(table_taylor,!r,7,overid,"c",2)
			%opstr=@left(@str(overid_p),4)
			setcell(table_taylor,!r+1,7,"("+ %opstr +")", "c")

			scalar radj=instr{%country}_{%meth}.@rbar2
			scalar ser=instr{%country}_{%meth}.@se

			if %meth="base" then
				scalar f=0
				scalar fp=0
				%fpval=@str(fp)
			else
				freeze(wald) instr{%country}_{%meth}.wald c(7)=0, c(8)=0, c(9)=0, c(10)=0, c(11)=0, c(12)=0
				scalar f=@val(wald(6,2))
				scalar fp=@val(wald(6,4))
				%fpval=@str(fp)
				delete wald
			endif
	
			setcell(table_taylor,!r,8,radj,"c",3)
			setcell(table_taylor,!r,9,ser,"c",3)
			setcell(table_taylor,!r,10,f,"c",3)
			setcell(table_taylor,!r+1,10,"("+ %fpval +")", "c")
			!r=!r+2
		next
	endif

next

delete nc instr temp ro ga be ro_se ga_se be_se radj ser overid overid_p f fp 



'VARs and impulse response functions

smpl 1983:1 1997:12

'VARs and impulse response functions

for %country bd fra ita spa
	smpl 1983:1 1997:8

		%c2=@left(%country,2)
		%regrlist="l"+%c2+"ip "+%country+"infl "+%country+"ibk3m "

		if %country="bd" then %strum="c usinfl "
		else %strum="c usinfl bdibk3m bdinft "
		endif
	
		var var{%country}_base.ls 1 6 %regrlist @ %strum
		freeze(i_{%country}_base) var{%country}_base.impulse(36,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m

	%fn=%country+"fact_"
	%fe="eufact4_bp"

	if %country="bd" then
		var var{%country}_fh3sc.ls 1 6 %regrlist @ %strum {%fn}os1 {%fn}os2 {%fn}os3 
		freeze(i_{%country}_fh3sc) var{%country}_fh3sc.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		var var{%country}_sw3sc.ls 1 6 %regrlist @ %strum {%fn}bp1 {%fn}bp2 {%fn}bp3 
		freeze(i_{%country}_sw3sc) var{%country}_sw3sc.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		graph i_{%country}.merge i_{%country}_base i_{%country}_fh3sc i_{%country}_sw3sc 
		i_{%country}.align(3,1.5,1.5)
	endif

	if %country="fra" then
		var var{%country}_fh6eu.ls 1 6 %regrlist @ %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6 
		freeze(i_{%country}_fh6eu) var{%country}_fh6eu.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		var var{%country}_sw6eu.ls 1 6 %regrlist @ %strum {%fe}1 {%fe}2 {%fe}3 {%fe}4 {%fe}5 {%fe}6 
		freeze(i_{%country}_sw6eu) var{%country}_sw6eu.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		graph i_{%country}.merge i_{%country}_base i_{%country}_fh6eu i_{%country}_sw6eu
		i_{%country}.align(3,1.5,1.5)
	endif

	if %country="ita" then
		var var{%country}_fh3eu.ls 1 6 %regrlist @ %strum eu4fact_3os1 eu4fact_3os2 eu4fact_3os3 
		freeze(i_{%country}_fh3eu) var{%country}_fh3eu.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		var var{%country}_sw3sc.ls 1 6 %regrlist @ %strum {%fn}bp1 {%fn}bp2 {%fn}bp3 
		freeze(i_{%country}_sw3sc) var{%country}_sw3sc.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		graph i_{%country}.merge i_{%country}_base i_{%country}_fh3eu i_{%country}_sw3sc
		i_{%country}.align(3,1.5,1.5)
	endif

	if %country="spa" then
		var var{%country}_fh6eu.ls 1 6 %regrlist @ %strum eu4fact_6os1 eu4fact_6os2 eu4fact_6os3 eu4fact_6os4 eu4fact_6os5 eu4fact_6os6 
		freeze(i_{%country}_fh6eu) var{%country}_fh6eu.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		var var{%country}_sw6eu.ls 1 6 %regrlist @ %strum {%fe}1 {%fe}2 {%fe}3 {%fe}4 {%fe}5 {%fe}6 
		freeze(i_{%country}_sw6eu) var{%country}_sw6eu.impulse(40,m,imp=chol,se=a) l{%c2}ip {%country}infl {%country}ibk3m @ {%country}ibk3m
		graph i_{%country}.merge i_{%country}_base i_{%country}_fh6eu i_{%country}_sw6eu
		i_{%country}.align(3,1.5,1.5)
	endif

next

