Need help ... there are 3 errors when I run the code .... First "G0008 : Syntax error, line 1" ... Second "G0155 : Nested procedure definition, line 181" ... Third "G0008 : Syntax Error 'proc(1)=NLINX(xx)', line 181"

new ; cls;
/**********************************************************************
Causality tests: Anne PEGUIN-FEISSOLLE and Timo TERASVIRTA (2000)
A general framework for testing the Granger noncausality hypothesis,
SSE/EFI Working Paper Series in Economics and Finance, n? 343, Stockholm
School of Economics, Email: [email protected]
May 2010 - Can be applied on economic series
***********************************************************************/

timedeb = time;
library pgraph;

/*0000000000000000000000000000000000000000000000000000000000000000000000*/
/*00000000000000000 YOU CAN CHANGE SOME PARTS BELOW 0000000000000000000*/
/*0000000000000000000000000000000000000000000000000000000000000000000000*/

@ Parameters for testing @

qretards = 1; /* Nb of lags of the endogenous y for testing */
nretards = 1; /* Nb of lags of the exogenous x for testing */
ktaylor = 3; /* Order k the Taylor expansion */
qqcp = 20; /* Nb of hidden units in ANN test */
cpseuil = 0.80 ; /* Threshold of princ. comp. */

@ Generating or reading
- the endogenous vector yzero of dimension (T x 1)
- the exogenous vector vectorX of dimension Tx1
- The null is vectorX does not GC yzeros @

//load yzero[] = c:\gauss10\tmp\OilREER\IndiaOilREER\oils4.txt;
//load vectorX[] = c:\gauss10\tmp\OilREER\IndiaOilREER\reers4.txt;
//load yzero[] = C:\Users\abnae\Dropbox\Working paper\Connectedness CBOE\US markets, EPU, GPR\epu.txt;
//load yzero[] = C:\Users\abnae\Dropbox\Working paper\Connectedness CBOE\US markets, EPU, GPR\overall.txt;

yzero1 = yzero;
vectorX1 = vectorX;
yzero = yzero1;
vectorX = vectorX1;

T = rows(yzero); /* Number of observations */
seedn=982674 ; seedu=68372 ; seednh0=45914 ; seednh1=seednh0 ;

/*0000000000000000000000000000000000000000000000000000000000000000000000*/
/*0000000000000000000 DO NOT CHANGE AFTER THIS LINE 00000000000000000000*/
/*0000000000000000000000000000000000000000000000000000000000000000000000*/

@ Computation of the matrices of lagged endogenous and exogenous variables @

/* creation of xxx (T x nretards) */
xxx0=MATXXX(vectorX) ;
xxx=xxx0[100+1+nretards:rows(xxx0),1:nretards] ;
/* generation of yyy (T x qretards) */
yyy = MATYYY ;
yzero=yzero[100+1+nretards:rows(yzero),.] ;
yyy=yyy[100+1+nretards:rows(yyy),.] ;

@ Printing of parameters @

print "/**********************************************************************
Causality tests: Anne PEGUIN-FEISSOLLE and Timo TERASVIRTA (2000)
A general framework for testing the Granger noncausality hypothesis,
SSE/EFI Working Paper Series in Economics and Finance, n? 343, Stockholm
School of Economics, Email: [email protected]
***********************************************************************/" ;
format /mat /mb1 /rd 5,0 ;
print ; print "Some parameters: ";
print " - Number of observations* = " rows(yzero) ;
print " - Number of lags of the endogenous y for testing = " qretards ;
print " - Number of lags of the exogenous x for testing = " nretards ;
print " - Order k of Taylor expansion = " ktaylor ;
print " - Number of hidden units in ANN test = " qqcp ;
format /mat /mb1 /rd 7,2 ;
print " - Threshold for principal components = " cpseuil ;
print "(*: after tre creation of the matrices of lagged endogenous
and exogenous variables)";

@ Computation of some matrices @

