Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extracting non-zero rows/columns

    Using Stata 14.1 MP under Win 7E. I think this is more of a mata question, so I'll try posting here. If not, let me know and I'll put it on the general board. I've run a model with svy:logit. Now I want to recover the SEs. This means getting the square roots of the diagonals of the covariance matrix. I typically use the following to process a covariance matrix :

    Code:
    matrix se=vecdiag(cholesky(diag(vecdiag(v))))'
    However, that seems not to work for a GLM, presumably due to the zero row and column for the intercept term (I have two IVs). Thus, I need to delete those rows/columns first.

    Assume v=e(V). In mata, I could use something along the lines of:

    Code:
    x= select(select(v, rowsum(abs(v))),colsum(abs(v)))
    But that leaves unanswered how to get the covariance matrix into mata and then back out. Plus, I think it's missing an argument for that purpose.

    Here's what I'm envisioning (just not syntactically correct):

    Code:
    matrix v=e(V) //save covariance matrix from svylogit
    mata: x= select(select(v, rowsum(abs(v))),colsum(abs(v))) //select the non-zero rows and columns, this needs an additional argument after the first parenthesis
    matrix se=vecdiag(cholesky(diag(vecdiag(x))))' //compute SEs
    I need a way to translate the matrix v into mata and then x back out. Any tips appreciated.

  • #2
    See st_matrix()
    Code:
    v = st_matrix("e(V)")

    But you can get the se's in this way

    Code:
    mata: se = sqrt(diag(st_matrix("e(V)")))
    mata: st_matrix("se",se)

    Comment


    • #3
      Perfect. Thanks for your help.

      Comment

      Working...
      X