Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Mata looping question
From
Anna Reimondos <[email protected]>
To
[email protected]
Subject
st: Mata looping question
Date
Tue, 18 Oct 2011 20:37:50 +1100
Hello,
I am just starting to try and learn how to use mata and have a
question about a simple loop command.
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.
matrix b = J(4,3,0)
forvalues i = 1/4 {
local x=`i'+1
forvalues j = 1/3 {
local y=`j'+1
matrix b[`i',`j']= a[`x',`y']
}
}
matrix list b
I have tried reading a lot of tutorials about using mata but am still
confused about how I would go about doing this in mata
Any advice that would help me along my way would be much appreciated,
Thanks
Anna
*
* 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/