G0152 Variable not Initialized error message

Hello!

I am facing a problem with the error message G0152 and do not know how to fix it. I am running a code that calls another one, which returns the error message. The main code is this one:

new;
closeall;
library user, pgraph;
cls;

/* Global defaults
*/
_output = 1;
_fcmptol = 1E-10;

#include 22kap&M&var_MPMP_testtest_two_mean_var_SW_test4_SOE_nkmp_mod.src;
#include 22kap&M&var_MPMP2_testtest_two_mean_var_SW_test4_SOE2_nkmp_para.src;
#include 22kap&M&var_MP_testtest_two_mean_var_lplh2.src;
#include SOE_nkmp_spec.g;
#include pathspec.g;
#include dsgesel.src;
#include gensys.src;
#include matop.src;
#include gensys_z2.src;
#include kap&M&var_SW_lpdraw.src;

nblock = 1000;
mhrun = "11";

opath = parapath $+ "\\mhrun" $+ mhrun;
chkdir = chk_dir(opath);
/********************************************************
** Import data
** series (nobs,3)
*/
#include SOE_loaddata.g

nobs = rows(YY); /* number of observations */

/********************************************************
** Initialize Output files
*/
oss = opath $+ "\\kap&M&variance_swps";
create fhss = ^oss with SS, nobs,2;

fss = opath $+ "\\kap&M&variance_swfs";
create fhfs = ^fss with fS, nobs,2;
******************
** Open files with theta and phi draws
*/
opath = parapath $+ "\\mhrun" $+ mhrun;
ltheta = opath $+ "\\kap&M&variance_swpa";

open fhtheta = ^ltheta for read;

/********************************************************
** Read files with theta and phi draws
*/

blockind = 1;
eofloop = 0;
nuse = 4; /* use every nuse observation */

do until eofloop;

tstart = date;

theta_sim = readr(fhtheta, nblock );
nread = rows(theta_sim);

indseq = seqa(1,1,nread);
indseq = indseq % nuse;
indseq = indseq .NE 0;

theta_sim = delif(theta_sim,indseq);

ssT_sim1 = zeros( rows(theta_sim), nobs);
fsT_sim1 = zeros( rows(theta_sim), nobs);

i = 1;
do until i > rows(theta_sim);

