when I run following codes, it always shows operator missing, however if i separate the codes into parts, i can get the results i need. I'm wondering how to make it run smoothly without cutting codes into several pieces?
/********************************************* load the data **********************************************/
LOAD data[50,3]=main.txt; r = data[.,1]; d = data[.,2]; dp = data[.,3]; dv=r~d~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) */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;
4 Answers
also how to make a loop if I want to redo following estimation by changing '5' to 10, 15 and 20?
"b_lr"; b_lr; "b_ld"; b_ld; "b_ldp"; b_ldp;
jacob = ((1-(rho^5)*(phi^5))/(1-rho*phi))~0~aux_br|0~((1-(rho^5)*(phi^5))/(1-rho*phi))~aux_bd|0~0~5*(rho^5)*(phi^(5-1)); varcov = jacob*avcovb*jacob'; tstat = (b_lr|b_ld|b_ldp)./sqrt(diag(varcov));
It seems that you are missing a semi-colon towards the top on the line that reads:
dv=r~d~p
Below is an image of the error that I receive from GAUSS:
There is also another line missing a semi-colon further down--the second line after "---------------------------long-run coefficients-----------------------------------";
thanks for helping on this issue.
I also did another analysis after "--------long-run coefficients--------------------------------", but Gauss keep running without showing any results, I must did something stupid again..
"---------------------------K-year decompositions-----------------------------------";
Ku = 20;
b_lrk = zeros(Ku,1);
b_ldk = zeros(Ku,1);
b_ldpk = zeros(Ku,1);
identk = zeros(Ku,1);
t_lrk1 = zeros(Ku,1);
t_ldk1 = zeros(Ku,1);
t_ldpk1 = zeros(Ku,1);
t_lrk2 = zeros(Ku,1);
t_ldk2 = zeros(Ku,1);
t_ldpk2 = zeros(Ku,1);
b_lrkd = zeros(Ku,1);
b_ldkd = zeros(Ku,1);
b_ldpkd = zeros(Ku,1);
t_lrkd = zeros(Ku,1);
t_ldkd = zeros(Ku,1);
t_ldpkd = zeros(Ku,1);
identkd = 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_ld = b_d*(1-(rho^K)*(phi^K))/(1-rho*phi);
b_ldp = (rho^K)*(phi^K);
ident = b_lr-b_ld+b_ldp;
aux1 = -K*b_r*(rho^K)*(phi^(K-1))*(1-rho*phi)+rho*b_r*(1-(rho^K)*(phi^K));
aux2 = -K*b_d*(rho^K)*(phi^(K-1))*(1-rho*phi)+rho*b_d*(1-(rho^K)*(phi^K));
aux3 = (1-rho*phi)^2;
aux_br = aux1/aux3;
aux_bd = aux2/aux3;
jacob = ((1-(rho^K)*(phi^K))/(1-rho*phi))~0~aux_br|0~((1-(rho^K)*(phi^K))/(1-rho*phi))~aux_bd|0~0~K*(rho^K)*(phi^(K-1));
varcov = jacob*avcovb*jacob';
tstat1 = (b_lr|b_ld|b_ldp)./sqrt(diag(varcov));
tstat2 = ((b_lr-1)|(b_ld+1)|(b_ldp-1))./sqrt(diag(varcov));
b_lrk[K,1] = b_lr;
b_ldk[K,1] = b_ld;
b_ldpk[K,1] = b_ldp;
identk[K,1] = ident;
t_lrk1[K,1] = tstat1[1,1];
t_ldk1[K,1] = tstat1[2,1];
t_ldpk1[K,1] = tstat1[3,1];
t_lrk2[K,1] = tstat2[1,1];
t_ldk2[K,1] = tstat2[2,1];
t_ldpk2[K,1] = tstat2[3,1];
Endo;
I made a new question to answer your question about the loop not ending which you can find here. It is generally better to start a new thread for a question about a different problem even if it is related, because it makes it easier for others in the future to find an answer to their problem if they encounter one like yours.