# error g0025

I have a problem, what should I do?

``G0025: Undefined symbol 'resid' [procs.txt, line 76]``

Program

``````resid = y[pphi+1:capt,1] - alpha0;
iz = 1;
do until iz > pphi;
resid = resid - phi[iz,1]*y[pphi+1-iz:capt-iz,1];
iz = iz+1;
endo;
if pphi > 0;
resid = (sig0*ones(pphi,1)) | resid;
endif;``````

0

Is that code inside of a GAUSS proc? If so, can you post the entire procedure (the code from proc (1) = procname all the way to endp). The error message means that the code is trying to use the value in a variable named resid before resid is assigned a value.

0

this procedure for procs. What should i do?

/* ============================================================== */
proc matf(pm); @This proc returns the (n x n) matrix F of Markov
transition probabilities for state vector @
local iz,iw,ib,na,nb,nc,fz,fm;

@ set initial values for use with iteration @
na = 1;
nb = ns;
nc = ns*ns;
fm = pm;
iz = 1;
do until iz > ps;
fz = fm;
fm = zeros(nc,nc);
iw = 1;
do until iw > ns;
fm[((iw-1)*nb+1):(iw*nb),((iw-1)*na+1):(iw*na)]
= fz[1:nb,((iw-1)*na+1):iw*na];
iw = iw+1;
endo;
ib = 2;
do until ib > ns;
fm[1:nc,((ib-1)*nb+1):ib*nb] = fm[1:nc,1:nb];
ib = ib+1;
endo;
na = na*ns;
nb = nb*ns;
nc = nc*ns;
iz = iz+1;
endo;
retp(fm);
endp;
/* ==================================================================== */

/* ================================================================= */
proc ofn(th); @ this proc evaluates filter probs and likelihood @
local spar,eps,alpha0,phi,sig0,a0,a1,g1,pm,b1,l1,cm,nu,
iz,fm,chsi,it,f,fit,fx,hw,fj,ij,ap,const,pq,hk,ihk;

@ -------------- Convert parameter vector to convenient form [email protected]
spar = 1;
alpha0 = th[1,1];
spar = spar + 1;
if pphi > 0;
phi = th[spar:spar+pphi-1,1];
else;
phi = 0;
endif;
spar = spar + pphi;
sig0 = 10000;
a0 = abs(th[spar,1]);
a1 = abs(th[spar+1:spar+karch,1]);
spar = spar+1+karch;
b1=abs(th[spar:spar+garch-1,1]);
spar=spar+garch;
pm = matpm(th[spar:spar+(ns*(ns-1))-1-irs,1]);
spar = spar+(ns*(ns-1))-irs;
g1 = 1|abs(th[spar:spar+ns-2,1]);
spar = spar+ns-1;
if larch == 1;
l1 = abs(th[spar,1]);
spar = spar+1;
endif;
if tarch == 1;
nu = 2 + abs(th[spar,1]);
spar = spar + 1;
endif;

@ ---------- Convert data to AR resids [email protected]
resid = y[pphi+1:capt,1] - alpha0;
iz = 1;
do until iz > pphi;
resid = resid - phi[iz,1]*y[pphi+1-iz:capt-iz,1];
iz = iz+1;
endo;
if pphi > 0;
resid = (sig0*ones(pphi,1)) | resid;
endif;

@------------- Collect karch+1 most recent squared residuals in
the captst by karch + 1 matrix heta [email protected]
eta2 = resid^2;
heta = a0*ones(captst,1);
iz = 1;
do until iz > karch;
heta = heta ~ eta2[nk-iz:capt-iz,1];
iz = iz + 1;
endo;

