Bookmark and Share

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]

RE: st: do loops and mata


From   <[email protected]>
To   <[email protected]>
Subject   RE: st: do loops and mata
Date   Thu, 13 Mar 2014 13:48:18 +0000

Dear Nick

Thanks for the quick response. The commands is indeed almost equivalent to vec (except I need to go from a 39X4 matrix to 39  2 by 2 matrices rather than a column vector ) but I still need a loop to extract the 39 separate matrices and label them differently

I can do this in the old matrix sequence using the commands

mkmat ee eu ue uu, matrix(P)
matrix list P

local i=1
while `i'<=rowsof(P) {
matrix P`i'= P[`i',1...]	/* loops to give 39 different 1 by 4 matrices of transition probabilities */
local i=`i'+1
}

matrix list P1
matrix list P39

but I was interested in doing the mata equivalent

thanks again

Jonathan Wadsworth


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 13 March 2014 12:49
To: [email protected]
Subject: Re: st: do loops and mata

This looks like a way of reinventing -stack-. Am I wrong?

Nick
[email protected]


On 13 March 2014 12:34,  <[email protected]> wrote:

> As a novice to mata I'm trying to generate a set of 39 matrices using 
> a loop - essentially extracting each row of a larger matrix P 
> sequentially and then transforming the vector into a matrix using the 
> rowshape command
>
> I've got as far as this - which does indeed scroll through a matrix P 
> 39 times and extract a row at a time and writes to a mtrix Pi, but 
> then it overwrites the matrix Pi each time so that I'm left with just 
> one matrix called Pi at the end of the loop instead of 39 matrics 
> called P1--P39
>
> Does anyone know how to adapt the code below to generate and store 39 different matrices named p1, p2, ..p39 ?

> mata
>
>
> P = st_data( ., ("ee", "eu" ,"ue", "uu") ) P
>
> for ( i=1; i<=rows(P) ;i++) {
>
> Pi= P[i,.]
> Pi
>
> xi=rowshape( Pi, 2)
> xi
>
> }
>
> end

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index