'load data 
'remember monthly dataset 1959:03 1998:12

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


'forward-looking taylor rules for the us
'one-sided fhlr factors and contemporaneous instruments

smpl 1983:01 1997:12

	%strum="C USGAP(-1) USINFL(-1) LPCM(-1) LPCM(-2) USPR(-1) D12LUSEMP(-1)"

	equation tayus_base.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum
	equation tayus_bp12.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum usfact_bp01 usfact_bp02 usfact_bp03 usfact_bp04 usfact_bp05 usfact_bp06 usfact_bp07 usfact_bp08 usfact_bp09 usfact_bp10 usfact_bp11 usfact_bp12
	equation tayus_bp6.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum usfact_bp01 usfact_bp02 usfact_bp03 usfact_bp04 usfact_bp05 usfact_bp06
	equation tayus_bp3.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum usfact_bp01 usfact_bp02 usfact_bp03
	equation tayus_fh6.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum usfact_fh01 usfact_fh02 usfact_fh03 usfact_fh04 usfact_fh05 usfact_fh06
	equation tayus_fh3.gmm USPR=C(1)*(1-C(2))+C(3)*(1-C(2))*USGAP+C(4)*(1-C(2))*(USINFL(+12)-2)+C(2)*USPR(-1) @ %strum usfact_fh3_os1 usfact_fh3_os2 usfact_fh3_os3

	table(22,10) tab_taylor
	table(1,1) temp

	scalar nc=4

	!r=1
	for %meth base fh3 fh6 bp3 bp6 bp12 
		if %meth ="base" then
			scalar instr=7
		else %nfac=@mid(%meth,3)
			scalar instr=7+@val(%nfac)
		endif
		!c=2
		for %coef ro ga be
			!i=!c
			scalar {%coef}=tayus_{%meth}.@coefs(!i)
			scalar {%coef}_se=tayus_{%meth}.@stderrs(!i)
			setcell(tab_taylor,!r,!c,{%coef},"c",2)
			setcell(temp,1,1,{%coef}_se,"l",3)
			%entry=temp(1,1)
			setcell(tab_taylor,!r+1,!c,"("+ %entry +")","c")
			!c=!c+1
		next
	
		scalar radj=tayus_{%meth}.@rbar2
		scalar ser=tayus_{%meth}.@se
		scalar overid=tayus_{%meth}.@regobs*tayus_{%meth}.@jstat
		scalar overid_p=1-@cchisq(overid,instr-nc)

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

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


'assessing the joint significance of the instrumental variables

	%reg="usinfl(+12) c usgap(-1) usinfl(-1) lpcm(-1) lpcm(-2) uspr(-1) d12lusemp(-1) "

	equation instr_base.ls %reg
	equation instr_bp12.ls %reg usfact_bp01 usfact_bp02 usfact_bp03 usfact_bp04 usfact_bp05 usfact_bp06 usfact_bp07 usfact_bp08 usfact_bp09 usfact_bp10 usfact_bp11 usfact_bp12
	equation instr_bp6.ls %reg usfact_bp01 usfact_bp02 usfact_bp03 usfact_bp04 usfact_bp05 usfact_bp06
	equation instr_bp3.ls %reg usfact_bp01 usfact_bp02 usfact_bp03
	equation instr_fh6.ls %reg usfact_fh01 usfact_fh02 usfact_fh03 usfact_fh04 usfact_fh05 usfact_fh06
	equation instr_fh3.ls %reg usfact_fh3_os1 usfact_fh3_os2 usfact_fh3_os3

	!r=1
	for %meth base fh3 fh6 bp3 bp6 bp12 

		if %meth ="base" then
			scalar instr=7
		else %nfac=@mid(%meth,3)
			scalar instr=7+@val(%nfac)
		endif

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

		if %meth="base" then
			scalar f=0
			scalar fp=0
			%fpval=@str(fp)
		endif

		if %meth="fh3" or %meth="bp3" then
			freeze(wald) instr_{%meth}.wald c(8)=0, c(9)=0, c(10)=0
			scalar f=@val(wald(6,2))
			scalar fp=@val(wald(6,4))
			%fpval=@str(fp)
			delete wald
		endif

		if %meth="fh6" or %meth="bp6" then
			freeze(wald)  instr_{%meth}.wald c(8)=0, c(9)=0, c(10)=0, c(11)=0, c(12)=0, c(13)=0
			scalar f=@val(wald(6,2))
			scalar fp=@val(wald(6,4))
			%fpval=@str(fp)
			delete wald
		endif

		if %meth="bp12" then
			freeze(wald) instr_{%meth}.wald c(8)=0, c(9)=0, c(10)=0, c(11)=0, c(12)=0, c(13)=0, c(14)=0, c(15)=0, c(16)=0, c(17)=0, c(18)=0, c(19)=0
			scalar f=@val(wald(6,2))
			scalar fp=@val(wald(6,4))
			%fpval=@str(fp)
			delete wald
		endif
	
		setcell(tab_taylor,!r,8,radj,"c",3)
		setcell(tab_taylor,!r,9,ser,"c",3)
		setcell(tab_taylor,!r,10,f,"c",3)
		setcell(tab_taylor,!r+1,10,"("+ %fpval +")", "c",3)
		!r=!r+3
	next


