Statalist


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

st: How can I loop a FOR command across columns of a matrix


From   Nathan Danneman <ndanneman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: How can I loop a FOR command across columns of a matrix
Date   Thu, 4 Jun 2009 22:44:06 -0400

Hello,

I have a 2 x N matrix, such as the following...

2  3  5  10  6
1  2  8  13  6

I would like to write a loop, such as foreach or forvalues, that will
take the first and second element of each column, and use them for
some operation, and then move on to subsequent columns.

For examle,

foreach column i...
multiply row a times row b.

Such that the above matrix would be turned into the vector

2 6 40 130 36.

Is there a straightforward way to accomplish this without using Mata?

Thanks,
Nathan

-- 
"Imagination is more important than knowledge..."
      -- Albert Einstein
*
*   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   |   What's new   |   Site index