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: mata matrix permutation


From   Christophe Kolodziejczyk <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: mata matrix permutation
Date   Mon, 17 Feb 2014 17:30:40 +0100

Dear Yoad

The following piece of code seems to do what you require.
Note the use of rowshape(), vec() and subscripting.
Best
Christophe


clear mata
mata:

 a = runiform(1,3000)
 r = range(1,3000,1)'

 // reshape r such that
 /* s =[1   , 2
        1001, 1002,
  2001, 2002,] */
 s = rowshape(r',3)
 s[,1..10]

 // vectorize and transpose s
 s = vec(s)'

 s[1,1::10]
 s[1,2990::3000]

 // rearrange matrix a
 b = a[1,s]


 // s

 // a\b


end

2014-02-17 3:48 GMT+01:00 yoad shefi <[email protected]>:
> I have a matrix in mata that has 3000 columns, but consists of 3
> distinct blocks (each with 1000 columns).
> I'm trying to change the order of the columns so that I get a
> consecutive set of columns one from each block - 1, 1001, 2001, 2,
> 1002, 2002, 3, 1003, 2003 ....., 999,1999,2999, 1000, 2000, 3000.
>
> Is there an easy way to do this in mata?
>
> any help would be appreciated,
>
> Thanks,
> Yoad
> *
> *   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/



-- 
Christophe Kolodziejczyk
Research Fellow

AKF, Anvendt KommunalForskning
Danish Institute of Governmental Research
Købmagergade 22
DK-1150 København K

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