Bookmark and Share

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: summing across matrices created with a loop


From   "Schmidt, Nicole" <n.schmidt@neu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: summing across matrices created with a loop
Date   Wed, 19 Feb 2014 02:48:16 +0000

Hi there,
 
I am using stata to create a pxp matrix for each individual in my 
data set using a loop, and now I want to sum all matrices together. For 
example:
 
forval i=1/`N' {;

  

/* Create a matrix for subject `i' containing value of '1', exposure, and covariates */
mkmat constant `exp' `covs' if obs==`i', matrix(A`i');
matrix list A`i';
/* Transpose matrix */
matrix B`i'=A`i'';
matrix list B`i';
/* Multiplying column matrix B * it's transpose * weight */
matrix C`i'=B`i'*A`i'*W`i';
matrix list C`i';
};
 
Now I want to add all C`i' together to create a pxp matrix that is 
the sum of the C matrix across all individuals in the data. I saw a 
thread about this back in 2007, but it was a suggestion for how to do 
this in mata:

http://www.stata.com/statalist/archive/2007-08/msg00944.html
 
Any advice on how to do this in stata?
 
Thanks,
Nicole


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index