' VARs and impulse response functions

smpl 1983:1 1997:12

!hor=40
!lag=1

for %y usgap usout

	%regrlist=%y+" "+ "usinfl uspr"
	%strum="dlpcm(-1) dlexrus(-1) d12lusemp(-1)"

	var var_{%y}_base.ls 1 !lag %regrlist @ c %strum
	freeze(i_{%y}_base) var_{%y}_base.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

	for %factype bp nbp 

		var var_{%y}_{%factype}12.ls 1 !lag %regrlist @ c %strum usfact_{%factype}01(-1) usfact_{%factype}02(-1) usfact_{%factype}03(-1) usfact_{%factype}04(-1) usfact_{%factype}05(-1) usfact_{%factype}06(-1) usfact_{%factype}07(-1) usfact_{%factype}08(-1) usfact_{%factype}09(-1) usfact_{%factype}10(-1) usfact_{%factype}11(-1) usfact_{%factype}12(-1)
		freeze(i_{%y}_{%factype}12) var_{%y}_{%factype}12.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

		var var_{%y}_{%factype}6.ls 1 !lag %regrlist @ c %strum usfact_{%factype}01(-1) usfact_{%factype}02(-1) usfact_{%factype}03(-1) usfact_{%factype}04(-1) usfact_{%factype}05(-1) usfact_{%factype}06(-1) 
		freeze(i_{%y}_{%factype}6) var_{%y}_{%factype}6.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

		var var_{%y}_{%factype}3.ls 1 !lag %regrlist @ c %strum usfact_{%factype}01(-1) usfact_{%factype}02(-1) usfact_{%factype}03(-1) 
		freeze(i_{%y}_{%factype}3) var_{%y}_{%factype}3.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

	next

	var var_{%y}_fh6.ls 1 !lag %regrlist @ c %strum usfact_fh01(-1) usfact_fh02(-1) usfact_fh03(-1) usfact_fh04(-1) usfact_fh05(-1) usfact_fh06(-1)
	freeze(i_{%y}_fh6) var_{%y}_fh6.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

	var var_{%y}_fh3.ls 1 !lag %regrlist @ c %strum usfact_fh01(-1) usfact_fh02(-1) usfact_fh03(-1) 
	freeze(i_{%y}_fh3) var_{%y}_fh3.impulse(!hor,m,imp=chol,se=a) %y usinfl uspr @ uspr

	graph i_{%y}.merge i_{%y}_base i_{%y}_fh3 i_{%y}_fh6 i_{%y}_bp3 i_{%y}_bp6 i_{%y}_bp12
	graph i_{%y}.align(3,1.5,1.5)

next

delete f fp instr overid_p radj ser

