Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: use mata loop to generate matrix
From
Zhi Su <[email protected]>
To
statalist <[email protected]>
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:[email protected]
*
* 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/