Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: summing across matrices created with a loop

From   "Schmidt, Nicole" <>
To   "" <>
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 
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:
Any advice on how to do this in stata?

*   For searches and help try:

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