Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Re: cross-products in Mata


From   Edwin Leuven <edwin.leuven@ensae.fr>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: cross-products in Mata
Date   Tue, 7 Jul 2009 18:16:50 +0200

Kit wrote:
> This brings about a 20% speed improvement:
> mata:
> XW = X*W
> xwx2 = J(st_nobs(), 1, .)
> for (i=1; i<=st_nobs(); i++) {
>    xwx2[i] = XW[i,.] * X[i,.]'
> }
> end

hi kit,

i can invert W, so in the end using similar logic the following one-liner

xwx = rowsum((X*cholesky(W)):^2)

is more than twice as fast as my initial solution

the only disadvantage (apparently also with the rowsum solution) is that it involves a copy of the data area which can become a problem with big datasets

thanks for the help!

regards, edwin

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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