Statalist


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

RE: Rephrase of earlier post: how might one calculate such things as cross-product matrices without storing Xs as matrices?


From   Roy Wada <[email protected]>
To   <[email protected]>
Subject   RE: Rephrase of earlier post: how might one calculate such things as cross-product matrices without storing Xs as matrices?
Date   Mon, 12 Jan 2009 17:54:56 -0800

>In a previous post, I had asked how matrix accum works. Nick Cox 
>replied that it was a very clever algorithm proprietary to Stata. 
>Stata's awesome :)
>
>Maybe I should rephrase my question. How might one go about calculating 
>such things as cross-product matrices without swamping memory by storing 
>entire lists of independent variables as matrices?

Why not use -matrix accum- for that?
 
If you are asking to do it by hand, then you need to take the sum of 
the product of two variables (or with itself or with ones). You can 
use -sum( )- function for that. It comes with an exceptionally high 
degree of precision, which leads me to believe this is one of the 
purposes for which this ugly-duckling was designed for. Most people 
don't use it much, briefly becoming undocumented when a 
similar-sounding option became popular.
 
My guess is that it or its cousin is responsible for making fast and 
precise computations of OLS-type estimators possible. Wrapping this 
function into a null mat, you should be able to reproduce the results 
of -matrix accum- almost as fast. It produces a running sum, so you 
will need to collect the results from the bottom row.
 
You can alternatively take the product of two variables and use -sum- 
command to get the mean and the number of observation. Multiply them
together, and you again get the sum of the product of two variables.
 
Roy
 
_________________________________________________________________
Windows Live™ Hotmail®: Chat. Store. Share. Do more with mail. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t1_hm_justgotbetter_howitworks_012009
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index