if larch == 1; @ Correct heta for leverage effects if desired @
heta[.,2] = heta[.,2]
+ (l1/a1[1,1])*
((resid[nk-1:nk-1+captst-1,1] . ps+1;
hsig[iz,(iz-1)*ns+1:iz*ns] = a1[iz-1,1]./g1';
iz = iz+1;
endo;
hsig = hsig*hp;

@----------- Postmultiply heta by hsig to obtain the captst by n matrix of
variances that would apply for each of the n possible configurations
for recent states [email protected]
heta = heta*hsig;
h0 = meanc(y^2)*ones(capt,1);
iz = 1;
do until iz > garch;
h0= h0[nk-iz:capt-iz,1];
iz = iz + 1;
endo;

ig = nk;
do until ig > captst;
h0[ig,1]=heta[ig,1]+b1*h0[ig-1,1];
ig=ig+1;
endo;
heta=h0;
hq = ones(1,ns^karch).*.g1';
heta = heta.*hq;

@------------ Calculate a captst by n matrix of conditional densities;
row t of this matrix gives the n possible values the likelihood would
take at date t for each of the n possible configurations of states [email protected]
if tarch == 0; @ normal density here @
eta = eta2[nk:nk+captst-1,1]./heta;
eta = 0.39894228 * (1./sqrt(heta)).*exp(-eta/2);
elseif tarch == 1; @ t density here @
eta = ones(captst,n) + (eta2[nk:nk+captst-1,1]./(heta*(nu-2)));
endif;

@---------- Calculate ergodic probabilities [email protected]
fm = matf(pm);
ap = (eye(n)-fm)|ones(1,n);
chsi = sumc((invpd(ap'*ap))');
chsi = maxc(chsi'|zeros(1,n)); @ This line eliminates roundoff error @
if kc > 1;
"";"Matrix of Markov transition probabilities:";pm;
"";"Ergodic probs for full state vector:";chsi';
"";"Ergodic probs for primitive states:";
pq = hp*chsi;pq[1:ns,1]';
endif;

@ ------------The basic filter iteration is contained here ----------- @
f = 0;
it = 1;
do until it > captst;

if ks == 2; @calculate predicted variances and outlier probs if
desired @
varfor[it+nk-1,1] = heta[it,.]*chsi;
if tarch == 0;
hprob = cdfnc(resid[it+nk-1,1]./sqrt(heta[it,.]));
elseif tarch == 1;
hprob = cdftc(resid[it+nk-1,1]./
sqrt(heta[it,.]*(nu-2)/nu),nu);
endif;
outprob[it+nk-1,1] = hprob*chsi;
endif;

fx = chsi .* eta[it,.]';
fit = sumc(fx);
skif[it,.] = fx'/fit;
f = f + ln(fit);
chsi = fm*fx/fit;
it = it+1;
endo;

@ --------- Calculate smoothed probabilities if desired [email protected]
if ks == 2;
skis[captst,.] = skif[captst,.];
it = 1;
do until it == captst;
if minc(skif[captst-it,.]') > 1.e-150;
skis[captst-it,.] = skif[captst-it,.].*
((skis[captst-it+1,.]./(skif[captst-it,.]*fm'))*fm);
else; @ adjust code so as not to divide by zero @
hk = skif[captst-it,.]*fm';
ihk = 1;
do until ihk > n;
if hk[1,ihk] > 1.e-150;
hk[1,ihk] = skis[captst-it+1,ihk]/hk[1,ihk];
else;
hk[1,ihk] = 0;
endif;
ihk = ihk + 1;
endo;
skis[captst-it,.] = skif[captst-it,.].*(hk*fm);
endif;
it = it+1;
endo;
endif;

@-------- Print out value of log likelihood if desired [email protected]
if kc == 2;
"";"Log likelihood:";f;
endif;

retp(-f);
endp;
/*===============================================================*/
/*============= Calculate Q-Statistic ===========================*/
proc Qstat(res,k);

local r,Q,n,j,pvalue;

n=rows(res);
r=zero(k,1);

j=1;
do while j<=k;
r[j]= (sumc((res[j+1:n]-meanc(res[j+1:n]).*(res[1:n-j]-meanc(res[1:n-j])))/(n-j))/(sumc((res-meanc(res))^2)/n);
j=j+1;
endo;

Q = n*(n+2)*sumc((r.^2)./(n-seqa(1,1,k)));
pvalue=cdfchic(Q,k);
/* print "Q(" k ")= " Q "[" pvalue "]";
print "r" r;
*/
retp(pvalue);
endp;

0

Problem you report It appears that the problem is in the procedure `ofn`. They must have declared or used a global variable somewhere else named `resid`. This procedure will run if you add `resid` to the list of `ofn` local variables, like this:

``````proc ofn(th); @ this proc evaluates filter probs and likelihood @
local spar,eps,alpha0,phi,sig0,a0,a1,g1,pm,b1,l1,cm,nu,
iz,fm,chsi,it,f,fit,fx,hw,fj,ij,ap,const,pq,hk,ihk, resid;``````

Notice I added resid to the end of the list. If the program needs to use this value that is set in ofn that will cause problems later. Probably there is another file that came with this code that first assigns a value to resid. You may need to run that file first. Do you have another file that came with this code that defines resid?

Second problem I found While looking over the code, I found one mistake. There is an `if` in the `ofn` procedure that looks like this:

``````    if larch == 1; @ Correct heta for leverage effects if desired @
heta[.,2] = heta[.,2]
+ (l1/a1[1,1])*
((resid[nk-1:nk-1+captst-1,1] . ps+1;
hsig[iz,(iz-1)*ns+1:iz*ns] = a1[iz-1,1]./g1';
iz = iz+1;
endo;``````

That `endo` at the end needs to be replaced with an `endif` statement, like this:

``````    if larch == 1; @ Correct heta for leverage effects if desired @
heta[.,2] = heta[.,2]
+ (l1/a1[1,1])*
((resid[nk-1:nk-1+captst-1,1] . ps+1;
hsig[iz,(iz-1)*ns+1:iz*ns] = a1[iz-1,1]./g1';
iz = iz+1;
endif;``````

`endo` is for ending `do while` loops. `if` statements need to end with `endif`.

0

this is another file nother file that came with this code that defines resid. What is the solusion?

``````proc echoo(th); @ proc to echo starting values @;

alpha0 = th[1,1];
spar = 2;
if pphi > 0;
phi = th[2:2+pphi-1,1];
spar = spar+1;
else;
phi = 0;
endif;
"Constant term in regression";;  alpha0;
"Autoregressive coefficients in regression";; phi';
a0 = abs(th[spar,1]);
a1 = abs(th[spar+1:spar+karch,1]);
spar = spar+1+karch;
b1=abs(th[spar:spar+garch-1,1]);
"Constant term in ARCH process";;a0;
"Coefficients on lagged epsilon squared in ARCH process";;a1';
"Constant term in GARCH process";;b1';
spar=spar+garch;
pm = matpm(th[spar:spar+(ns*(ns-1))-1-irs,1]);
"(Transposed) matrix of transition probabilities";;pm;"";
"The state with no adjustment to ARCH process is state 1, with transition";
"probability ";;pm[1,1];
spar = spar+(ns*(ns-1))-irs;
g1 = abs(th[spar:spar+ns-2,1]);
"Vector of variance factors for states 2 through";;ns;;g1';
spar = spar+ns-1;

if larch == 1;
l1 = abs(th[spar,1]);
"Coefficient on negative lagged change for asymmetric effect";;l1;
spar = spar+1;
endif;
if tarch == 1;
nu = 2 + abs(th[spar,1]);
"degree of freedom for t distribution is";; nu;
spar = spar + 1;
endif;

retp(a0);
endp;

/* ================================================================ */
@ This section calls main programs @

hp = pattern1;
#include procs.txt;
x = startval;

@ The following lines are for convenience of analysis and should be removed
for final calculations
izz = 2;
kc = 2;
ks = 2; @

call echoo(x);
"";"Initial values:";; x';
"Initial value for negative log likelihood:";; ofn(x);

"";"Do you wish to continue (y or n)?";;
zzs = cons;
if zzs .\$== "n";
end;
endif;

@  goto jump; @

/* ==================================================================== */
@ Set parameters to use Gauss numerical optimizer @

library optmum.lcg;
#include optmum.ext;
__btol = 1.e-03; @ This controls convergence criterion for [email protected]
__opgtol = 1.e-03; @ This controls convergence criterion for gradient @
__opalgr = 2;     @ This chooses BFGS optimization  @
__opstep = 3;
__opmiter = 500;  @ This controls the maximum number of iterations @
__output = 2;   @ This causes extra output to be displayed @
__covp = 1;     @ This speeds up return from OPTMUM @

@ Next call  the GAUSS numerical optimizer @
output file=junk.out off;
output file=junk reset;

{x,f,g,h} =optmum(&ofn,startval);
output file=junk off;
output file=junk.out on;

"";"";"======================================================";
"          FINAL ESTIMATES";
"";"Value of log likelihood:";;-f;
"";"Coefficients:";x';"";
call echoo(x);
vg=hessp(&ofn,x);
{va,ve} = eigrs2(vg);
va = sortc(va~ve',1);
if va[1,1] > 0;
"Standard errors:";
h=invpd(vg);
hh=sqrt(diag(h));
hh';
else;
"Hessian not positive definite; eigenvalues are";
va[.,1]';
"eigenvector associated with smallest eigenvalue is";
va[1,.];
endif;

/* ======================================================================= */
@ Print out complete analysis @
jump:

kc = 2;
ks = 2;
call ofn(x);
nxx = captst; @ Use nxx = captst for full output @
output file=junk.out off;
output file=junk.fil reset;
"Probabilities for primitive states";

"filtered probabilities";format /rd 1,0;
"Obs ";;"return  ";;
t = 0;
do until t > ps;
i = 1;
do until i == ns;
"P(st-";;t;;"=";;i;;") ";;
i = i+1;
endo;
t = t+1;
endo;"";
format /rd 6,4;
skif = (skif*hp')*(eye(ps+1).*.id[.,1:ns-1]);
skif =  seqa(nk,1,captst)~y[nk:capt,1]~skif;
skif[1:nxx,.];
output file=junk.fil off;

output file=junk.smo reset;

"";"smoothed probabilities";
format /rd 1,0;
"Obs ";;"return ";;
i = 1;
do until i > ns;
"P(st = ";;i;;") ";;
i = i+1;
endo;
format /rd 6,8;
skis = skis*hp';
skis = seqa(nk,1,captst)~y[nk:capt,1]~skis[.,1:ns];
skis[1:nxx,.];
output file=junk.smo off;

output file=junk.var reset;
"";"   Obs   Residual  Variance  Prob of observing larger value";
outprob = 1 - outprob;
iitlow = 0;
iithigh = 0;
it = 1;
do until it >  nxx;
nk+it-1;;"   ";;resid[nk+it-1,1];;"   ";;varfor[nk+it-1,1];;"   ";;
if outprob[it+nk-1,1] > 0.975;
outprob[it+nk-1,1];;"  *";
iitlow = iitlow+1;
elseif outprob[it+nk-1,1] 1.96*varfor.^0.5)/rows(resid);
cls;

@____________________________ Informations criteria [email protected]
print "Verossimilhanco=" -f;
print "AIC=" 2*f/(capt-nk)+2*rows(x)/(capt-nk);
print "BIC=" 2*f/(capt-nk)+rows(x)*ln(capt-nk)/(capt-nk);

@___________________________ Q statistics [email protected]
print;
print "Q(1){stdres}=" Qstat(resid./vasfor^0.5,1);
print "Q(6){stdres}=" Qstat(resid./vasfor^0.5,5);
print "Q(12){stdres}=" Qstat(resid./vasfor^0.5,10);
print "Q(1){stdres}=" Qstat((resid./vasfor^0.5)^2,1);
print "Q(5){stdres}=" Qstat((resid./vasfor^0.5)^2,5);
print "Q(10){stdres}=" Qstat((resid./vasfor^0.5)^2,10);
print;
wait;

@___________________________ Loss Function [email protected]
print "MSE=" sumc((resid.^2-varfor).^2)/rows(resid);
print "MAE=" sumc(abs(resid.^2-varfor))/rows(resid);
print "LE2=" sumc(ln(resid.^2)-ln(varfor)).^2)/rows(resid);
print "|LE|=" sumc(abs(ln(resid.^2)-ln(varfor)))/rows(resid);
print "freq.rejeicao=" freq;
x';

/*
@___________________________ Residuals analysis [email protected]
print "Standardised residuals analysis";
yxx = resid./varfor^0.5;            /*standardised residuals*/
n = rows(yxx);
print "";
"Average =                                    " meanc(yxx); /*residual average*/
"Stadard error =                              " stdc(yxx);  /*standard error*/
vyx =((yxx-meanc(yxx))'*(yxx-,eanc(yxx)));
sk = (ones(n,1)'*(yxx-meanc(yxx))^3)/n;
sk=sk/((vyx/n)^1.5);
"Skewness =                                   ";; sk;       /*skewness*/
ek = (ones(n,1)'*(yxx-meanc(yxx))^4)/n;
ek=(ek/((vyx/n)^2));
"Kurtosis =                                   ";; ek;       /*kurtosis*/
nt=(n/6)*(sk^2+.25*(ek-3)^2);                   /*Jarque-Bera test*/
"Normality Test-Jarque-Bera(1980)            =";;nt;
"Jarque-Bera's p-value =                      ";;cdfchic(nt,2);
*/
output file=junk.out off;
end;``````

0

I am seeing more problems in this code. Where did you get the code from?

0

One of the people who ever estimate the model msgarch with gauss. Where are the happened a problem? can you tell me or  help me solve the problem?

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.