Announcement

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

  • Filling upper triangle of a symmetric matrix

    Hi,
    I have data on cross correlations among let's say 4 variables. It is structured like this:

    var1 var2 var3 var4
    1 . . .
    4 1 . .
    3 4 1 .
    3 5 7 1

    I need to fill the upper triangle of my data with the transposed values from the lower triangle. So it becomes:

    var1 var2 var3 var4
    1 4 3 3
    4 1 4 5
    3 4 1 7
    3 5 7 1

    Is there a short way to do it?
    Thanks!


  • #2
    Assuming these are the only variables in the dataset, this should work

    Code:
    // your example
    clear
    inp var1 var2 var3 var4
    1 . . .
    4 1 . .
    3 4 1 .
    3 5 7 1
    end
    
    // suggested code
    mkmat * , matrix(mymat)
    m : st_replacematrix("mymat", makesymmetric(st_matrix("mymat")))
    rename * old_*
    svmat mymat , names(col)
    
    // result
    list
    I wonder, however, what you want to do with such a dataset.

    Best
    Daniel

    Comment


    • #3
      Thanks so ,much! It worked just fine.

      I need this matrix as input data for NodeXL.

      Comment

      Working...
      X