/* Taylor series expansion for lagged x only */
xtaylor = TAYLOR(xxx,xxx) ;
santafe = xxx~xtaylor ;
{ santafecp , vertigo, anon } = princomp(santafe,cols(santafe)) ;
i=1 ;
do while i <= rows(vertigo) ;
if sumc(vertigo[1:i]) >= cpseuil ; goto labelstopdebu1 ;
endif ;
i=i+1 ;
endo;
labelstopdebu1: ;
onlyxtaylorallcp = santafecp[.,1:i] ;
/* Taylor series expansion for lagged y only */
ytaylor = TAYLOR(yyy,yyy) ;
ytaylorall = ones(rows(ytaylor),1)~yyy~ytaylor ;
santafe = yyy~ytaylor ;
{ santafecp , vertigo, anon } = princomp(santafe,cols(santafe)) ;
i=1 ;
do while i <= rows(vertigo) ;
if sumc(vertigo[1:i]) >= cpseuil ; goto labelstop1 ;
endif ;
i=i+1 ;
endo;
labelstop1: ;
ytaylorallcp = santafecp[.,1:i] ;
ytaylorallcp = ones(rows(ytaylor),1)~ytaylorallcp ;
/* Taylor series expansion mixing lagged x and y */
xynavajo= TAYLOR(xxx~yyy,xxx~yyy) ;
xytaylor = TAYXY ;
/* Taylor series terms with at least one lagged x inside */
xytaylorall = xxx~xytaylor~xtaylor ;
santafe = xytaylorall ;
{ santafecp , vertigo, anon } = princomp(santafe,cols(santafe)) ;
i=1 ;
do while i <= rows(vertigo) ;
if sumc(vertigo[1:i]) >= cpseuil ; goto labelstop2 ;
endif ;
i=i+1 ;
endo;
labelstop2: ;
xytaylorallcp = santafecp[.,1:i] ;

@ Testing @

/* tests DIRECTLY*/
{ statgranger, pdgranger } = GRANGER ;
{ statgeneral, pdgeneral } = GENERALCP ;
{ statneural, pdneural } = NEURALCP ;
{ statadditive, pdadditive } = ADDITIVECP ;
/* ------------ STRATEGY : LINEARITY all param ass. with other terms than 1 ,
simple lagged x and lagged y are zeros */
plinearCP = LINEARITYCP ;
if plinearcp >= 0.05 ;
/*print " ------------> accept linearity " ; */
goto labelgrangerh0 ;
else ; /*print "------------> accept non linearity " ;*/
goto labelgeneralh0 ;
endif ;
/* tests */
labelgeneralh0:;
{ statunderh0, punderh0 } = GENERALCP ;
goto labelnextih0 ;
labelgrangerh0:;
{ statunderh0, punderh0 } = GRANGER ;
labelnextih0:;

@ Printing of results @

format /mat /mb1 /rd 8,4 ;
print ; print"F-versions of the different causality tests:" ;
print " stat pvalue ";

print "Linear Granger " statgranger pdgranger ;
print "General Taylor-based " statgeneral pdgeneral ;
print "Semi-additive Taylor-based " statadditive pdadditive ;
print "P-General Taylor based " statunderh0 punderh0 ;
print "ANN-based " statneural pdneural ;
print "(if pvalue < 0.05 --> reject H0 (H0: non causality) --> accept causality)";

print;
end;
/**************************************************************************/
/**************************** PROCEDURES ****************************/
/**************************************************************************/

PROC(1)=NLIN ; /*generation of y without causality*/
local uu1,i ;
uu1=rndns(100+nretards+T,1,seednh0);
yzero=zeros(100+nretards+T,1);
i=6; /* <--------------------------------------------------- TO CHANGE IF NECESSARY -------*/
do while i<=100+nretards+T;

yzero[i]= 0.5+10/(1+exp(-2*(-0.05+1*yzero[i-1]-3*yzero[i-2]) ))+0.001*uu1[i] ;

i=i+1;
endo;
retp(yzero);
ENDP;

