' rolling ADF unit root test
' run in quiet mode for slight speed up
'
' revised for version 4.0 (10/26/2000 h)

' change path to program path
%path = @runpath
cd "{%path}"

' get workfile
%evworkfile = "..\data\basics"
load "{%evworkfile}"

' set sample
smpl @all

' find size of workfile
series _temp = 1
!length = @obs(_temp)
delete _temp 

' set fixed sample size
!ssize = 50

' initialize matrix to store results
matrix(!length-!ssize+1,2) adftstat

' run test regression for each subsample and
' store each ar(1) coefficient
' test includes constant with no lagged first difference
for !i = 1  to  !length-!ssize+1

	' set rolling subsample
	smpl @first+!i-1 @first+!i+!ssize-2
	
	' estimate test regression
	equation temp.ls d(m1) c m1(-1)

	' store t-statistic
	adftstat(!i,1) = temp.@tstat(2)
	
	' 5% critical value from Davidson and MacKinnon,
	' Table 20.1, page 708 
	adftstat(!i,2) = -2.86
next

' plot graph of t-statistic
freeze(graph1) adftstat.line
' set aspect ration and use line pattern
graph1.option size(8,2)	linepat
' set legend text
graph1.setelem(1) legend(ADF t-statistic)
graph1.setelem(2) legend(Asymptotic 5% critical value)
' add text at top of graph
%comment = "ADF t-statistic for window of " + @str(!ssize) + " obs for M1"
graph1.addtext(t) {%comment}
show graph1
