Announcement

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

  • Making and filling matrix ..in mata

    Dear all.

    I'm trying to make mata program, but there are lots of things I do not know.
    For example, I have a data set as below and then I use st_view or st_data to access the data set.
    id1 id2 x
    1 2 5
    1 3 6
    1 4 8
    2 1 18
    2 3 4
    2 4 67
    3 1 0
    3 2 12
    3 4 54
    4 1 6
    4 2 86
    4 3 9
    After access the dataset. The procedures that I wanna do are followings.

    1. I would like to make a matrix(ex. saying matrix T) with the unique number of id1 rows and the unique number of id1 columns.
    2. I would like to change the row names and column names of matrix T to id1.
    3. After setting the T matrix, I would like to fill the matrix like, if T(1,3)=6, the x value when id1=1 and id3=3, and T(2.4) =67, the x value when id1=2 and id3==4.

    I think I ask too many things.
    But I really wanna learn how to handle mata command.

    Thank you for reading this.

  • #2
    For #1, you can use the uniqrows function (help mf_uniqrows).

    For #2, the concept of row names does not exist in Mata so I'm not sure of what you want

    Now, what do you really want? From what I get, you want to replicate a -reshape wide- with Mata? If that's what you want, I wrote a proof of concept of that with ftools (ssc install ftools), that uses also the colshape function (which you might want to use even if you don't use ftools.

    Code is here: https://github.com/sergiocorreia/fto...c/freshape.ado

    Comment

    Working...
    X