Statalist


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

RE: st: RE: use Mata to calculate the eigenvalues of the matrix


From   [email protected]
To   [email protected]
Subject   RE: st: RE: use Mata to calculate the eigenvalues of the matrix
Date   Sun, 08 Mar 2009 16:23:13 -0400

Thank you all! It works!

The new codes are:

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

By the way, does negative semidefinite require all the eigenvalues of the matrix negative? Even one of them positive makes fail?

Jingjing


Quoting Glenn Goldsmith <[email protected]>:

Hi,

In addition to what Nick said:

1. I think that you want to be looping through the *rows* of your M matrix,
rather than the columns as you are trying to do now.

2. It doesn't look like you actually want all the rows of your M matrix as
it stands, you only want the last 10.

An *easy* way to achieve this (though not the most *elegant* way of
proceeding) would be to insert

M = M[,7..16]'

after the first line of your code.

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

HTH

Glenn.

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