rndseed 12345 %T = %0 %rep = "1000" %runin = "0" %r1 = %1 %d = "1" %eta = "1" %theta = "1" !model = {%2} %modellist = """1. ADF"" ""2. RADF (rolling ADF)"" ""3. SADF (sup ADF)"" ""4. GSADF (generalized SADF)""" !ADFspec = {%3} %ADFspeclist = """Constant"" ""Constant and trend"" ""None""" !dist_plot=0 !Trw=1 %beta = "0.95" ' GUI menu setup !result = @uidialog("caption","Simulate finite sample distribution and critical values", _ "list",!model,"A. Choose test:",%modellist, _ "text","B. Choose simulation specifications:", _ "edit",%T,"Sample size (T)", _ "edit",%rep,"Replications", _ "edit",%runin,"Run-in observations", _ "radio",!ADFspec,"Include in test equation",%ADFspeclist , _ "edit",%r1,"Initial window size (fraction or observations)", _ "text","C. Choose the critical values sequence's significance level:", _ "edit",%beta,"beta", _ "text","D. Choose the parameters for the null model:", _ "text","x(t) = d*T^(-eta)+theta*x(t-1)+e(t)", _ "edit",%d,"d",2, _ "edit",%eta,"eta", _ "edit",%theta,"theta", _ "check",!Trw,"Use accurate sample size for the CV sequence (T*r_w instead of T)") '"check",!dist_plot,"t-stat distribution plot") if !result = -1 then stop endif %ADFspec = "c" if !ADFspec = 2 then %ADFspec = "c @trend" endif if !ADFspec = 3 then %ADFspec = "" endif !rep = @val(%rep) !runin = @val(%runin) !T = @val(%T) !r1= @val(%r1) if !r1<1 then !t1 = @round(!T*!r1) else !t1=!r1 endif !d = @val(%d) !eta = @val(%eta) !theta = @val(%theta) !beta = @val(%beta) scalar beta_pc = @round(!beta*100) 'create a new page !totalobs = !runin+!T pagecreate(page=simulation) u !totalobs '**** ADF test if !model = 1 then vector(!rep) tstat series adf_cv table cv 'create a data generating proces series x ' begin replititions tic statusline Simulating finite sample distribution for !i=1 to !rep ' set first observation to x=0 smpl 1 1 x=0 ' set rest ot observations smpl 2 !totalobs x = !d*!T^(-!eta)+!theta*x(-1)+nrnd smpl !runin+1 !runin+1+!T equation eq.ls d(x) x(-1) {%ADFspec} tstat(!i)=eq.@tstats(1) %perc_comp=@str(@round(100*!i/!rep)) statusline Simulating finite sample distribution ({%perc_comp}% completed) next toc if !dist_plot=1 then tstat.distplot endif cv(1,1) = "90%" cv(2,1) = "95%" cv(3,1) = "99%" cv(1,2) = @quantile(tstat, .90) cv(2,2) = @quantile(tstat, .95) cv(3,2) = @quantile(tstat, .99) endif '****Rolling ADF test if !model = 2 then matrix( !T-!t1+1,!rep) tstat matrix( !T-!t1+1,!rep) tstat_cv vector(!rep) tstat_max vector temp series radf_cv = na table cv 'create a data generating proces series x series y ' begin replititions tic statusline Simulating finite sample distribution and seuqnece of critical values for !i=1 to !rep ' set first observation to x=0 smpl 1 1 x=0 y=0 ' set rest ot observations smpl 2 !totalobs x = !d*!T^(-!eta)+!theta*x(-1)+nrnd for !j=0 to !T-!t1 if !Trw = 1 then smpl 2 !totalobs y = !d*!t1^(-!eta)+!theta*y(-1)+nrnd endif smpl !runin+1+!j !runin+1+!t1+!j-1 equation eq.ls d(x) x(-1) {%ADFspec} tstat(!j+1,!i)=eq.@tstats(1) if !Trw=1 then equation eq.ls d(y) y(-1) {%ADFspec} tstat_cv(!j+1,!i)=eq.@tstats(1) endif next %perc_comp=@str(@round(100*!i/!rep)) statusline Simulating finite sample distribution and seuqnece of critical values ({%perc_comp}% completed) next toc tstat_max=@cmax(tstat) 'generate ADF critical values series for !j=0 to !T-!t1 if !Trw=1 then temp=@rowextract(tstat_cv,!j+1) radf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) else temp=@rowextract(tstat,!j+1) radf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) endif next if !dist_plot=1 then tstat_max.distplot endif cv(1,1) = "90%" cv(2,1) = "95%" cv(3,1) = "99%" cv(1,2) = @quantile(tstat, .90) cv(2,2) = @quantile(tstat, .95) cv(3,2) = @quantile(tstat, .99) endif '**** SADF test if !model = 3 then matrix( !T-!t1+1,!rep) tstat matrix( !T-!t1+1,!rep) tstat_cv vector(!rep) tstat_max vector temp series sadf_cv = na table cv 'create a data generating proces series x series y ' begin replititions tic statusline Simulating finite sample distribution and seuqnece of critical values for !i=1 to !rep ' set first observation to x=0 smpl 1 1 x=0 y=0 ' set rest ot observations smpl 2 !totalobs x = !d*!T^(-!eta)+!theta*x(-1)+nrnd for !j=0 to !T-!t1 if !Trw = 1 then smpl 2 !totalobs y = !d*(!t1+!j)^(-!eta)+!theta*y(-1)+nrnd endif smpl !runin+1 !runin+1+!t1+!j-1 equation eq.ls d(x) x(-1) {%ADFspec} tstat(!j+1,!i)=eq.@tstats(1) if !Trw = 1 then equation eq.ls d(y) y(-1) {%ADFspec} tstat_cv(!j+1,!i)=eq.@tstats(1) endif next %perc_comp=@str(@round(100*!i/!rep)) statusline Simulating finite sample distribution and seuqnece of critical values ({%perc_comp}% completed) next toc tstat_max=@cmax(tstat) 'generate ADF critical values series for !j=0 to !T-!t1 if !Trw = 1 then temp=@rowextract(tstat_cv,!j+1) sadf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) else temp=@rowextract(tstat,!j+1) sadf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) endif next if !dist_plot=1 then tstat_max.distplot endif cv(1,1) = "90%" cv(2,1) = "95%" cv(3,1) = "99%" cv(1,2) = @quantile(tstat_max, .90) cv(2,2) = @quantile(tstat_max, .95) cv(3,2) = @quantile(tstat_max, .99) endif '**** GSADF test if !model = 4 then matrix(!T-!t1+1,!T-!t1+1) tstat matrix(!T-!t1+1,!T-!t1+1) tstat_cv matrix(!T-!t1+1,!rep) tstat_max matrix(!T-!t1+1,!rep) tstat_max_cv vector(!rep) tstat_max_max series gsadf_cv = na vector temp table cv 'create a data generating proces series x series y ' begin replititions tic statusline Simulating finite sample distribution and seuqnece of critical values for !i=1 to !rep ' set first observation to x=0 smpl 1 1 x=0 y=0 ' set rest ot observations smpl 2 !totalobs x = !d*!T^(-!eta)+!theta*x(-1)+nrnd 'initialize the matrix that holds sadf tstat = -99999 for !j=!t1 to !T !dim=!j-!t1 for !k=0 to !dim if !Trw = 1 then smpl 2 !totalobs y = !d*(!j-!k)^(-!eta)+!theta*y(-1)+nrnd endif smpl !runin+1+!k !runin+1+!j-1 equation eq.ls d(x) x(-1) {%ADFspec} tstat(!k+1,!j-!t1+1)=eq.@tstats(1) if !Trw = 1 then equation eq.ls d(y) y(-1) {%ADFspec} tstat_cv(!k+1,!j-!t1+1)=eq.@tstats(1) endif next next if !Trw = 1 then colplace(tstat_max_cv,@cmax(tstat_cv),!i) endif colplace(tstat_max,@cmax(tstat),!i) %perc_comp=@str(@round(100*!i/!rep)) statusline Simulating finite sample distribution and seuqnece of critical values ({%perc_comp}% completed) next toc tstat_max_max=@cmax(tstat_max) 'generate BSADF critical values series for !j=0 to !T-!t1 if !Trw = 1 then temp=@rowextract(tstat_max_cv,!j+1) gsadf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) else temp=@rowextract(tstat_max,!j+1) gsadf_cv(!runin+1+!t1-1+!j)=@quantile(temp, !beta) endif next if !dist_plot=1 then tstat_max_max.distplot endif cv(1,1) = "90%" cv(2,1) = "95%" cv(3,1) = "99%" cv(1,2) = @quantile(tstat_max_max, .90) cv(2,2) = @quantile(tstat_max_max, .95) cv(3,2) = @quantile(tstat_max_max, .99) endif