proc(1)=NLINX(xx) ; /*generation of y with causality*/
local uu1,i,x1, maxofx ;
uu1=rndns(100+nretards+T,1,seednh1);
yzero=zeros(100+nretards+T,1);
maxofx = nretards ;
x1=zeros(rows(xx),maxofx);
/*generation de x1=matrice des nretards retards simples*/
i=1;
do while i <= maxofx ;
x1[.,i]=lagn(xx,i);
i=i+1;
endo;
xxx0 = x1;
i=6; /* <--------------------------------------------------- TO CHANGE IF NECESSARY -------*/
do while i<=100+nretards+T;

yzero[i]= 0.5+0.1*yzero[i-1]-0.3*yzero[i-2]+0.1*xxx0[i,1]-0.2*xxx0[i,2]+
0.100*uu1[i] ;

/*
yzero[i]= 0.5+ln(10*(0.1*yzero[i-1]^2+0.3*yzero[i-2]^2+
0.1*xxx0[i,1]^2+0.2*xxx0[i,2]^2+0.3*xxx0[i,3]^2))+0.100*uu1[i] ;
yzero[i]= 0.5+0.1*yzero[i-1]+0.5*uu1[i-1]*xxx0[i,1]+1*uu1[i] ;
yzero[i]= 0.5+100/(1+exp(-2*(-0.05+1*yzero[i-1]-3*yzero[i-2])
+ 100/(1+exp(xxx0[i,1]-2*xxx0[i,2]+3*xxx0[i,3]))))+0.001*uu1[i] ;
yzero[i]= (0.02-0.9*yzero[i-1]+0.795*yzero[i-2]+xxx0[i,1]+0.9*xxx0[i,3])/
(1+exp(-10*(yzero[i-1]-0.02)))+0.1*uu1[i] ;
yzero[i]= 0.5+0.1*yzero[i-1]-0.3*yzero[i-2]+0.1*xxx0[i,1]-0.2*xxx0[i,2]+
0.100*uu1[i] ;
*/

i=i+1;
endo;
retp(yzero);
ENDP;

PROC(1)=SEUIL; /*generation of y with causality*/
local uu1,i ;
uu1=rndns(100+nretards+T,1,seedn);
yzero=zeros(100+nretards+T,1);
i=4; /* <--------------------------------------------------- TO CHANGE IF NECESSARY -------*/
do while i<=100+nretards+T;
if uu1[i-1] <0;
yzero[i]=0.1*yzero[i-1]+0.01*uu1[i] ;
else;
yzero[i]=-0.5*yzero[i-1]+0.01*uu1[i] ;
endif;
i=i+1;
endo;
retp(yzero);
ENDP;

PROC(1)=SEUILX; /*generation of y with causality*/
local uu1,i ;
uu1=rndns(100+nretards+T,1,seedn);
yzero=zeros(100+nretards+T,1);
i=4; /* <--------------------------------------------------- TO CHANGE IF NECESSARY -------*/
do while i<=100+nretards+T;
/* if yzero[i-1] <0;
yzero[i]=0.1*yzero[i-1]+0.03*xxx0[i,1]^2+0.1*uu1[i] ;
else;
yzero[i]=-0.5*yzero[i-1]+0.1*uu1[i] ;
endif;*/
if uu1[i-1] <0;
yzero[i]=0.1*yzero[i-1]+10*xxx0[i,1]^2+0.01*uu1[i] ;
else;
yzero[i]=-0.5*yzero[i-1]+0.01*uu1[i] ;
endif;
i=i+1;
endo;
retp(yzero);
ENDP;

