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: Re:Turn lower diagonal matrix


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Re:Turn lower diagonal matrix
Date   Thu, 1 Nov 2012 18:36:22 +0000

Sorry, but I think this question has been answered repeatedly by Scott
Merryman and myself; conversely, you are not responding to the points
we make.

Nick

On Thu, Nov 1, 2012 at 6:33 PM, Bianca B. <[email protected]> wrote:
> I transposed my original matrix without using mata:
>
>  matrix list S2
>
> S2[2,2]
>     var1  var2
> r1     0     .
> r2     1     0
>
>  mat S2t = S2'
>
> . matrix list S2t
>
> S2t[2,2]
>       r1  r2
> var1   0   1
> var2   .   0
>
> Is it possible to combine S2 and S2t for obtaining
>
>        r1  r2
> var1   0   1
> var2   1   0
>
> ?
>
>
>
> --- On Thu, 11/1/12, Nick Cox <[email protected]> wrote:
>
>> From: Nick Cox <[email protected]>
>> Subject: Re: st: Re: Stata matrix to Mata matrix form - Turn lower diagonal matrix
>> To: [email protected]
>> Date: Thursday, November 1, 2012, 11:05 AM
>> Then the missing . should have
>> carried over to Mata and should have
>> been displayed, which is not visible in your previous
>> report. More
>> importantly, -makesymmetric()- works:
>>
>> . mat li S2
>>
>> S2[2,2]
>>     c1  c2
>> r1   0   .
>> r2   1   0
>>
>> . mata
>> ------------------------------------------------- mata (type
>> end to
>> exit) --------------------------------------------
>> : S2 = st_matrix("S2")
>>
>> : S2
>>        1   2
>>     +---------+
>>   1 |  0   .  |
>>   2 |  1   0  |
>>     +---------+
>>
>> : makesymmetric(S2)
>> [symmetric]
>>        1   2
>>     +---------+
>>   1 |  0      |
>>   2 |  1   0  |
>>     +---------+
>>
>> :
>> What you may be missing is that -makesymmetric()- shows the
>> result of
>> making a matrix symmetric; it does not itself change the
>> argument.
>> That can be done by assignment or by using
>> -_makesymmetric()-
>>
>> : _makesymmetric(S2)
>>
>> : S2
>> [symmetric]
>>        1   2
>>     +---------+
>>   1 |  0      |
>>   2 |  1   0  |
>>     +---------+
>>
>>
>>
>> On Thu, Nov 1, 2012 at 5:57 PM, Bianca B. <[email protected]>
>> wrote:
>> > The elements in row 1 are 0 and . (i.e. missing value),
>> in row 2 1 and 0.
>> > Then I converted my original stata matrix into mata.
>> >
>> >
>> >
>> > --- On Thu, 11/1/12, Nick Cox <[email protected]>
>> wrote:
>> >
>> >> From: Nick Cox <[email protected]>
>> >> Subject: Re: st: Re: Stata matrix to Mata matrix
>> form - Turn lower diagonal matrix
>> >> To: [email protected]
>> >> Date: Thursday, November 1, 2012, 10:11 AM
>> >> I mean what is the element in row 1
>> >> and column 2 of your matrix?
>> >>
>> >> mat_s2[1,2]
>> >>
>> >> will display it in Mata.
>> >>
>> >> I may be missing something important, but I don't
>> understand
>> >> how your
>> >> matrix can display like that unless it is
>> symmetric.
>> >>
>> >> Nick
>> >>
>> >> On Thu, Nov 1, 2012 at 4:46 PM, Bianca B. <[email protected]>
>> >> wrote:
>> >>
>> >> > mat_S2[1,2] is the name of the matrix.
>> >> >
>> >> >   mat_S2
>> >> >
>> >> >    1   2
>> >> >    +---------+
>> >> >  1 |  0      |
>> >> >    |  1   0
>> >> >    |
>> >> >> >+---------+
>> >> > I found this old post
>> >> > http://www.stata.com/statalist/archive/2007-02/msg00156.html
>> >> >
>> >> > where there is exactly my same question that
>> is to turn
>> >> my lower-triangular matrix, named mat_S2, into a
>> symmetrical
>> >> matrix by reflecting the lower triangular elements
>> across
>> >> the diagonal.
>> >> >
>> >> > I tried to use mata makesymmetric function but
>> I do not
>> >> obtain the matrix I wish and that I report below
>> >> >
>> >> >
>> 1   2
>> >> >       +---------+
>> >> >     1 |
>> >> 0   1  |
>> >> >     2 |
>> >> 1   0  |
>> >> >       +---------+
>> >> >
>> >> >
>> >> >
>> >> > --- On Thu, 11/1/12, Nick Cox <[email protected]>
>> >> wrote:
>> >> >
>> >> >> From: Nick Cox <[email protected]>
>> >> >> Subject: Re: st: Re: Stata matrix to Mata
>> matrix
>> >> form
>> >> >> To: [email protected]
>> >> >> Date: Thursday, November 1, 2012, 9:34 AM
>> >> >> You've lost me. What is mat_S2[1,2]?
>> >> >>
>> >> >> Nick
>> >> >>
>> >> >> On Thu, Nov 1, 2012 at 3:39 PM, Bianca B.
>> <[email protected]>
>> >> >> 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 <[email protected]>
>> >> >> wrote:
>> >> >> >
>> >> >> >> From: Nick Cox <[email protected]>
>> >> >> >> Subject: Re: st: Re: Stata matrix
>> to Mata
>> >> matrix
>> >> >> form
>> >> >> >> To: [email protected]
>> >> >> >> 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.
>> >> <[email protected]>
>> >> >> >> 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. <[email protected]>
>> >> >> >> wrote:
>> >> >> >> >
>> >> >> >> >> From: Bianca B. <[email protected]>
>> >> >> >> >> Subject: Stata matrix to
>> Mata
>> >> matrix form
>> >> >> >> >> To: [email protected]
>> >> >> >> >> 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/
>>
>
> *
> *   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/
*
*   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