Announcement

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

  • Counter in Mata

    Hello, I am writing a code in Mata. In this code I need to create some matrix R1, R2 , R3 ,...,Rn
    In Stata, I could write:
    forvalues h =1/n {
    ... commands....
    matrix R`h'= expression
    }
    However, I don't know how to do this in Mata
    Help me , please!!!

  • #2
    Hi Christian
    Try and look at the link below.
    Especially Matthew's comment.
    I am wondering whether there are high dimensional matrices in Mata. Right now I can just use pointer for high dimensional matrices. I think high dimensional
    Kind regards

    nhb

    Comment


    • #3
      You can use a vector of pointers

      Code:
      . mata:
      ------------------------------------------------- mata (type end to exit) -----------------------------------------------------------------
      : 
      : a = J(1,2,NULL)
      
      : 
      : for (i=1;i<=cols(a);i++) {
      >                 a[1,i] = &J(i,i,i)
      > 
      > }
      
      : 
      : a
                     1           2
          +-------------------------+
        1 |  0x2154470   0x21e8f10  |
          +-------------------------+
      
      : *a[1,1]
        1
      
      : *a[1,2]
      [symmetric]
             1   2
          +---------+
        1 |  2      |
        2 |  2   2  |
          +---------+
      
      : 
      : for (i=1;i<=cols(a);i++) {
      >                 *(a[1,i]) = J(1,1,.)
      > 
      > }
      
      : 
      : a
                     1           2
          +-------------------------+
        1 |  0x2154470   0x21e8f10  |
          +-------------------------+
      
      : *a[1,1]
        .
      
      : *a[1,2]
        .
      
      : 
      : 
      : end
      -------------------------------------------------------------------------------------------------------------------------------------------

      Comment

      Working...
      X