Help me please, Error G0058: Index out of range [Modelo_1.gss, line 96]

Hello, hoping that each of you are very well, I need someone to help me with the following error (G0058: Index out of range [Modelo_1.gss, line 96], I have made a note on the line with the error.

Thank you very much already.


new;
format /m1 /ldn 16,6;

bigt=1057;
load data[bigt,5]= "Base_Modelo1.txt";
tc=data[.,1];
d=data[.,2];
pc=data[.,3];
pp=data[.,4];
spread=data[.,5];

pc_1=lag(pc);
pp_1=lag(pp);
tc_1=lag(tc);
spread_1=lag(spread);
d_1=lag(d);

dpc=ln(pc)-ln(pc_1);
dpp=ln(pp)-ln(pp_1);
dtc=ln(tc)-ln(tc_1);
dspread=(spread-spread_1);

dtc_1=lag(dtc);

@ Cointegration Regression @
xc=ones(bigt,1)~pc~pp~spread;
bc=inv(xc'xc)*xc'*tc;
uc=tc-xc*bc;
uc_1=lag(uc);

d_dpc=d.*dpc;
d_dpp=d.*dpp;
d_dspread=d.*dspread;
d_dtc_1=d.*dtc_1;
d_uc_1=d.*uc_1;

x=ones(bigt-2,1)~dpc[3:bigt]~dpp[3:bigt]~dspread[3:bigt]~uc_1[3:bigt]~dtc_1[3:bigt]
~d[3:bigt]~d_dpc[3:bigt]~d_dpp[3:bigt]~d_dspread[3:bigt]~d_uc_1[3:bigt]~d_dtc_1[3:bigt];
b=inv(x'x)*x'*dtc[3:bigt];
e=dtc[3:bigt]-x*b;
s2e=e'e/bigt;
sdb=sqrt(diag(s2e*inv(x'x)));
ttb=b ./ sdb;
pvb= 2*cdfnc(abs(ttb));

@ GARCH Estimation @
param0=ln(s2e)|ln(0.05)|ln(0.87)|ln(0.001)|ln(0.001)|ln(0.001);

e=zeros(2,1)|e;
h=ones(bigt,1)*s2e;

proc (1)= of_migarch(param);
local omega,alpha,beta,d0h,d1h,d2h,ln_lik,s_ln_lik;

omega=exp(param[1]);
alpha=exp(param[2]);
beta=exp(param[3]);
d0h=exp(param[4]);
d1h=exp(param[5]);
d2h=exp(param[6]);

for i(3,bigt,1);
h[i]=omega+alpha*(e[i-1]^2)+beta*h[i-1]+d0h*d[i]+d1h*(d[i]*(e[i-1]^2))+d2h*(d[i]*h[i-1]);
endfor;

ln_lik=-0.5*(ln(2*pi)+ln(h)+(e.^2)./h);
s_ln_lik=sumc(ln_lik);
retp(-s_ln_lik);

endp;

proc (1)= of_bigg(param);
local omega,alpha,beta,d0h,d1h,d2h,ln_lik;

omega=exp(param[1]);
alpha=exp(param[2]);
beta=exp(param[3]);
d0h=exp(param[4]);
d1h=exp(param[5]);
d2h=exp(param[6]);

for i(3,bigt,1);
h[i]=omega+alpha*(e[i-1]^2)+beta*h[i-1]+d0h*d[i]+d1h*(d[i]*(e[i-1]^2))+d2h*(d[i]*h[i-1]);
endfor;

ln_lik=-0.5*(ln(2*pi)+ln(h)+(e.^2)./h);
retp(-ln_lik);

endp;

_qn_RelGradTol=0.0001;

{ param,s_ln_lik,g,retcode } = QNewton(&of_migarch,param0);
coeff=exp(param[1:6]); // ***** ERROR ON THIS LINE *****
aic=(-2*-s_ln_lik+2*rows(param))/bigt;
bic=(-2*-s_ln_lik+ln(bigt)*rows(param))/bigt;

hm = hessp(&of_migarch,param);
gm= gradp(&of_bigg,param);
opg=gm'gm;
sd_h= sqrt(diag(inv(hm)));
sd_opg= sqrt(diag(inv(opg)));
sd_qml= sqrt(diag(inv(hm)*opg*inv(hm)));
sd= coeff[1:6].*sd_qml[1:6];
tt=coeff ./ sd;
pv= 2*cdfnc(abs(tt));
print;
b_names="C"|"DPC"|"DPP"|"DSPREAD"|"U(-1)"|"DTC(-1)"|"D"|"D*DPC"|"D*DPP"|"D*DSPREAD"|"D*U(-1)"|"D*DTC(-1)";
names="Coeff"~"Std.Dev"~"T-test"~"P-value";
print "MEAN EQUATION";
print b[1:12]~sdb[1:12]~ttb[1:12]~pvb[1:12];
print;
print "VARIANCE EQUATION";
print coeff[1:6]~sd[1:6]~tt[1:6]~pv[1:6];
print;
print "Log Lik:" -s_ln_lik;
print "BIC:" bic;
print "AIC:" aic;
print;

loss=((1+b[5])^2)*(uc_1.^2)+((0*dtc_1).^2)+h+2*(1+b[5])*uc_1.*(0*dtc_1);
d_loss=d.*loss;
s_loss=sortc(loss,1);

library pgraph;
graphset;

t=seqa(1,1,bigt-2);
interv=abs(d-d_1);

begwind;
window(2,2,0);
lab = "OCT99 OCT00 OCT01 OCT02 OCT03 OCT04 OCT05 OCT06 OCT07 OCT08 OCT09 OCT10 OCT11 OCT12 OCT13";
asclabel(lab,0);
xtics(1,bigt,52,11);
title("Expected Loss Function and Intervention Periods");
xlabel("Time");
ylabel("");
_plegctl=0;
_plegstr="Loss\000Intervention";
_pdate = "";
_pltype = { 6 6 3};
_plwidth = { 10 5 10};
xy(t,loss[3:bigt]~interv[3:bigt]*maxc(loss));
nextwind;
title("Nominal Exchange Rate");
xlabel("Time");
ylabel("");
_plegctl=0;
_plegstr="Nominal Exchange Rate\000Intervention";
_pdate = "";
_pltype = { 6 6};
_plwidth = { 10 5};
xy(t,tc[3:bigt]~interv[3:bigt]*maxc(tc));
nextwind;
title("Misalignment");
xlabel("Time");
ylabel("");
_plegctl=0;
_plegstr="Misalignment\000Intervention";
_pdate = "";
_pltype = { 6 6};
_plwidth = { 10 5};
xy(t,uc[3:bigt]~interv[3:bigt]*maxc(uc));
nextwind;
title("Volatility");
xlabel("Time");
ylabel("");
_plegctl=0;
_plegstr="Conditional Variance\000Intervention";
_pdate = "";
_pltype = { 6 6};
_plwidth = { 10 5};
xy(t,h[3:bigt]~interv[3:bigt]*maxc(h));
endwind;

@print "Expected Loss Function and Intervention Periods";
print t~loss[3:bigt]~interv[3:bigt]*maxc(loss);
print;
print "Nominal Exchange Rate";
print t~tc[3:bigt]~interv[3:bigt]*maxc(tc);
print;
print "Misalignment";
print t~uc[3:bigt]~interv[3:bigt]*maxc(uc);
print;
print "Volatility";
print t~h[3:bigt]~interv[3:bigt]*maxc(h);@

end;

1 Answer



0



The error G0058: Index out of range means that the code is trying to either assign or reference outside the bounds of the matrix or vector. For example:

// Create a 5x1 vector
parm = { 0, 9, 3, 4, 2 };

// Try to access the first 6 elements of a 5 element vector
x = parm[1:6];

aptech

1,773

Your Answer

1 Answer

0

The error G0058: Index out of range means that the code is trying to either assign or reference outside the bounds of the matrix or vector. For example:

// Create a 5x1 vector
parm = { 0, 9, 3, 4, 2 };

// Try to access the first 6 elements of a 5 element vector
x = parm[1:6];


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.