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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Mata looping question


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Mata looping question
Date   Tue, 18 Oct 2011 11:54:36 +0200

On Tue, Oct 18, 2011 at 11:37 AM, Anna Reimondos wrote:
> For example if I have one original matrix called 'a'
>
> matrix a=(1,0,0\0,2,1\0,1,0\0,0,0)
> matrix list a
>
> I then want to create another matrix 'b' which is equal to 'a' but
> where every element has been shifted up one row and across one column.

I would not do that with a loop:

*------------- begin example ----------------
mata
a=(1,0,0\0,2,1\0,1,0\0,0,0)
b = J(5,1,0), (a \ J(1,3,0))
b
end
*----------- end example ----------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany


http://www.maartenbuis.nl
--------------------------
*
*   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