hi, I'm trying to run following codes, and it shows error G0458
/********************************************* load the data **********************************************/ LOAD data[50,4]=x.txt; r = data[.,1]; e = data[.,2]; de = data[.,3]; ep = data[.,4]; dv=r~e~de~ep; /******************************* parameters **************************************************************/ q_nw = 2; Ku = 20; /*******************************************************************************************************************/ 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) */D=(1/T).*(EYE(N).*.(X'X)); 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; /******************************************* ANALYSIS**************************************/ rho = 1/(1+exp(meanc(ep))); "rho ="; rho; {T,N,R2,AR2,B,BETA,T_BETA,P_BETA,AVCOVB_NW,VCOV_EHAT}=VAR_REST(dv,ep,q_nw); "number of observations"; T; "number of variables in the VAR"; N; "R2 for VAR equations"; R2; "adjusted R2 for VAR equations"; AR2; "VAR coefficients"; B; "VAR coefficients"; BETA; "t-statistics for VAR coefficients"; T_BETA; "p-values for VAR coefficients"; P_BETA; "var-cov matrix for vAR coefficients"; AVCOVB_NW; avcovb=AVCOVB_NW[2 4 6 8,2 4 6 8]; "var-cov matrix for vAR slope coefficients"; AVCOVB; "var-cov matrix for vAR residuals"; VCOV_EHAT; b_r=beta[1,2]; b_e=beta[2,2]; b_de=beta[3,2]; phi=beta[4,2]; "b_r"; b_r; "b_e"; b_e; "b_de"; b_de; "phi"; phi; b_ri = 1-rho*phi+b_e+b_de; b_ei = -1+rho*phi+b_r-b_de; b_dei = -1+rho*phi+b_r-b_e; phi_i = (1+b_e-b_r+b_de)/rho; "implied b_r"; b_ri; "implied b_e"; b_ei; "implied b_de"; b_dei; "implied phi"; phi_i; jacob = 0~1~1~(-rho)|1~0~(-1)~rho|1~(-1)~0~rho|(-1/rho)~(1/rho)~(1/rho)~0; varcov = jacob*avcovb*jacob'; "variance-covariance matrix for the implied coefficients"; varcov; tstat = (b_ri|b_ei|b_dei|phi_i)./sqrt(diag(varcov)); "---------------------------K-year decompositions-----------------------------------"; b_lrk = zeros(Ku,1); b_lek = zeros(Ku,1); b_ldek = zeros(Ku,1); b_lepk = zeros(Ku,1); identk = zeros(Ku,1); t_lrk1 = zeros(Ku,1); t_lek1 = zeros(Ku,1); t_lde1 = zeros(Ku,1); t_lepk1 = zeros(Ku,1); t_lrk2 = zeros(Ku,1); t_lek2 = zeros(Ku,1); t_ldek2 = zeros(Ku,1); t_lepk2 = zeros(Ku,1); K=1; do while K<=Ku; /* implied VAR(1) estimates */ b_lr = b_r*(1-(rho^K)*(phi^K))/(1-rho*phi); b_le = b_e*(1-(rho^K)*(phi^K))/(1-rho*phi); b_lde = (1-rho)*b_de*(1-(rho^K)*(phi^K))/(1-rho*phi); b_lep = (rho^K)*(phi^K); ident = b_lr-b_le-b_lde+b_lep; aux1 = -K*b_r*(rho^K)*(phi^(K-1))*(1-rho*phi)+rho*b_r*(1-(rho^K)*(phi^K)); aux2 = -K*b_e*(rho^K)*(phi^(K-1))*(1-rho*phi)+rho*b_e*(1-(rho^K)*(phi^K)); aux3 = -K*b_de*(rho^K)*(phi^(K-1))*(1-rho*phi)*(1-rho)+rho*b_e*(1-(rho^K)*(phi^K))*(1-rho); aux4 = (1-rho*phi)^2; aux_br = aux1/aux4; aux_be = aux2/aux4; aux_bde = aux3/aux4; jacob = ((1-(rho^K)*(phi^K))/(1-rho*phi))~0~0~aux_br|0~((1-rho)*(1-(rho^K)*(phi^K))/(1-rho*phi))~0~aux_be|0~0~((1-(rho^K)*(phi^K))/(1-rho*phi))~aux_bde|0~0~0~K*(rho^K)*(phi^(K-1)); varcov = jacob*avcovb*jacob'; tstat1 = (b_lr|b_le|b_lde|b_lep)./sqrt(diag(varcov)); tstat2 = (b_lr-1|b_le+1|b_lde+1|b_lep-1)./sqrt(diag(varcov)); b_lrk[K,1] = b_lr; b_lek[K,1] = b_le; b_ldek[K,1] = b_lde; b_lepk[K,1] = b_lep; identk[K,1] = ident; t_lrk1[K,1] = tstat1[1,1]; t_lek1[K,1] = tstat1[2,1]; t_ldek1[K,1] = tstat1[3,1]; t_lepk1[K,1] = tstat1[4,1]; t_lrk2[K,1] = tstat2[1,1]; t_lek2[K,1] = tstat2[2,1]; t_lde2[K,1] = tstat2[3,1]; t_lepk2[K,1] = tstat2[4,1]; K=K+1; endo; auxk = seqa(1,1,Ku); "long-run coefficients"; auxk~b_lrk~b_lek~b_ldek~b_lepk; "t-stats for long-run coefficients. Null hypthesis: b_l=1,-1"; auxk~t_lrk2~t_lek2~t_ldek2~t_lepk2;
4 Answers
0
The error report should give you a line number. What is the code on the line from the error report?
0
sorry, I copy paste the codes, and there isn't a line showing the error.
the error just pop out at the end of programme
0
but the errors must appear after "K-year decompositions"
0
When I run the code, I get this:
It shows that the error is on line 168. This error is occurring, because the variable t_ldek1 has never been initialized to anything. So the code is trying to index into something that does not exist.
The reason the error comes up this way is that GAUSS first assumes that a variable is a procedure until it is defined to be something else.
Your Answer
4 Answers
The error report should give you a line number. What is the code on the line from the error report?
sorry, I copy paste the codes, and there isn't a line showing the error.
the error just pop out at the end of programme
but the errors must appear after "K-year decompositions"
When I run the code, I get this:
It shows that the error is on line 168. This error is occurring, because the variable t_ldek1 has never been initialized to anything. So the code is trying to index into something that does not exist.
The reason the error comes up this way is that GAUSS first assumes that a variable is a procedure until it is defined to be something else.