Data uploading and running regression

Dear Friend,

I am very new to GAUSS but I am on my toes to learn it. I am uploading a dataset from Excel by giving a command,

fname="data.xls";
range="b2:b634";
sheet=1;
myvars=spreadSheetReadSA(fname,range,sheet);

After having uploaded the file I want to define the variables. Let's say first column is sensex return and second column gdp. How would I be able to define the column? is it by command vnames={"sensex""gdp") how would I be able to run regression between sensex return and gdp?

I would be grateful if you please address this?

Regards,

Debasish

7 Answers



0



In the example code that you posted, I see that you are only loading in one column. For an example, let's pretend that the variable sensex is in the B column of the spreadsheet and gdp is in the C column. Then we could load both columns in a two column matrix, named myvars like this:

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars'
myvars=spreadSheetReadM(fname,range,sheet);

Now myvars contains both of our variables. Since we are assuming, for our example, that sensex was in the B column of the spreadsheet, the first column of myvars will contain the data for the variable sensex. The second column of myvars will contain gdp. We can create a new variable named sensex and a new variable named gdp, using the GAUSS indexing operators like this:

//Extract all rows of the first column
sensex = myvars[.,1];

//Extract all rows of the second column
gdp = myvars[.,2];

Now that we have our model variables, we can run a regression. The GAUSS function ols will compute an ordinary least squares regression and inferential statistics. Here is the basic code needed to run this regression:

//This line is not strictly required, but
//the '__altnam' global variable provides variable names
//for the ols report
__altnam = { "sensex", "gdp" };

call ols("", sensex, gdp);

This will print out a report similar to this (note this report was made with random data):

Valid cases:       100    Dependent variable:       sensex
Missing cases:       0    Deletion method:            None
Total SS:      852.479    Degrees of freedom:           98
R-squared:       0.893    Rbar-squared:              0.892
Residual SS:    90.863    Std error of est:          0.963
F(1,98):       821.440    Probability of F:          0.000

                      Standard              Prob   Standardized  Cor with
Variable   Estimate    Error    t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     0.0491    0.0986    0.4984     0.619       ---         ---  
gdp          0.9367    0.0326   28.6607     0.000    0.945    0.945

aptech

1,773


0



Thanks a ton for your prompt reply. I am applying those changes now. If I feel stuck anywhere, I would come back to you again.



0



Hi,
I have run the codes that you have shared but I am getting errors mentioned below;

c:\gauss10\src\ols.src(296) : error G0165 : Type mismatch or missing arguments
Currently active call: _olsx [296] c:\gauss10\src\ols.src
Stack trace:
_olsx called from c:\gauss10\src\ols.src, line 269
ols

Kindly guide me through the steps



0



We are happy to help. However, I think it would be easiest for us to help if you post your exact lines of code. That will allow us to give an answer tailored to the problems that you are having.

aptech

1,773


0



I am dealing with two variables, nifty and mid. I am uploading data from excel file.

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars'and change the directory to the folder where the data is
myvars=spreadSheetReadSA(fname,range,sheet);

//Extract all rows of the first column
nifty= myvars[.,1];

//Extract all rows of the second column
mid= myvars[.,2];

call ols("", nifty, mid);

Once I give this command to call ols, GAUSS shows error which is as follows;

c:\gauss10\src\ols.src(296) : error G0165 : Type mismatch or missing arguments
Currently active call: _olsx [296] c:\gauss10\src\ols.src
Stack trace:
_olsx called from c:\gauss10\src\ols.src, line 269

Kindly help me out



0



The problem is that your code is reading the data in as a string array, rather than numeric data. (I apologize, my example code originally contained this error).

Assuming the data in the b and c columns of the Excel sheet is numeric, then this should work:

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars' as a matrix
//using spreadSheetReadM
myvars=spreadSheetReadM(fname,range,sheet);

//Extract all rows of the first column
nifty= myvars[.,1];

//Extract all rows of the second column
mid= myvars[.,2];

call ols("", nifty, mid);

Please let me know if you have any more questions.

aptech

1,773


0



Thanks a ton. I am now able to run OLS. I would appreciate you if you help me on another GAUSS code (causality test designed by Anne PEGUIN-FEISSOLLE and Timo TERASVIRTA, 2000) .
I am uploading the codes. I want to run this codes on my variables (nifty and mid). The codes are written on random variables which are generated. However, I would like to run this on my real variables. Kindly navigate me in doing this. I would be grateful to you for this.

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    = 2 ;        /* Nb of lags of the endogenous y for testing */
nretards    = 3 ;        /* 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 @

T           = 200 ;      /* Number of observations */
seedn=982674 ; seedu=68372 ; seednh0=45914 ; seednh1=seednh0 ;

/* generation of the exogenous vector vectorX of dimension Tx1  */
vectorX=zeros(T+100+nretards,1);
i=2;
do while i <= T+100+nretards;
    vectorX[i,1]=0.7*vectorX[i-1,1]+rndns(1,1,seedn);
    i=i+1;
endo;

/* generation of the endogenous vector yzero of dimension (T x 1)  */
	/*  yzero = NLIN ;  without causality */
