Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: mata: why this loop is so slow


From   "U.A.QU.AP" <uaquap@gnet.tn>
To   statalist@hsphsun2.harvard.edu
Subject   st: mata: why this loop is so slow
Date   Mon, 29 May 2006 18:50:54 +0100 (CET)

I've written this portion of code (see below) and it works
perfectly the problem is the execution time which is about 15
mn. Under SAS (IML) my co-author code the same thing and the
execution time is 1 (one) minute on 35900 observations. is
there a problem with my programmation Style?
AbdelRahmen
*--------begin mata code
w = st_data(., tokens(st_local("instrume")))	// matrix
q = st_data(., tokens(st_local("vprobit")))	// matrix
dmills=st_data(., "dmills")                   // colvector
s=st_data(., "selection")                 // colvector
t=st_data(., "t")                     // colvector
chw=cols(w)                        // scalar
cq=cols(q)                        // scalar
for (i=1; i<=nt; i++) {
jacobi=J(chw, (cq*T) ,0)
jacobi[(chw - T + t[i]),(cq*t[i] -cq
+1)..cq*t[i]]=q[i,.]:*dmills[i,.]
F=F+(s[i,.]:*h[i,.]')*beta'*jacobi
}
F=(1/n)*F
*--------end mata code
*--------begin SAS IML code
dmills=-mill1#(qpi+mill1)#q;
do i=1 to N;   
 jacobi=j(chw,cq#T,0);
 period=t[i];
 jacobi[chw-T+period,cq#(period-1)+1:cq#period]=dmills[i,];  
 F=F+h[i,]`*(beta`*jacobi);
 F=(F/N)
*--------end SAS IIML code
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index