Hi, the codes have been fixed!! Thanks so much! The modified codes are as follows: proc iml; start LL(param); f=shape(param[1:9],3,3); q=shape(param[10:18],3,3); r=param[19]; mu=shape(param[20:22],3,1); beta_current=shape(param[23:25],3,1); p_current=shape(param[26:34],3,3); use origin; read all var{time} into time; read all var{y} into y; read all var{x1,x2,x3} into x; LL=0; do i=1 to 405; idx=loc(time=i); y_t=y[idx,]; x_t=x[idx,]; beta_pred=mu+f*beta_current; p_pred=f*p_current*f`+q; aita_pred=y_t-x_t*beta_pred; f_pred=x_t*p_pred*(x_t)`+r; k=p_pred*(x_t)`*inv(f_pred); beta_current=beta_pred+k*aita_pred; p_current=p_pred-k*x_t*p_pred; if f_pred<=0 then LL=.; else LL=LL-(1/2)*log(2*3.14*f_pred)-(1/2)*(aita_pred)`*inv(f_pred)*aita_pred; end; return(LL); finish; con_f_1=j(1,9,-0.95); con_q_1=j(1,9,0); con_r_1=j(1,1,0); con_mu_1=j(1,3,.); con_beta_1=j(1,3,.); con_p_1=j(1,9,0); con_f_2=j(1,9,0.95); con_q_2=j(1,9,.); con_r_2=j(1,1,.); con_mu_2=j(1,3,.); con_beta_2=j(1,3,.); con_p_2=j(1,9,.); con_1=con_f_1||con_q_1||con_r_1||con_mu_1||con_beta_1||con_p_1; con_2=con_f_2||con_q_2||con_r_2||con_mu_2||con_beta_2||con_p_2; con=con_1//con_2; initial=j(1,34,0.1); opt={1,2}; call nlpnra(rc,result,"LL",initial,opt,con); quit; Here I set the constraints to some parameters. The whole program only runs 4 minutes! Much much faster~~ In the future I'll try to avoid the mixture of MACRO and IML~~~And use the LOC function as the index, rather than the macro variable. Thanks so much~~
... View more