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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: use mata loop to generate matrix


From   Zhi Su <su.zh@husky.neu.edu>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: use mata loop to generate matrix
Date   Fri, 20 May 2011 16:02:40 -0400

I want to construct a simulated Y mean matrix that is a 667x4 matrix.
XB is drawn from a dataset with 667 observations and four variables
"xbm1", "xbm2", "xbm3","xbm4" . U is drawn from 4 normal distribution
with a variance-covariance V.The draw is repeated 1000 times.  Here is
what I do

/*number of repetions*/
N=1000

/*Multiple draws from multivariate normal distribution with variance
and covariance V */
U=(invnormal(uniform(N,cols(V)))*cholesky(V)')

for(k=1;k<=667;k++) {

XB=st_data(k,("xbm1", "xbm2", "xbm3","xbm4"))

Y_si=XBM:+U

M_u=mean(Y_si)
}

I can get means of each simulated Y by looping the process from 1 to
667.  But I do not know how to put the mean row vectors into a 667X 4
matrix.
Anyone can give me some suggestions?
Thanks!
-- 
Zhi Su
348 Holmes Hall
Northeastern University
360 Huntington Avenue
Boston, MA 02115
Office:1-617-373-2316
email:su.zh@husky.neu.edu
*
*   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