Hello,
The following code crashes Stata silently and I cannot figure out why. If I replace w with a simple vector, the code executes with no problems, including the loop. But when I try to optimize, it almost instantly crashes in Stata 16.1 and Stata 17 with a Windows 10 machine. Any help would be appreciated.
The following code crashes Stata silently and I cannot figure out why. If I replace w with a simple vector, the code executes with no problems, including the loop. But when I try to optimize, it almost instantly crashes in Stata 16.1 and Stata 17 with a Windows 10 machine. Any help would be appreciated.
Code:
mata void function solver(todo, w, lnf, retailmargin, H) { omega_p=ownership_p*Delta_p g=(ownership_v:*Delta_p')*w' retailmargin=-pinv(omega_p)*(ex_shares+g) D=J($models, $models, .) secondterm=J($models, $models, 0) fourthterm=J($models, $models, 0) thirdterm=J($models, $models, 0) for (j = 1; j <= $models; j++){ for (k=1; k<=$models; k++){ for (i=1; i <= $models; i++){ secondterm[j,k]=secondterm[j,k]+ownership_p[i,j]*asarray(secder, i)[j,k]*retailmargin[i,1] fourthterm[j,k]=fourthterm[j,k]+ownership_v[i,j]*asarray(secder, i)[j,k]*w[1,i] } thirdterm[j,k]=ownership_p[k,j]*ex_shares_jacobian[k,j] D[j,k]=Delta_p[j,k]+secondterm[j,k]+thirdterm[j,k]+fourthterm[j,k] } } Delta_pw=pinv(D)*(Delta_ow*Delta_p)' Delta_w=Delta_p*Delta_pw h=(ownership_v':*Delta_w')*retailmargin+(ownership _v':*Delta_pw')*ex_shares s_term=ex_shares+h omega_w=ownership_w:*Delta_w lnf1 = w' + pinv(omega_w)*s_term lnf=lnf1:^2 } M=optimize_init() optimize_init_evaluator(M, &solver()) optimize_init_evaluatortype(M, "gf0") optimize_init_params(M, starting) optimize_init_which(M, "min") optimize_init_conv_ptol(M, 1e-6) optimize_init_conv_vtol(M, 1e-6) optimize_init_tracelevel(M,"value") optimize_init_conv_maxiter(M, 10) w=optimize(M) qui: optimize_result_V_oim(M) end
Comment