White Noise, AR(1) and Random Walk

'close the old version of primer_ts workfile

close primer_ts.wf1

'create new workfile

workfile primer_ts q 1950:1 1990:4

'create time trend variable

series t=@trend+1

'create normally distributed wite noise

series eps = nrnd

'create random walk

series rw = 0

smpl 1950:2 1990:4

rw = rw(-1)+eps

smpl 1950:1 1990:4

'create AR(1)

series ar1 = 0

smpl 1950:2 1990:4

ar1 = 1+0.6*ar1(-1)+eps

smpl 1950:1 1990:4

'plot all variables and enjoy running program again and again

freeze(gr_wn) eps.line

gr_wn.option(h,v,-k)

gr_wn.name(1) White Noise

show gr_wn

freeze(gr_rw) rw.line

gr_rw.option(h,v,-k)

gr_rw.name(1) Random Walk

show gr_rw

freeze(gr_ar1) ar1.line

gr_ar1.option(h,v,-k)

gr_ar1.name(1) AR(1) process phi=0.6, m=1

show gr_ar1

Trend and Seasonality

'close the old version of primer_t&s workfile

close primer_t&s.wf1

'create new workfile

workfile primer_t&s q 1950:1 1960:4

'create time trend variable

series t=@trend+1

'create quater number variable

series q=@quarter

'create quarter dummies

series d1=(q=1)

series d2=(q=2)

series d3=(q=3)

series d4=(q=4)

'create normally distributed wite noise

series eps = nrnd

'create season variable (simulation)

series season = 10*d1+15*d2+19*d3+8*d4

'ice cream consumption (simulation)

series ice = season+eps

'airpassengers (simulation)

series air = 0.2*t+season+eps

'plot all variables and enjoy running program again and again

freeze(gr_ice) ice.line

gr_ice.option(h,v,-k)

gr_ice.name(1) Ice-cream Cosumption

show gr_ice

graph gr_air.line air 0.2*t+(10+15+19+8)/4

gr_air.option(h,v,-k)

gr_air.name(1) Airpassengers

gr_air.name(2) Trend

show gr_air

SPURIOUS REGRESSION

' Spurious Regression

'close the old version of spur_reg workfile

%N="1000"

%M="5000"

close spur_reg.wf1

'create new workfile

create spur_reg u 1 %M

genr tt=0

genr tdw=0

genr tr2=0

vector(%M) vt

vector(%M) vr2

vector(%M) vdw

smpl 1 %N

scalar count=0

for !i=1 to %M

genr x=0

genr y=0

smpl 2 %N

genr x=x(-1)+nrnd

genr y=y(-1)+nrnd

smpl 1 %N

equation temp.ls y c x

vt(!i)= temp.@tstat(2)

vr2(!i)=temp.@r2

vdw(!i)=temp.@dw

if abs(temp.@tstat(2))>2 then

count = count+1

endif

next

'look at the results and enjoy running the program again and again

smpl 1 %M

mtos(vt,tt)

show tt.stats

show count

mtos(vdw,tdw)

show tdw.stats

mtos(vr2,tr2)

show tr2.stats

DICKEY-FULLER TEST

' Dickey-Fuller Test

'close the old version of df_test workfile

%N="1000"

%M="5000"

%phi="0.99"

close df_test.wf1

'create new workfile

create df_test u 1 %M

genr tt=0

genr tdw=0

vector(%M) vt

vector(%M) vtdw

smpl 1 %N

scalar count1=0

scalar count2=0

scalar count3=0

for !i=1 to %M

genr x=0

genr y=0

smpl 2 %N

genr x = x(-1)+nrnd

genr y = %phi*y(-1)+nrnd

smpl 1 %N

equation temp1.ls y c y(-1)

equation temp2.ls x c x(-1)

vt(!i) = (temp1.c(2)-1)/temp1.@stderr(2)

vtdw(!i) = (temp2.c(2)-1)/temp2.@stderr(2)

if vt(!i)<-1.66 then

count1 = count1+1

endif

if vtdw(!i)<-1.66 then

count2 = count2+1

endif

if vtdw(!i)<-2.86 then

count3 = count3+1

endif

next

table(3,5) tab

tab(1,1)="phi"

tab(2,1)="tc"

tab(3,1)="p"

tab(1,2)=%phi

tab(1,3)=1

tab(1,4)=1

tab(2,2)= -1.66

tab(2,3)= -1.66

tab(2,4)= -2.86

tab(3,2)= count1/%M

tab(3,3)= count2/%M

tab(3,4)= count3/%M

'look at the results and enjoy running the program again and again

smpl 1 %M

mtos(vt,tt)

show tt.stats

mtos(vtdw,tdw)

show tdw.stats

show tab

1

Time series examples NES 2005, A.Peresetsky