Do not know how to modify the code

library maxlik;
#include maxlik.ext;
a0=0.4;
a1=0.5;
a2=0.3;
T=1000;
{da}=garch_sample(a0,a1,a2,T);
var=vcx(da);
u=(da-meanc(da))^2;
maxset;
_max_active = {1,1,1};
_max_gradtol = 1e-5;
_max_algorithm = 5;
_max_linesearch = 5;
_max_maxiters = 100;
_max_maxtry = 5;
_max_randradious = 1e-3;
_max_covpar = 3;
__output = 1;
iv = 0.001|0.97|0.02;

{est,fmax,grad,cov,retcode}=maxlik(u,1,&lr,iv);
/*==================================================*/
proc lr(miv,u);
LOCAL a0,a1,a2,h,t,ll ;
a0 = miv[1];
a1 = miv[2];
a2 = miv[3];
if a0.<=0;
ll = -1000000;
goto skip;
endif;
if a1.<0;
ll=-1000000;
goto skip;
endif;
if a2.1;
ll = -1000000;
goto skip;
endif;
h = zeros(rows(u),1);
h[1] = a0+(a1 + a2)*var;
t=2;
do until t>rows(u);
h[t]=a0+a1*h[t-1]+a2*u[t-1];
t=t+1;
endo;
ll = -0.5*ln(2* pi)-0.5*ln(h[2:rows(u)])-0.5*(u[2:rows(u)]./h[2:rows(u)]);
skip:
retp(ll);
endp;
/*==================================================*/
proc garch_sample(a0,a1,a2,T);
local nobs, et,ut,ht,utend;
nobs=ROUND(T^(1/2));
et=rndn(T+nobs,1);
ut=zeros(T+nobs,1);
ht=zeros(T+nobs,1);
ht[1]=a0/(1-a1-a2);

for i(2,T+nobs,1);
ht[i]=a0+a1*ht[i-1]+a2*ut[t-1]^2;
ut[i]=et[i-1]*ht[i-1]^(1/2);
endfor;
utend=ut[nobs+1:T+nobs];
retp(utend);
endp;

G0156 : Illegal redefinition of procedure 'u' [garch.gss, line 9]
G0155 : Nested procedure definition [garch.gss, line 57]
G0008 : Syntax error 'proc garch_sample(a0,a1,a2,T)' [garch.gss, line 57]

2 Answers



0



  1. The "illegal redefinition" error is probably coming from some other code you have recently run. Add a new statement as the VERY FIRST line of your program.
  2. I also found a programming mistake around line 38 of the code. There is a line with this content:
    if a2.1;
    

    based upon some of the code above, I think it should probably be this:

    if a2 .< 1;
    

Try making those changes and see if it will run for you.

aptech

1,773


0



thanks a lot!keep trying

Your Answer

2 Answers

0
  1. The "illegal redefinition" error is probably coming from some other code you have recently run. Add a new statement as the VERY FIRST line of your program.
  2. I also found a programming mistake around line 38 of the code. There is a line with this content:
    if a2.1;
    

    based upon some of the code above, I think it should probably be this:

    if a2 .< 1;
    

Try making those changes and see if it will run for you.

0

thanks a lot!keep trying


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.