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

st: re: speed up mkmat

From   Kit Baum <>
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

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 ~/desktop/mkmat2.ado

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

Caveat executor!

Kit Baum, Boston College Economics

* For searches and help try:

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