yzero = NLINX(vectorX) ;  /*   with causality */



/*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 = 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 = 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 = 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  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 = 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 = 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

7 Answers

0

In the example code that you posted, I see that you are only loading in one column. For an example, let's pretend that the variable sensex is in the B column of the spreadsheet and gdp is in the C column. Then we could load both columns in a two column matrix, named myvars like this:

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars'
myvars=spreadSheetReadM(fname,range,sheet);

Now myvars contains both of our variables. Since we are assuming, for our example, that sensex was in the B column of the spreadsheet, the first column of myvars will contain the data for the variable sensex. The second column of myvars will contain gdp. We can create a new variable named sensex and a new variable named gdp, using the GAUSS indexing operators like this:

//Extract all rows of the first column
sensex = myvars[.,1];

//Extract all rows of the second column
gdp = myvars[.,2];

Now that we have our model variables, we can run a regression. The GAUSS function ols will compute an ordinary least squares regression and inferential statistics. Here is the basic code needed to run this regression:

//This line is not strictly required, but
//the '__altnam' global variable provides variable names
//for the ols report
__altnam = { "sensex", "gdp" };

call ols("", sensex, gdp);

This will print out a report similar to this (note this report was made with random data):

Valid cases:       100    Dependent variable:       sensex
Missing cases:       0    Deletion method:            None
Total SS:      852.479    Degrees of freedom:           98
R-squared:       0.893    Rbar-squared:              0.892
Residual SS:    90.863    Std error of est:          0.963
F(1,98):       821.440    Probability of F:          0.000

                      Standard              Prob   Standardized  Cor with
Variable   Estimate    Error    t-value     >|t|     Estimate    Dep Var
-------------------------------------------------------------------------------
CONSTANT     0.0491    0.0986    0.4984     0.619       ---         ---  
gdp          0.9367    0.0326   28.6607     0.000    0.945    0.945
0

Thanks a ton for your prompt reply. I am applying those changes now. If I feel stuck anywhere, I would come back to you again.

0

Hi,
I have run the codes that you have shared but I am getting errors mentioned below;

c:\gauss10\src\ols.src(296) : error G0165 : Type mismatch or missing arguments
Currently active call: _olsx [296] c:\gauss10\src\ols.src
Stack trace:
_olsx called from c:\gauss10\src\ols.src, line 269
ols

Kindly guide me through the steps

0

We are happy to help. However, I think it would be easiest for us to help if you post your exact lines of code. That will allow us to give an answer tailored to the problems that you are having.

0

I am dealing with two variables, nifty and mid. I am uploading data from excel file.

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars'and change the directory to the folder where the data is
myvars=spreadSheetReadSA(fname,range,sheet);

//Extract all rows of the first column
nifty= myvars[.,1];

//Extract all rows of the second column
mid= myvars[.,2];

call ols("", nifty, mid);

Once I give this command to call ols, GAUSS shows error which is as follows;

c:\gauss10\src\ols.src(296) : error G0165 : Type mismatch or missing arguments
Currently active call: _olsx [296] c:\gauss10\src\ols.src
Stack trace:
_olsx called from c:\gauss10\src\ols.src, line 269

Kindly help me out

0

The problem is that your code is reading the data in as a string array, rather than numeric data. (I apologize, my example code originally contained this error).

Assuming the data in the b and c columns of the Excel sheet is numeric, then this should work:

fname="data.xls";

//Range is column 'b' and column 'c'
range="b2:c634";

sheet=1;

//Load both columns into 'myvars' as a matrix
//using spreadSheetReadM
myvars=spreadSheetReadM(fname,range,sheet);

//Extract all rows of the first column
nifty= myvars[.,1];

//Extract all rows of the second column
mid= myvars[.,2];

call ols("", nifty, mid);

Please let me know if you have any more questions.

0

Thanks a ton. I am now able to run OLS. I would appreciate you if you help me on another GAUSS code (causality test designed by Anne PEGUIN-FEISSOLLE and Timo TERASVIRTA, 2000) .
I am uploading the codes. I want to run this codes on my variables (nifty and mid). The codes are written on random variables which are generated. However, I would like to run this on my real variables. Kindly navigate me in doing this. I would be grateful to you for this.

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    = 2 ;        /* Nb of lags of the endogenous y for testing */
nretards    = 3 ;        /* 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 @

T           = 200 ;      /* Number of observations */
seedn=982674 ; seedu=68372 ; seednh0=45914 ; seednh1=seednh0 ;

/* generation of the exogenous vector vectorX of dimension Tx1  */
vectorX=zeros(T+100+nretards,1);
i=2;
do while i <= T+100+nretards;
    vectorX[i,1]=0.7*vectorX[i-1,1]+rndns(1,1,seedn);
    i=i+1;
endo;

/* generation of the endogenous vector yzero of dimension (T x 1)  */
	/*  yzero = NLIN ;  without causality */
yzero = NLINX(vectorX) ;  /*   with causality */



/*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 = 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 = 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 = 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  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 = 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 = 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;

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.