PROC(1) = LINEARITY ;
local exog, eps, SSR0, zm, nu, SSR, statcau, pstatcau ;
exog=ones(rows(xxx),1)~xxx~yyy ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
zm=exog~ytaylor~xtaylor~xytaylor ;
nu=eps-zm*inv(zm'zm)*zm'eps ;
SSR=nu'nu ;
statcau = ( (SSR0-SSR) / (cols(zm)-cols(exog)) ) / (SSR / (rows(zm)-cols(zm) ) ) ;
pstatcau = cdffc( statcau, (cols(zm)-cols(exog)),rows(zm)-cols(zm) );
retp(pstatcau) ;
ENDP ;

PROC(1) = LINEARITYCP ;
local exog, eps, SSR0, zm, nu, SSR, statcau, pstatcau , xxxcp , santafe , santafecp , vertigo , anon ;
exog=ones(rows(xxx),1)~xxx~yyy ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
santafe = ytaylor~xtaylor~xytaylor ;
{ santafecp , vertigo, anon } = princomp(santafe,cols(santafe)) ;
i=1 ;
do while i <= rows(vertigo) ;
if sumc(vertigo[1:i]) >= cpseuil ; goto labelstop3 ;
endif ;
i=i+1 ;
endo;
labelstop3: ;
xxxcp = santafecp[.,1:i] ;
zm=exog~xxxcp ;
nu=eps-zm*inv(zm'zm)*zm'eps ;
SSR=nu'nu ;
statcau = ( (SSR0-SSR) / ( cols(xxxcp) ) ) / (SSR / (rows(zm)-cols(zm) ) ) ;
pstatcau = cdffc( statcau, cols(xxxcp) ,rows(zm)-cols(zm) );
retp(pstatcau) ;
ENDP ;

proc(2) = ADDITIVECP ;
local exog, eps, SSR0, zm, nu, SSR, statcau, pstatcau ;
exog=ytaylorallcp ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
zm=ytaylorallcp~onlyxtaylorallcp ;
nu=eps-zm*inv(zm'zm)*zm'eps ;
SSR=nu'nu ;
statcau = ( (SSR0-SSR) / cols(onlyxtaylorallcp) ) / (SSR / (rows(zm)-cols(zm) ) ) ;
pstatcau = cdffc( statcau, cols(onlyxtaylorallcp),rows(zm)-cols(zm) );
retp(statcau, pstatcau) ;
ENDP ;

proc(2) = GENERALCP ;
local exog, eps, SSR0, zm, nu, SSR, statcau, pstatcau ;
exog=ytaylorallcp ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
zm=ytaylorallcp~xytaylorallcp ;
nu=eps-zm*inv(zm'zm)*zm'eps ;
SSR=nu'nu ;
statcau = ( (SSR0-SSR) / cols(xytaylorallcp) ) / (SSR / (rows(zm)-cols(zm) ) ) ;
pstatcau = cdffc( statcau, cols(xytaylorallcp),rows(zm)-cols(zm) );
retp(statcau, pstatcau) ;
ENDP ;

proc(2)=GRANGER ; /* calcul de la p-value du test en F de noncausalite lineaire */
local exog,eps,SSR0,zm,nu,SSR,grangerF1,pgrangerF1;
exog=ones(rows(yzero),1)~yyy ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
zm=exog~xxx ;
nu=eps-zm*inv(zm'zm)*zm'eps ;
SSR=nu'nu ;
/*calcul de la statistique de test*/
grangerF1=((SSR0-SSR)/cols(xxx))/(SSR/(T-cols(zm))) ;
pgrangerF1=cdffc(grangerF1,cols(xxx),t-cols(zm)) ;
retp(grangerF1, pgrangerF1) ;
ENDP ;

proc(2)=NEURALCP;
local exog , eps , SSR0 , xn , nn , wn , gam , bid , psi , ecap , SSR ;
local neural1, cp , vertigo, anon , pneural1b , santafe , santafecp ;
exog=ytaylorallcp ;
eps = yzero-exog*inv(exog'exog)*exog'yzero ;
SSR0=eps'eps ;
xn = ones(rows(eps),1)~xxx ;
label1:;
nn=1;
wn=zeros(rows(xn),1);
do while nn<=qqcp;
gam=-2+4*rndus(cols(xn),1,seedu);
bid=xn*gam;
psi=1/(1+exp(-bid));
wn=wn~psi;
nn=nn+1;
endo;
psi=wn[.,2:cols(wn)];
santafe = psi ;
{ santafecp , vertigo, anon } = princomp(santafe,cols(santafe)) ;
i=1 ;
do while i <= rows(vertigo) ;
if sumc(vertigo[1:i]) >= cpseuil ; goto labelstop6 ;
endif ;
i=i+1 ;
endo;
labelstop6: ;
cp = santafecp[.,1:i] ;
wn = exog~xxx~cp;
ecap=eps-wn*(inv(wn'wn))*wn'eps;
SSR=ecap'ecap;
neural1=((SSR0-SSR)/(cols(wn)-cols(exog)))/(SSR/(rows(wn)-cols(wn)));
if neural1 <= 0 ;
goto label1;
endif;
pneural1b=cdffc(neural1,cols(wn)-cols(exog),rows(wn)-cols(wn));
retp(neural1, pneural1b);
ENDP;

PROC(1)=TAYXY ;
local xygarder , ytaylorout , inavajo, iy , xtaylorout ;
xygarder = ones(rows(xynavajo),1)~xynavajo~ones(rows(xynavajo),1) ;
ytaylorout = ones(rows(xygarder),1)~ytaylor~ones(rows(xynavajo),1) ;
inavajo = 2 ;
do while inavajo <= cols(xygarder)-1 ;
iy=2 ;
do while iy <= cols(ytaylorout)-1 ;
if xygarder[.,inavajo] == ytaylorout[.,iy] ;
xygarder = xygarder[.,1:inavajo-1]~xygarder[.,inavajo+1:cols(xygarder)] ;
ytaylorout = ytaylorout[.,1:iy-1]~ytaylorout[.,iy+1:cols(ytaylorout)] ;
goto label1 ;
endif ;
iy=iy+1;
endo;
inavajo = inavajo + 1 ;
label1: ;
endo ;
xtaylorout = ones(rows(xygarder),1)~xtaylor~ones(rows(xynavajo),1) ;
inavajo = 2 ;
do while inavajo <= cols(xygarder)-1 ;
iy=2 ;
do while iy <= cols(xtaylorout)-1 ;
if xygarder[.,inavajo] == xtaylorout[.,iy] ;
xygarder = xygarder[.,1:inavajo-1]~xygarder[.,inavajo+1:cols(xygarder)] ;
xtaylorout = xtaylorout[.,1:iy-1]~xtaylorout[.,iy+1:cols(xtaylorout)] ;
goto label2 ;
endif ;
iy=iy+1;
endo;
inavajo = inavajo + 1 ;
label2: ;
endo ;
xytaylor = xygarder[.,2:cols(xygarder)-1] ;
retp(xytaylor);
ENDP;

PROC(1)=TAYLOR(yprime,ysecond) ;
local zy , i1, navajo1, i2, navajo2 , i3, navajo3 , itaylor ;
zy = ones(rows(yprime),1) ;
i1=1;
do while i1 <= cols(yprime) ;
navajo1 = yprime[.,i1] ;
i2=i1;
do while i2 <= cols(ysecond) ;
navajo2 = navajo1.*ysecond[.,i2] ;
zy = zy~navajo2 ;
itaylor = 3 ;
do while itaylor <= ktaylor ;
i3=i2 ;
do while i3 <= cols(ysecond) ;
navajo3 = navajo2.*ysecond[.,i3] ;
zy = zy~navajo3 ;
i3 = i3+1;
endo;
itaylor = itaylor + 1 ;
endo;
i2 = i2+1 ;
endo;
i1=i1+1 ;
endo;
zy = zy[.,2:cols(zy)] ;
retp(zy);
ENDP;

proc(1)=MATXXX(xx); /*creation de la matrice des x */
local xx, x1 ,i , maxofx ;
maxofx = nretards ;
x1=zeros(rows(xx),maxofx);
/*generation de x1=matrice des nretards retards simples*/
i=1;
do while i <= maxofx ;
x1[.,i]=lagn(xx,i);
i=i+1;
endo;
retp(x1);
endp;

PROC(1)=MATYYY; /*creation de la matrice des y */
local yy,i;
yy=yzero;
i=1;
do while i <= qretards;
yy=yy~lagn(yzero,i) ;
i=i+1;
endo;
yy=yy[.,2:cols(yy)] ;
retp(yy);
ENDP;

Your Answer


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy