I am running a large number of simulations. Below is a snippet of my code. The following code works but is not efficient as a result of the do loop. Can the QUAD function be vectorized for better efficiency?
Regards,
Raphael
/* Incomplete Gamma Function */
start IGF(a,b);
return( b#gamma(a)#CDF('GAMMA', 1, a, 1/b) );
finish IGF;
/* Derivative of the Incomplete Gamma Function w.r.t. aa */
start DIGF(x) global(aa,bb);
return( log(x)#x##(aa - 1/2)#exp(-x#bb/2) );
finish DIGF;
nu = 3;
seed = 123456;
c = j(15000, 1, seed);
w = 2*uniform(c);
evalnum = J(nrow(w),1); /* pre-allocate matrix */
limits = {0 1};
do k = 1 to nrow(w);
aa = nu; bb = w;
call quad(result, "DIGF", limits);
evalnum = result;
end;
evalden = IGF(nu + 1/2,w/2);
r = evalnum/evalden;