hi it keep showing this error, can you please tell me how to correct it

/********************************************* load the data ***********************************************/ LOAD data[51,3]=gauss.txt; r = data[.,1]; dg = data[.,2]; dp = data[.,3]; dv=r~dg~dp /******************************* parameters ********************************************/ q_nw = 2; /******************************************************************************************************************************************/ PROC(10)=VAR_REST(YY,XX,Q_NW); /* Restricted VAR */ LOCAL T,N,X,K,Y,Z,W_I,D,B,EHAT,EPSLON,AUX1,AUX2,R2,AR2,G,S_W,S_NW,J,GAMMA_J,AVCOVB_NW,SEB_NW,TSTATB_NW,PVALUES_NW, BETA,T_BETA,P_BETA,VCOV_EHAT; /* Definition of variables */ YY=LAGN(YY,-1); YY=TRIMR(YY,0,1); XX=TRIMR(XX,0,1); T=ROWS(YY);/* number of observations*/ X=ONES(T,1)~XX; /* Number of forecasting variables (including a constant) */ K=COLS(X); N=COLS(YY); /* N is the number of variables in the VAR */ /* Calculations */ Y=RESHAPE(YY',1,N*T)'; Z=EYE(N).*.X; /* data matrix of the regressors (NTxNK) */ W_I=EYE(N*K); /* weighting matrix for first stage GMM (NKxNK) */ D=(1/T).*(EYE(N).*.X'X); /* D matrix; equal to dgT(b)/db (NKxNK) */ B=(EYE(N).*.(INVPD(X'X)*X'))*Y; /* Simplified formula (applied to this case) for GMM estimator (NKx1) */ EHAT=Y-Z*B; /* stacked vector with residuals (NTx1) */ EPSLON=RESHAPE(EHAT,N,T); /* Auxiliar matrix. Transforms the vector of residuals into a matrix, where each column corresponds to the t th observation, t =1,...,T (NxT) */ VCOV_EHAT=VCXS(EPSLON'); AUX1=(EPSLON'-MEANC(EPSLON')')'(EPSLON'-MEANC(EPSLON')'); AUX2=(YY-MEANC(YY)')'(YY-MEANC(YY)'); R2=1-DIAG(AUX1)./DIAG(AUX2); AR2=ONES(N,1)-(ONES(N,1)-R2).*((T-1)/(T-K)); G=(EPSLON')*~X; S_W=(1/T).*G'G; /****************************************************************************************** Newey-West standard errors ******************************************************************************************/ S_NW=ZEROS(N*K,N*K); J=1; DO WHILE J<=Q_NW-1; GAMMA_J=(1/T).*G[1:T-J,.]'G[1+J:T,.]+(1/T).*G[1+J:T,.]'G[1:T-J,.]; S_NW=S_NW+(1-J/Q_NW).*GAMMA_J; J=J+1; ENDO; S_NW=S_W+S_NW; AVCOVB_NW=(1/T).*(INVPD(D)*S_NW*INVPD(D)); SEB_NW=SQRT(DIAG(AVCOVB_NW)); TSTATB_NW=B./SEB_NW; PVALUES_NW=2*CDFNC(ABS(TSTATB_NW)); BETA=RESHAPE(B,N,K); T_BETA=RESHAPE(TSTATB_NW,N,K); P_BETA=RESHAPE(PVALUES_NW,N,K); RETP(T,N,R2,AR2,B,BETA,T_BETA,P_BETA,AVCOVB_NW,VCOV_EHAT); ENDP;

{T,N,R2,AR2,B,BETA,T_BETA,P_BETA,AVCOVB_NW,VCOV_EHAT}=VAR_REST(dv,dp,q_nw);

## 11 Answers

The error message should tell you which line the error is occurring on. Which line is causing the error?

line 77, in black

proc lagn(x,n);

local y;

y = shiftr(x', n, (miss(0, 0))');

**retp(y');**

endp;

I'm using a light version, i don't know if the error message telling the same thing as in full version

What are the dimensions of `YY` at the beginning of `VAR_REST`? If `VAR_REST` is called multiple times and the error is not on the first one, it might be simplest to add a print statement right before the call to `lagn`. Something like:

print "at the start of VAR_REST, YY is: " rows(YY) " by " cols(YY);

at the start of VAR_REST, YY is 51 by 3

I don't think that is what is causing the error. Is `VAR_REST` being called more than once? If you are using GAUSS 14 and you have an error in a procedure like `lagn` you should a nicely laid out stack trace that will tell you the line and file from which `lagn` was called that caused the error.

Since you have GAUSS Light which does not have the debugger, I would put print statements before and after the call to `lagn` at the start of the `VAR_REST` function. For example, I would change this part of the code:

/* Definition of variables */ YY=LAGN(YY,-1); YY=TRIMR(YY,0,1); XX=TRIMR(XX,0,1);

to:

/* Definition of variables */ print "rows(YY) = " rows(YY) "cols(YY) = " cols(YY); YY=LAGN(YY,-1); print "back from LAGN call"; YY=TRIMR(YY,0,1); XX=TRIMR(XX,0,1);

Then if you don't see "back from LAGN call", you can be more certain that the error did occur there. You will also see what the size of `YY` was right before the error.

********************** START **********************

rows(YY) = 51.000000 cols(YY) = 3.0000000

back from LAGN call

Does that mean my error occurs from the very beginning of the lagn call, and `VAR_REST` has being called once only. there is a separate sheet (lag.src) showed some examples, and marked the **retp(y')**

**> lagn

**

** Purpose: Lags a matrix a specified number of time periods for

** time series analysis.

**

** Format: y = lagn(x,t);

**

** Input: x NxK matrix.

**

** t scalar, number of time periods.

**

** Output: y NxK matrix, x lagged t periods.

**

** Remarks: If t is positive, lagn lags x back by t time periods, so

** the first t observations of y are missing.

** If t is negative, lagn lags x forward by t time periods, so

** the last t observations of y are missing.

**

** See Also: lag1

*/

proc lagn(x,n);

local y;

y = shiftr(x', n, (miss(0, 0))');

**retp(y');**

endp;

It means that the `VAR_REST` procedure is not being called more than once before the error. It also means that the error is not related to `lagn`. To narrow it down. I would add a couple of print statements to the `VAR_REST` procedure, something like:

print "passed line <enter line number here>

When I run that code in GAUSS, I get the following error message:

Looking at the line of code that is causing the error, it appears to me that there is a bug in this program. The kronecker product has the same operator precedence as matrix multiplication, so that is evaluated first. However, I believe they want (X'X) evaluated first. Place parentheses around X'X on that line like this:

D=(1/T).*(EYE(N).*.(X'X));

and the code will run.

oh i didn't noticed this mistake at all..

it is running now, thanks so much!!

Thank you, this solution solved my problem, too:)