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: matrix subscripting using loop


From   Thomas <tpt21@cam.ac.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: matrix subscripting using loop
Date   Wed, 15 Sep 2010 13:34:10 +0100

I would like to turn a 1 X 49 matrix into a 7 X 7 matrix using a loop.

I tried the following:

mat evi = J(7,7,0)

            forvalues r = 1(1)7{
                forvalues i = 1(7)43{
                    forvalues j = 7(7)49{

                        matrix evi[`r',1] = evimat[1,`i'..`j']
            }
            }
            }

it does not seem to work because it first loops over the first set of forvalues, then the second, etc.

But what I need is for it to loop over all three forvalue statements "at the same time". Any idea how to do this?

Then there might a an altogether different way of doing this...

Many thanks,

Thomas
*
*   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