Announcement

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

  • Search value in a matrix

    Dear all,

    I am trying to extract a specific value corresponding to a criterium from a group of matrices, and paste all the values obtained in a single vector.

    In the example below I created a matrix where the headings have 3 numbers and the others are values to be possibly extracted.
    I called the matrix "M1" and I have similar matrices "M2" to "M10".
    111 112 121
    111 1 7 8
    121 6 3 12
    131 2 8 3
    133 1 7 43
    The other matrices (M2 - M10) may not have exactly all the same rows and columns, for example M2 may be of the form:
    111 112
    111 10 4
    131 3 5
    222 3 7
    For each matrix, I would like to extract the value corresponding to the headings -say- column:112, row:131 and paste it in a vector which has 10 entries (for each matrix from M1 to M10),
    or paste a missing value in the vector when the entry is not available in the matrix.

    Thanks in advance for the help!

    Sincerely
    Luca

  • #2
    I don't understand what you want to do. Can you show what this vector would look like (or at least the entries for M1 and M2) based on the data you show in #1? In particular, I don't understand how you will make a matrix when there appear to be three dimensions: M1-M10, Row header (111, 121, 131, 133, 222) and Column header (111, 121, 122).

    You might also want to explain what the larger context is here. While Stata (and, more to the point, Mata) provides a very good set of tools for matrix manipulations, they are oriented specifically towards matrix algebra. Matrices are not, in general, an effective structure for storing information to be analyzed in Stata unless you are specifically going to be doing matrix algebra on them. Without knowing what your overall goals are I can't be more specific, but I suspect that whatever you ultimately want from this data you will get more easily from a data set in long layout than from matrices.

    Comment

    Working...
    X