Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: -gen double- or -gen-


From   [email protected]
To   [email protected]
Subject   Re: st: -gen double- or -gen-
Date   Mon, 16 Mar 2009 22:43:58 -0400

Yes Glenn. I totally understand it now.

Jingjing



Quoting Glenn Goldsmith <[email protected]>:

Hi Jingjing,

Didn't we already do this the other day:
http://www.stata.com/statalist/archive/2009-03/msg00366.html?

I am wondering if -M= = st_matrix("M")- here make sure it is a *symmetric*
matrix with the elements h11 h21... that I just generated.

-st_matrix("M")- will return whatever is in your stata matrix M. If your
stata matrix M is symmetric, then it will return a symmetric matrix. If not,
then it won't. You've said that your stata matrix is Tx10, so that's what
you'll get.

But I don't think you want M to be symmetric anyway; you want mt to be
symmetric.

The expression

  mt = invvech(M[., t])

extracts the tth column of M and tries to turn it into a symmetric matrix.
But that won't work, because it's the *rows* of M that contain the h* values
you want to use.

  mt = invvech(M[t,.]')

should give you what you want (the transpose is necessary because
-invvech()- requires a colvector argument).

Alternatively, if you only want to transpose once, it may be slightly more
efficient to code:

  M = st_matrix("M")'

At the top of your routine, and leave the rest as is.

Best wishes,

Glenn.


[email protected] wrote:

Thanks Maarten,

I know what's "double" now.

And I have to corrected my expression in the previous email.

I first use -gen-...  to calculate the elements of matrix M.


Then -mkmat h*, mat(M)- creat matrix M as T*10, where T is the mumver of
observations in the sample and there are 10 elements in the lower triangle
of the matrix for a specific period

Now I want to calculate the eigenvalues of the matrix for each time period:

mata:
M = st_matrix("M")
lambda = J(cols(M), 4, .)
for(t=1; t<=cols(M); t++) {
mt = invvech(M[., t])
lambda[t, .] = symeigenvalues(mt)
}
lambda
end


I am wondering if -M= = st_matrix("M")- here make sure it is a *symmetric*
matrix with the elements h11 h21... that I just generated.



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





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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index