'This code is provided 'as is'. There is no guarantee that it is free of errors. 'Simulating critical values for the GLS Dickey-Fuller test of Elliott et al. (1996, Econometrica) 'In its current form, this code considers the trend model. However, it can be modified quite easily to consider the intercept model 'The number of replications !reps = 100000 'Setting the sample size !sample=150 'The sample used in the simulation: an additional observation used to allow for a discarded initial value !obs=!sample+1 'Creating a workfile to house the results wfcreate GLS_!reps u !obs 'Creating vectors to store the test statistics (tests) and the critical values (cvs) vector(!reps) tests vector(3) cvs 'All observations smpl 1 !obs 'Fixing the seed so results can be replicated rndseed 1 'Creating c_bar and alpha_bar: note that c_bar=-7 for the intercept model and c_bar=-13.5 for the trend model scalar c_bar=-13.5 scalar alpha_bar=1+(c_bar/(!obs)) 'The simulation loop begins for !k=1 to !reps 'Creating the error term series u=nrnd genr trnd=@trend+1 'Initialisation smpl 1 1 series y = 0 genr ya=y genr ca=1 genr ta=1 'Creating terms over the rest of the sample smpl 2 !obs series y = y(-1)+u genr ya=y-alpha_bar*y(-1) genr ca=1-alpha_bar genr ta=trnd-alpha_bar*(trnd-1) 'Removing the effect of deterministics and creating the adjusted series and its first difference smpl @all equation eq1.ls ya ca ta genr yd=y-(eq1.@coefs(1))-(eq1.@coefs(2)*trnd) genr dyd=d(yd) 'The DF_GLS testing equation smpl 2 !obs equation eq2.ls dyd yd(-1) 'Storing the test statistic tests(!k)=eq2.@tstats(1) next 'Storing the 1%, 5% and 10% critical values cvs(1)=@quantile(tests,0.01) cvs(2)=@quantile(tests,0.05) cvs(3)=@quantile(tests,0.1) 'Storing the ordered test statistics generated over the replications vector stats=@sort(tests)