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: Re: Stata matrix to Mata matrix form


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Re: Stata matrix to Mata matrix form
Date   Thu, 1 Nov 2012 16:34:49 +0000

You've lost me. What is mat_S2[1,2]?

Nick

On Thu, Nov 1, 2012 at 3:39 PM, Bianca B. <bianca268@yahoo.com> wrote:
> Nick, you're right, I'm sorry. I didn't specify that I need to turn my lower-triangular matrix into a symmetrical matrix by reflecting the lower triangular elements across the diagonal. So starting from this matrix
>
> mat_S2
>
>         1   2
>      +---------+
>    1 |  0      |
>    2 |  1   0
>      |
>      +---------+
>  I'd like to obtain a matrix like that
>
>         1   2
>      +---------+
>    1 |  0   1  |
>    2 |  1   0  |
>      +---------+
>
>
>
>
> --- On Thu, 11/1/12, Nick Cox <njcoxstata@gmail.com> wrote:
>
>> From: Nick Cox <njcoxstata@gmail.com>
>> Subject: Re: st: Re: Stata matrix to Mata matrix form
>> To: statalist@hsphsun2.harvard.edu
>> Date: Thursday, November 1, 2012, 8:29 AM
>> Looks symmetric to me.
>>
>> If a matrix is symmetric, Stata says so, and only displays
>> the lower
>> half (including the principal diagonal).
>>
>> In your case, Stata is doing exactly that.
>>
>> Here is another example:
>>
>> . mata : I(3)
>> [symmetric]
>>
>>    1   2   3
>>     +-------------+
>>   1 |  1          |
>>   2 |  0   1      |
>>   3 |
>> 0   0   1  |
>>     +-------------+
>>
>> If this is not what you mean, you'll have to explain what
>> "doesn't
>> work" means exactly.
>>
>> Nick
>>
>> On Thu, Nov 1, 2012 at 3:16 PM, Bianca B. <bianca268@yahoo.com>
>> wrote:
>> > Dear Nick,
>> >
>> > Thanks a lot. I converted a lower-triangular matrix
>> from stata to mata form to apply the mata makesymmetric
>> command but it doesn't work.
>> > The command is
>> >
>> > : makesymmetric(mat_S2)
>> > [symmetric]
>> >        1   2
>> >     +---------+
>> >   1 |  0      |
>> >   2 |  1   0
>> |
>> >     +---------+
>> >
>> > Would you have any suggestion?
>> > Best,
>> > Bianca
>> >
>> >
>> >
>> > . mat foo = J(6,7,42)
>> >
>> > . mat li foo
>> >
>> > foo[6,7]
>> >     c1  c2  c3
>> c4  c5  c6  c7
>> > r1  42  42  42  42  42
>> 42  42
>> > r2  42  42  42  42  42
>> 42  42
>> > r3  42  42  42  42  42
>> 42  42
>> > r4  42  42  42  42  42
>> 42  42
>> > r5  42  42  42  42  42
>> 42  42
>> > r6  42  42  42  42  42
>> 42  42
>> >
>> > . mata : mat_foo = st_matrix("foo")
>> >
>> > . mata : mat_foo
>> >         1
>> 2    3    4    5
>> 6    7
>> >
>>    +------------------------------------+
>> >   1 |
>> 42   42   42   42   42   42   42
>> |
>> >   2 |
>> 42   42   42   42   42   42   42
>> |
>> >   3 |
>> 42   42   42   42   42   42   42
>> |
>> >   4 |
>> 42   42   42   42   42   42   42
>> |
>> >   5 |
>> 42   42   42   42   42   42   42
>> |
>> >   6 |
>> 42   42   42   42   42   42   42
>> |
>> >
>>    +------------------------------------+
>> >
>> > . mata : st_matrix("foo", mat_foo :/ 7)
>> >
>> > . mat li foo
>> >
>> > foo[6,7]
>> >     c1  c2  c3
>> c4  c5  c6  c7
>> >
>> r1   6   6   6   6   6   6   6
>> >
>> r2   6   6   6   6   6   6   6
>> >
>> r3   6   6   6   6   6   6   6
>> >
>> r4   6   6   6   6   6   6   6
>> >
>> r5   6   6   6   6   6   6   6
>> >
>> r6   6   6   6   6   6   6   6
>> >
>> > --- On Thu, 11/1/12, Bianca B. <bianca268@yahoo.com>
>> wrote:
>> >
>> >> From: Bianca B. <bianca268@yahoo.com>
>> >> Subject: Stata matrix to Mata matrix form
>> >> To: statalist@hsphsun2.harvard.edu
>> >> Date: Thursday, November 1, 2012, 7:25 AM
>> >> Hi Stata users,
>> >>
>> >> Does anyone know how can I get stata matrix in mata
>> matrix?
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index