Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: re: speed up mkmat


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: speed up mkmat
Date   Sun, 6 Feb 2005 13:39:44 -0500

Elisabeth indicated difficulties with mkmat, and Nick responded

"For each call to -mkmat- there is a

(1) -preserve- of your data

and a

(2) double loop over your variables and your
observations filling in the matrix element by
element

To avoid the problem (0) you might write
an alternative to -mkmat- as C code and make
it a plug-in.

To minimise the problem (1) you could check
to see that you are not working with a
relatively small subset of a relatively
large dataset, because otherwise the
-preserve- will be relatively expensive. "

I don't think that there is any good reason for a preserve in this context; I believe it can be replaced with a sort (which of course is not costless, but probably less burdensome than copying the whole data set). Here is a version of mkmat that with cursory testing produces the same result as official mkmat, but appears to reduce the time by at least 1/3 or so (tested on 74000 observations). If called per observation, getting rid of those preserve/restores should save quite a bit more.

To try out this version,
copy http://fmwww.bc.edu/ec-p/baum/mkmat2.ado ~/desktop/mkmat2.ado

(for the second argument substitute a location on your hard disk) and use mkmat2 rather than mkmat.

Caveat executor!
Kit

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index