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]

Re: st: matrix subscripting using loop


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: matrix subscripting using loop
Date   Wed, 15 Sep 2010 09:19:26 -0500

On Wed, Sep 15, 2010 at 8:27 AM, Maarten buis <maartenbuis@yahoo.co.uk> wrote:
> --- On Wed, 15/9/10, Thomas wrote:
>> I would like to turn a 1 X 49 matrix
>> into a 7 X 7 matrix using a loop.
>
> Have you tried to use the rowshape()
> in Mata?
>

Here is one way to use a loop:

mata
 a = (1..49)'
 for (i=1; i<=7; i++) {
	b[1::7,i] = a[7*i-6::7*i,1]
 }
b
end


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