Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

re: st: matrix operations when N exceeds matsize


From   Kit Baum <BAUM@BC.EDU>
To   statalist@hsphsun2.harvard.edu
Subject   re: st: matrix operations when N exceeds matsize
Date   Tue, 18 May 2010 16:35:48 -0400

<>
Re my last posting, to move Stata variables into Mata and get the resulting matrix back is straightforward (even with N = 120,000):

clear
set obs 120000
forv i=1/10 {
	g W`i' = runiform()
	g B`i' = runiform()
	loc wl "`wl' W`i'"
	loc bl "`bl' B`i'"
}
mata
st_view(W=., ., st_local("wl"))
st_view(B=., ., st_local("bl"))
vard = runiform(10,10)
result = W' * B * vard * B' * W
st_matrix("result", result)
end
mat list result

NB. I have about 500m allocated to Stata (which would work even on a 32-bit machine). The use of views in Mata avoids making a copy of those 120000 x 10 x 2 variables, which saves a great deal of memory.

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


*
*   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   |   Site index