I have posted a revised version of mkmat2.ado in the same site,
following some improvements suggested by Nick Cox. I have run the
following program for various n to determine how these two versions of
mkmat behave as n increases.
local x 25
sysuse auto,clear
expand `x'
mat b = J(3,3,0)
mat bb = J(3,3,0)
count
local nobs = r(N)
forv i=1/`nobs' {
mkmat price mpg rep78 if _n==`i', mat(a)
mat a = a'*a
mat b = nullmat(b)+a
}
forv i=1/`nobs' {
mkmat2 price mpg rep78 if _n==`i', mat(aa)
mat aa = aa'*aa
mat bb = nullmat(bb)+aa
}
But a graph of the mkmat and mkmat2 series against n show something
very similar to parallel lines as n increases, with mkmat2 maintaining
a similar advantage in terms of elapsed time (about 14 sec. for the
larger sample sizes).