{SSdraw, probsT} = drawpostss(theta_sim[i,.]',YY,msel);

ssT_sim1[i,.] = SSdraw[.,2]';
fsT_sim1[i,.] = (probsT[.,2])';

i = i+1;
endo;

wr = writer(fhss, ssT_sim1);
eofloop = eof(fhtheta);

wr = writer(fhfs, fsT_sim1);
eofloop = eof(fhtheta);

tend = date;

locate 1,1;
"Block Number: " blockind;
"Draws Processed:" rows(theta_sim);
"Elapsed Time: " etstr(ethsec(tstart,tend));
blockind = blockind + 1;

endo;

closeall fhss, fhtheta, fhphi, fhfs;

 

The error message appears inside the function "drawpostss" (described in the code "kap&M&var_SW_lpdraw.src"). In total it should run 200 blocks (because the dataset "theta_sim" has 200,000 rows). What I don't understand is that the error always appears in the block number 116 and the code stops running, that is to say, the code correctly runs until this block. So in my opinion, all the variables were well initialized at the beginning, right? What could possibly be the source of this error?

I appreciate your help!

Livia Paranhos.

5 Answers



0



Most likely this error occurs because that particular iteration takes a different path at one or more 'if' statements inside the code. Either it skips a section that would define the variable in question, or it enters a section that has not been run before with a variable that has not been defined.

Can you post the line of code that the error message points to?

aptech

1,773


0



Yes, of course. It is a pretty long code, and the error message points out the last line of the procedure "drawpostss":

eofdrawpostss:

 

I will copy the entire code here to make things more clear.

Thank you again!

 

proc (2) = drawpostss(para,YY,msel);
/* This procedure simulates from the latent vector of
** regimes and computes the likelihood of the draws
*/

local npara, retcode, nobs, loglh, loglht, loglhzero, loglhtmax,T10,T00,
obserror, obsvar, nstate, tau,kap, psi1,psi2,psi3,rhoR,rhoz,rr_steady,
pilq, pihq, alp,sigmy,sigmp,sigmr,gam_steady,pi_steady,sigLz,sigHz,sigq,
strans,strans2,strans4, piq, pist,rhopistar,rhoystar,rhoq,ccc, sigR,sigz,sigystar,sigpistar,sigqstar,
T1, TC, T0, EXPeffect_f, EXPeffect_m, EXPeffect, RC,
TT, RR, DD, ZZ, HH, QQ, QQ1,QQ2,QQ3,QQ4, VV, sumzeroprob3 ,sumzeroprob33 ,
t, At, Pt, At1, Pt1, probs12, probs13,draws12,draws13, i3,
Phat, Phat1, Phat2, Phat3, Phat4, yhat, yhat1, yhat2, yhat3, yhat4,
nu, nu1, nu2,nu3, nu4, Ft, Ft1, Ft2, Ft3, Ft4, alphahat, alphahat1, alphahat2, alphahat3, alphahat4, kentry,
probs, probx, probx2, selmat, collind, j, zeroprob, sumzeroprob, sumprobx2, probscore,
i, i2, nx, nxmax, nhist,Ath,Pth,probxh, jh,ih, selmat2, sumprobx22, sumzeroprob2,
EXPepsr, probst, epsr_m, epsr_ms, epsrx_m, epsrx_v, epsrt,draws1,probs1,ssT_draw,
zetat, zetat1, zetat2,ih2, mat2, mat3, ii,
epsrt_draw1, epsrt_draw2, epsrx_draw, probst_draw,jj,jj2,
eq_ygr,eq_pi, eq_r,eq_e, eq_q, ny, v_y, v_pi,v_R,v_e_del, v_q, v_z,e_R,e_q,bet,lamda,nep,
e_z, e_ystar,e_pistar,v_ylag,A,AAA,qi1,qi2,flags, probs11 , draws11 ;

/* Parameters
** THETA: gam, plst, phst, rrst, kap, tau, psi1,
** rhoR, rhog, rhoz, sigg, sigz, sigrl, sigrh
**
** PHI: phi, phi2
*/

npara = rows(para);
retcode = 0;
nhist = 2; /* default */
nxmax = 2^nhist;

nobs = rows(YY);
loglh = 0;
loglhzero = -1E8;
/** observation indices **/
eq_ygr = 1;
eq_pi = 2;
eq_r = 3;
eq_e = 4;
eq_q = 5;

/** number of observation variables **/
ny = 5;

/** variable indices **/
v_y = 1;
v_pi = 2;
v_R = 3;
v_e_del = 4;
v_q = 5;
v_z = 6;
v_ylag = 11;
/** shock indices **/
e_R = 1;
e_q = 2;
e_z = 3;
e_ystar = 4;
e_pistar = 5;
/********************************************************************
** assign names to parameters
********************************************************************/
tau = para[1];
kap = para[2];
psi1 = para[3];
psi2 = para[4];
rhoR = para[5];
rhoz = para[6];

rr_steady = para[7];
pi_steady = para[8];
gam_steady = para[9];
/********************************************************************
additional parameters
********************************************************************/
psi3 = para[10];
alp = para[11]; //import share

rhopistar = para[12]; // pi star
rhoystar = para[13]; // y star
rhoq = para[14]; // q star

ccc = para[15];

/** variance of shocks **/
sigR = para[16];
sigz = para[17];
sigystar = para[18];
sigpistar = para[19];
sigqstar = para[20];

if msel[1]==2; /** with measurement errors **/
sigmy = para[35];
sigmp = para[36];
sigmr = para[37];
endif;
/** additional parameters **/
bet = 1/(1+rr_steady/400); /* impose bet < 1 */
lamda = alp*(2-alp)*(1-tau);

/* Markov Transition Matrix
*/
strans = ( para[21] ~ (1 - para[22]) )|
((1 - para[21]) ~ para[22] );

A = eye(2) - strans | ones(1,2);
AAA = inv(A'*A)*A';
probs = AAA[.,3];

ssT_draw = zeros(nobs,2);

/* Solve the DSGE model */
{T1,T10,TC,T0,T00,RC} = dsgesolv(para,msel);

if (RC[1] == 1) and (RC[2]==1);
/* determinacy */
retcode[1] = 0;

elseif (RC[1] == 1) and (RC[2]==0) ;
/* indeterminacy */
retcode[1] = 1;
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

else;
/* no equilibrium exists, numerical problems */
retcode[1] = RC[1];
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

endif;
/* create system matrices for state space model
*/
nstate = cols(T1);// number of variables in the state vector.
nep =5; // number of foundamental shocks

ZZ = zeros(ny,nstate);

ZZ[eq_ygr,v_y] = 1;
ZZ[eq_ygr,v_ylag] = -1;
ZZ[eq_ygr,v_z] = 1;
ZZ[eq_pi,v_pi] = 4;
ZZ[eq_r,v_R] = 4;

ZZ[eq_e,v_e_del] = 1;
ZZ[eq_q,v_q] = 1;

DD = zeros(ny,1); /** demeaned **/
DD[eq_ygr,1] = gam_steady;
DD[eq_pi,1] = pi_steady;
DD[eq_r,1] = pi_steady + rr_steady + 4*gam_steady;

HH = zeros(ny,ny);
VV = zeros(nep,ny);
QQ = zeros(nep,nep);

/* We can now define the initial mean and variance for the state vector
** We use the same for all three specifications
*/
At = zeros(nstate,1);

QQ[e_R,e_R] = sigR^2;
QQ[e_z,e_z] = sigz^2;
QQ[e_q,e_q] = sigqstar^2;
QQ[e_pistar,e_pistar] = sigpistar^2;
QQ[e_ystar,e_ystar] = sigystar^2;

Pt = dlyap(T1,T0*QQ*T0');

/* Condition on the first observation */
yhat = ZZ*At + DD;
nu = YY[1,.] - yhat';
Ft = ZZ*Pt*ZZ';
Ft = 0.5*(Ft + Ft');
At = At + (Pt*ZZ')*inv(Ft)*nu';
Pt = Pt - (Pt*ZZ')*inv(Ft)*(Pt*ZZ')';
At1 = At';
Pt1 = vec(Pt)';
probx = 1;
nx = 1;

/* Initialize the matrix that store the info from
** the forward simulation
*/
ssT_draw = zeros(nobs,2);
probsT = zeros(nobs,2);
probsT[1,.] = probs';

t = 2;
do until t > nobs;

/* Forecasting the state probabilities
*/

probs = strans * probs;
probx2 = probs .*. probx;
loglht = zeros(2*nx,1);
At = zeros(2*nx,nstate);
Pt = zeros(2*nx,nstate^2);

i = 1;
do until i > nx;

/* Forecasting Step
*/

alphahat1 = T1*At1[i,.]' ;
alphahat2 = T10*At1[i,.]' ;

Phat1 = T1*reshape(Pt1[i,.],nstate,nstate)* T1' + T0* QQ*T0';
Phat2 = T10*reshape(Pt1[i,.],nstate,nstate)*T10' + T00*QQ*T00';

yhat1 = ZZ*alphahat1 + DD;
yhat2 = ZZ*alphahat2 + DD;

nu1 = YY[t,.] - yhat1';
nu2 = YY[t,.] - yhat2';

Ft1 = ZZ*Phat1*ZZ';
Ft2 = ZZ*Phat2*ZZ';

Ft1 = 0.5*(Ft1 + Ft1');
Ft2 = 0.5*(Ft2 + Ft2');
/* Compute likelihood
*/
loglht[i,1] = real(-0.5*cols(YY)*ln(2*pi)
- 0.5*real(ln(det(Ft1))) - 0.5*nu1*inv(Ft1)*nu1' );

loglht[nx+i,1] = real(-0.5*cols(YY)*ln(2*pi)
- 0.5*real(ln(det(Ft2))) - 0.5*nu2*inv(Ft2)*nu2' );

/* Updating Step
*/
At[i,.] = ( alphahat1 + Phat1*ZZ'*inv(Ft1)*nu1' )';
At[nx+i,.] = ( alphahat2 + Phat2*ZZ'*inv(Ft2)*nu2' )';

Pt[i,.] = vec(Phat1 - Phat1*ZZ'*inv(Ft1)*ZZ*Phat1' )';
Pt[nx+i,.] = vec(Phat2 - Phat2*ZZ'*inv(Ft2)*ZZ*Phat2' )';

i = i+1;

endo;

/* Updating mixture probabilities and the state probabilities
*/
loglhtmax = maxc(loglht);
probx2 = (probx2 .* exp(loglht-loglhtmax)) / ( probx2' * exp(loglht-loglhtmax) );
probs = sumc(probx2[1:nx]) | sumc(probx2[nx+1:2*nx]);

/* Collapse the state vector
*/

/* Check for zero probability states
*/
zeroprob = probx2 .< 1E-5;

if sumc(zeroprob) ge (2*nx-nxmax);

/* simply delete the zeroprob states
*/
At1 = delif(At,zeroprob);
Pt1 = delif(Pt,zeroprob);
probx = delif(probx2,zeroprob);

else;


/* we have to collapse some of the states */
selmat = eye(nx).*.(1~1);
sumprobx2 = selmat*probx2;
sumzeroprob = selmat*zeroprob;

At1 = zeros(nxmax,nstate);
Pt1 = zeros(nxmax,nstate^2);
probx = zeros(nxmax,1);

jh = 1;
ih = 1;
do until ih > nx;

ih2 = (ih-1)*2+1;

if sumzeroprob[ih] == 0;

probx[jh] = probx2[ih2]+ probx2[ih2+1];

At1[jh,.] = (probx2[ih2]/probx[jh]) * At[ih2,.]
+ (probx2[ih2+1]/probx[jh]) * At[ih2+1,.];

Pt1[jh,.] = vec( (probx2[ih2]/probx[jh]) * ((reshape(Pt[ih2,.],nstate,nstate) + At[ih2,.]'*At[ih2,.]) )
+ (probx2[ih2+1]/probx[jh]) * ((reshape(Pt[ih2+1,.],nstate,nstate) + At[ih2+1,.]'*At[ih2+1,.]) )
- At1[jh,.]'*At1[jh,.] )';

jh = jh+1;

elseif sumzeroprob[ih] == 1;

if zeroprob[ih2] == 0;
At1[jh,.] = At[ih2,.];
Pt1[jh,.] = Pt[ih2,.];
probx[jh,.] = probx2[ih2];
jh = jh+1;
endif;

if zeroprob[ih2+1] == 0;
At1[jh,.] = At[ih2+1,.];
Pt1[jh,.] = Pt[ih2+1,.];
probx[jh,.] = probx2[ih2+1];
jh = jh+1;
endif;
elseif sumzeroprob[ih] == 2;

probx[jh] = probx2[ih2]+ probx2[ih2+1];

At1[jh,.] = (probx2[ih2]/probx[jh]) * At[ih2,.]
+ (probx2[ih2+1]/probx[jh]) * At[ih2+1,.];

Pt1[jh,.] = vec( (probx2[ih2]/probx[jh]) * ((reshape(Pt[ih2,.],nstate,nstate) + At[ih2,.]'*At[ih2,.]) )
+ (probx2[ih2+1]/probx[jh]) * ((reshape(Pt[ih2+1,.],nstate,nstate) + At[ih2+1,.]'*At[ih2+1,.]) )
- At1[jh,.]'*At1[jh,.] )';

jh = jh+1;
endif;

ih = ih+1;
endo;

endif;
probx = probx/sumc(probx);
nx = rows(At1);

probsT[t,.] = probs';
t = t+1;

endo;

/* Backward simulation */

t = nobs;
probs1 = probsT[t,1];
draws1 = rndu(1,1) le probs1;
ssT_draw[t,1:2] = draws1 ~ (1-draws1);

do until t == 1;

t = t - 1;
probs1 = ssT_draw[t+1,1:2]*Strans[.,1]*(probsT[t,1])/( ssT_draw[t+1,1:2]*Strans*((probsT[t,1])~(probsT[t,2]))' );
draws1 = rndu(1,1) le probs1;
ssT_draw[t,1:2] = draws1 ~ (1-draws1);

endo;
eofdrawpostss:

retp(ssT_draw, probsT);
endp;


0



I think I see what the problem is. First off, if you get a GAUSS error message that points to a 'goto' label, such as:

//goto labels are single 'words' ending with a colon
eofdrawposts:

Then the error is most likely occurring on the next line of code. In this case, the next line of code is:

retp(ssT_draw, probsT);

This would indicate that either 'ssT_draw', or 'probsT' have not yet been defined.

A natural place to look for the code path which is causing the problem would be at any usages of:

goto eofdrawpostss;

since these cases are leaving the procedure early.

Around line 180 or so, we see the only two 'goto' statements in the file:

if (RC[1] == 1) and (RC[2]==1);
/* determinacy */
retcode[1] = 0;

elseif (RC[1] == 1) and (RC[2]==0) ;
/* indeterminacy */
retcode[1] = 1;
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

else;
/* no equilibrium exists, numerical problems */
retcode[1] = RC[1];
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

endif;

Clearly, 'ssT_draw' has been defined before the 'goto' statements. When we check for assignments to the other variable returned in the 'retp' at the end of the procedure, 'probsT', we see that the earliest it is ever assigned is around line 265, in this section of code:

   /* Initialize the matrix that store the info from
   ** the forward simulation
   */
  ssT_draw  = zeros(nobs,4);
   probsT = zeros(nobs,4);
   probsT[1,.] = probs';

Based on this, I think that you are getting the error, because 'probsT' has not been defined, because you are running through either the 'indeterminacy' or 'no equilibrium exists, numerical problems' sections of the code. So the question now becomes, which of these sections is causing the problem and why.

(NOTE: We are happy to help on the forum with this new question that came up. However, in order to make the forum a better resource for others with similar problems, we would prefer you to post a question about how to resolve the indeterminacy/no equilibrium problem under a new question. However, if you have questions about this answer, keep posting them on this question.)

aptech

1,773


0



Hello!

Thanks for your explanation. Actually I think I found the source of the indeterminacy/no equilibrium problem. I have good reasons to think that it is a sample problem because just before running the code I had changed the sample format. It turns out that this change was unwarranted. Thank you anyway for your support on this kind of error.

Livia Paranhos



0



 

Most likely this error occurs because that particular iteration takes a different path at one or more 'if' statements inside the code. Either it skips a section that would define the variable in question, or it enters a section that has not been run before with a variable that has not been defined.

Can you post the line of code that the error message points to?

Your Answer

5 Answers

0

Most likely this error occurs because that particular iteration takes a different path at one or more 'if' statements inside the code. Either it skips a section that would define the variable in question, or it enters a section that has not been run before with a variable that has not been defined.

Can you post the line of code that the error message points to?

0

Yes, of course. It is a pretty long code, and the error message points out the last line of the procedure "drawpostss":

eofdrawpostss:

 

I will copy the entire code here to make things more clear.

Thank you again!

 

proc (2) = drawpostss(para,YY,msel);
/* This procedure simulates from the latent vector of
** regimes and computes the likelihood of the draws
*/

local npara, retcode, nobs, loglh, loglht, loglhzero, loglhtmax,T10,T00,
obserror, obsvar, nstate, tau,kap, psi1,psi2,psi3,rhoR,rhoz,rr_steady,
pilq, pihq, alp,sigmy,sigmp,sigmr,gam_steady,pi_steady,sigLz,sigHz,sigq,
strans,strans2,strans4, piq, pist,rhopistar,rhoystar,rhoq,ccc, sigR,sigz,sigystar,sigpistar,sigqstar,
T1, TC, T0, EXPeffect_f, EXPeffect_m, EXPeffect, RC,
TT, RR, DD, ZZ, HH, QQ, QQ1,QQ2,QQ3,QQ4, VV, sumzeroprob3 ,sumzeroprob33 ,
t, At, Pt, At1, Pt1, probs12, probs13,draws12,draws13, i3,
Phat, Phat1, Phat2, Phat3, Phat4, yhat, yhat1, yhat2, yhat3, yhat4,
nu, nu1, nu2,nu3, nu4, Ft, Ft1, Ft2, Ft3, Ft4, alphahat, alphahat1, alphahat2, alphahat3, alphahat4, kentry,
probs, probx, probx2, selmat, collind, j, zeroprob, sumzeroprob, sumprobx2, probscore,
i, i2, nx, nxmax, nhist,Ath,Pth,probxh, jh,ih, selmat2, sumprobx22, sumzeroprob2,
EXPepsr, probst, epsr_m, epsr_ms, epsrx_m, epsrx_v, epsrt,draws1,probs1,ssT_draw,
zetat, zetat1, zetat2,ih2, mat2, mat3, ii,
epsrt_draw1, epsrt_draw2, epsrx_draw, probst_draw,jj,jj2,
eq_ygr,eq_pi, eq_r,eq_e, eq_q, ny, v_y, v_pi,v_R,v_e_del, v_q, v_z,e_R,e_q,bet,lamda,nep,
e_z, e_ystar,e_pistar,v_ylag,A,AAA,qi1,qi2,flags, probs11 , draws11 ;

/* Parameters
** THETA: gam, plst, phst, rrst, kap, tau, psi1,
** rhoR, rhog, rhoz, sigg, sigz, sigrl, sigrh
**
** PHI: phi, phi2
*/

npara = rows(para);
retcode = 0;
nhist = 2; /* default */
nxmax = 2^nhist;

nobs = rows(YY);
loglh = 0;
loglhzero = -1E8;
/** observation indices **/
eq_ygr = 1;
eq_pi = 2;
eq_r = 3;
eq_e = 4;
eq_q = 5;

/** number of observation variables **/
ny = 5;

/** variable indices **/
v_y = 1;
v_pi = 2;
v_R = 3;
v_e_del = 4;
v_q = 5;
v_z = 6;
v_ylag = 11;
/** shock indices **/
e_R = 1;
e_q = 2;
e_z = 3;
e_ystar = 4;
e_pistar = 5;
/********************************************************************
** assign names to parameters
********************************************************************/
tau = para[1];
kap = para[2];
psi1 = para[3];
psi2 = para[4];
rhoR = para[5];
rhoz = para[6];

rr_steady = para[7];
pi_steady = para[8];
gam_steady = para[9];
/********************************************************************
additional parameters
********************************************************************/
psi3 = para[10];
alp = para[11]; //import share

rhopistar = para[12]; // pi star
rhoystar = para[13]; // y star
rhoq = para[14]; // q star

ccc = para[15];

/** variance of shocks **/
sigR = para[16];
sigz = para[17];
sigystar = para[18];
sigpistar = para[19];
sigqstar = para[20];

if msel[1]==2; /** with measurement errors **/
sigmy = para[35];
sigmp = para[36];
sigmr = para[37];
endif;
/** additional parameters **/
bet = 1/(1+rr_steady/400); /* impose bet < 1 */
lamda = alp*(2-alp)*(1-tau);

/* Markov Transition Matrix
*/
strans = ( para[21] ~ (1 - para[22]) )|
((1 - para[21]) ~ para[22] );

A = eye(2) - strans | ones(1,2);
AAA = inv(A'*A)*A';
probs = AAA[.,3];

ssT_draw = zeros(nobs,2);

/* Solve the DSGE model */
{T1,T10,TC,T0,T00,RC} = dsgesolv(para,msel);

if (RC[1] == 1) and (RC[2]==1);
/* determinacy */
retcode[1] = 0;

elseif (RC[1] == 1) and (RC[2]==0) ;
/* indeterminacy */
retcode[1] = 1;
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

else;
/* no equilibrium exists, numerical problems */
retcode[1] = RC[1];
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

endif;
/* create system matrices for state space model
*/
nstate = cols(T1);// number of variables in the state vector.
nep =5; // number of foundamental shocks

ZZ = zeros(ny,nstate);

ZZ[eq_ygr,v_y] = 1;
ZZ[eq_ygr,v_ylag] = -1;
ZZ[eq_ygr,v_z] = 1;
ZZ[eq_pi,v_pi] = 4;
ZZ[eq_r,v_R] = 4;

ZZ[eq_e,v_e_del] = 1;
ZZ[eq_q,v_q] = 1;

DD = zeros(ny,1); /** demeaned **/
DD[eq_ygr,1] = gam_steady;
DD[eq_pi,1] = pi_steady;
DD[eq_r,1] = pi_steady + rr_steady + 4*gam_steady;

HH = zeros(ny,ny);
VV = zeros(nep,ny);
QQ = zeros(nep,nep);

/* We can now define the initial mean and variance for the state vector
** We use the same for all three specifications
*/
At = zeros(nstate,1);

QQ[e_R,e_R] = sigR^2;
QQ[e_z,e_z] = sigz^2;
QQ[e_q,e_q] = sigqstar^2;
QQ[e_pistar,e_pistar] = sigpistar^2;
QQ[e_ystar,e_ystar] = sigystar^2;

Pt = dlyap(T1,T0*QQ*T0');

/* Condition on the first observation */
yhat = ZZ*At + DD;
nu = YY[1,.] - yhat';
Ft = ZZ*Pt*ZZ';
Ft = 0.5*(Ft + Ft');
At = At + (Pt*ZZ')*inv(Ft)*nu';
Pt = Pt - (Pt*ZZ')*inv(Ft)*(Pt*ZZ')';
At1 = At';
Pt1 = vec(Pt)';
probx = 1;
nx = 1;

/* Initialize the matrix that store the info from
** the forward simulation
*/
ssT_draw = zeros(nobs,2);
probsT = zeros(nobs,2);
probsT[1,.] = probs';

t = 2;
do until t > nobs;

/* Forecasting the state probabilities
*/

probs = strans * probs;
probx2 = probs .*. probx;
loglht = zeros(2*nx,1);
At = zeros(2*nx,nstate);
Pt = zeros(2*nx,nstate^2);

i = 1;
do until i > nx;

/* Forecasting Step
*/

alphahat1 = T1*At1[i,.]' ;
alphahat2 = T10*At1[i,.]' ;

Phat1 = T1*reshape(Pt1[i,.],nstate,nstate)* T1' + T0* QQ*T0';
Phat2 = T10*reshape(Pt1[i,.],nstate,nstate)*T10' + T00*QQ*T00';

yhat1 = ZZ*alphahat1 + DD;
yhat2 = ZZ*alphahat2 + DD;

nu1 = YY[t,.] - yhat1';
nu2 = YY[t,.] - yhat2';

Ft1 = ZZ*Phat1*ZZ';
Ft2 = ZZ*Phat2*ZZ';

Ft1 = 0.5*(Ft1 + Ft1');
Ft2 = 0.5*(Ft2 + Ft2');
/* Compute likelihood
*/
loglht[i,1] = real(-0.5*cols(YY)*ln(2*pi)
- 0.5*real(ln(det(Ft1))) - 0.5*nu1*inv(Ft1)*nu1' );

loglht[nx+i,1] = real(-0.5*cols(YY)*ln(2*pi)
- 0.5*real(ln(det(Ft2))) - 0.5*nu2*inv(Ft2)*nu2' );

/* Updating Step
*/
At[i,.] = ( alphahat1 + Phat1*ZZ'*inv(Ft1)*nu1' )';
At[nx+i,.] = ( alphahat2 + Phat2*ZZ'*inv(Ft2)*nu2' )';

Pt[i,.] = vec(Phat1 - Phat1*ZZ'*inv(Ft1)*ZZ*Phat1' )';
Pt[nx+i,.] = vec(Phat2 - Phat2*ZZ'*inv(Ft2)*ZZ*Phat2' )';

i = i+1;

endo;

/* Updating mixture probabilities and the state probabilities
*/
loglhtmax = maxc(loglht);
probx2 = (probx2 .* exp(loglht-loglhtmax)) / ( probx2' * exp(loglht-loglhtmax) );
probs = sumc(probx2[1:nx]) | sumc(probx2[nx+1:2*nx]);

/* Collapse the state vector
*/

/* Check for zero probability states
*/
zeroprob = probx2 .< 1E-5;

if sumc(zeroprob) ge (2*nx-nxmax);

/* simply delete the zeroprob states
*/
At1 = delif(At,zeroprob);
Pt1 = delif(Pt,zeroprob);
probx = delif(probx2,zeroprob);

else;


/* we have to collapse some of the states */
selmat = eye(nx).*.(1~1);
sumprobx2 = selmat*probx2;
sumzeroprob = selmat*zeroprob;

At1 = zeros(nxmax,nstate);
Pt1 = zeros(nxmax,nstate^2);
probx = zeros(nxmax,1);

jh = 1;
ih = 1;
do until ih > nx;

ih2 = (ih-1)*2+1;

if sumzeroprob[ih] == 0;

probx[jh] = probx2[ih2]+ probx2[ih2+1];

At1[jh,.] = (probx2[ih2]/probx[jh]) * At[ih2,.]
+ (probx2[ih2+1]/probx[jh]) * At[ih2+1,.];

Pt1[jh,.] = vec( (probx2[ih2]/probx[jh]) * ((reshape(Pt[ih2,.],nstate,nstate) + At[ih2,.]'*At[ih2,.]) )
+ (probx2[ih2+1]/probx[jh]) * ((reshape(Pt[ih2+1,.],nstate,nstate) + At[ih2+1,.]'*At[ih2+1,.]) )
- At1[jh,.]'*At1[jh,.] )';

jh = jh+1;

elseif sumzeroprob[ih] == 1;

if zeroprob[ih2] == 0;
At1[jh,.] = At[ih2,.];
Pt1[jh,.] = Pt[ih2,.];
probx[jh,.] = probx2[ih2];
jh = jh+1;
endif;

if zeroprob[ih2+1] == 0;
At1[jh,.] = At[ih2+1,.];
Pt1[jh,.] = Pt[ih2+1,.];
probx[jh,.] = probx2[ih2+1];
jh = jh+1;
endif;
elseif sumzeroprob[ih] == 2;

probx[jh] = probx2[ih2]+ probx2[ih2+1];

At1[jh,.] = (probx2[ih2]/probx[jh]) * At[ih2,.]
+ (probx2[ih2+1]/probx[jh]) * At[ih2+1,.];

Pt1[jh,.] = vec( (probx2[ih2]/probx[jh]) * ((reshape(Pt[ih2,.],nstate,nstate) + At[ih2,.]'*At[ih2,.]) )
+ (probx2[ih2+1]/probx[jh]) * ((reshape(Pt[ih2+1,.],nstate,nstate) + At[ih2+1,.]'*At[ih2+1,.]) )
- At1[jh,.]'*At1[jh,.] )';

jh = jh+1;
endif;

ih = ih+1;
endo;

endif;
probx = probx/sumc(probx);
nx = rows(At1);

probsT[t,.] = probs';
t = t+1;

endo;

/* Backward simulation */

t = nobs;
probs1 = probsT[t,1];
draws1 = rndu(1,1) le probs1;
ssT_draw[t,1:2] = draws1 ~ (1-draws1);

do until t == 1;

t = t - 1;
probs1 = ssT_draw[t+1,1:2]*Strans[.,1]*(probsT[t,1])/( ssT_draw[t+1,1:2]*Strans*((probsT[t,1])~(probsT[t,2]))' );
draws1 = rndu(1,1) le probs1;
ssT_draw[t,1:2] = draws1 ~ (1-draws1);

endo;
eofdrawpostss:

retp(ssT_draw, probsT);
endp;
0

I think I see what the problem is. First off, if you get a GAUSS error message that points to a 'goto' label, such as:

//goto labels are single 'words' ending with a colon
eofdrawposts:

Then the error is most likely occurring on the next line of code. In this case, the next line of code is:

retp(ssT_draw, probsT);

This would indicate that either 'ssT_draw', or 'probsT' have not yet been defined.

A natural place to look for the code path which is causing the problem would be at any usages of:

goto eofdrawpostss;

since these cases are leaving the procedure early.

Around line 180 or so, we see the only two 'goto' statements in the file:

if (RC[1] == 1) and (RC[2]==1);
/* determinacy */
retcode[1] = 0;

elseif (RC[1] == 1) and (RC[2]==0) ;
/* indeterminacy */
retcode[1] = 1;
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

else;
/* no equilibrium exists, numerical problems */
retcode[1] = RC[1];
loglh = loglhzero;
ssT_draw = ones(nobs,1)~zeros(nobs,1);
goto eofdrawpostss;

endif;

Clearly, 'ssT_draw' has been defined before the 'goto' statements. When we check for assignments to the other variable returned in the 'retp' at the end of the procedure, 'probsT', we see that the earliest it is ever assigned is around line 265, in this section of code:

   /* Initialize the matrix that store the info from
   ** the forward simulation
   */
  ssT_draw  = zeros(nobs,4);
   probsT = zeros(nobs,4);
   probsT[1,.] = probs';

Based on this, I think that you are getting the error, because 'probsT' has not been defined, because you are running through either the 'indeterminacy' or 'no equilibrium exists, numerical problems' sections of the code. So the question now becomes, which of these sections is causing the problem and why.

(NOTE: We are happy to help on the forum with this new question that came up. However, in order to make the forum a better resource for others with similar problems, we would prefer you to post a question about how to resolve the indeterminacy/no equilibrium problem under a new question. However, if you have questions about this answer, keep posting them on this question.)

0

Hello!

Thanks for your explanation. Actually I think I found the source of the indeterminacy/no equilibrium problem. I have good reasons to think that it is a sample problem because just before running the code I had changed the sample format. It turns out that this change was unwarranted. Thank you anyway for your support on this kind of error.

Livia Paranhos

0

 

Most likely this error occurs because that particular iteration takes a different path at one or more 'if' statements inside the code. Either it skips a section that would define the variable in question, or it enters a section that has not been run before with a variable that has not been defined.

Can you post the line of code that the error message points to?


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.