Announcement

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

  • Create and export spatial matrix: spmatrix does not find the matrix created in Mata

    I have a code that partially works to create a spatial matrix:

    egen id = group(IOCode), label lname(IOCode)

    spset id

    local var v1 v2 v3 v4 v5

    mata: st_matrix("c",st_data((1,5),"`var'"))

    matrix coln c= `var'

    mat list c

    spmatrix spfrommata Wmat=c id

    Although mat list c shows the matrix, spmatrix leads to the error:

    matrix c not found

  • #2
    I've also tried:

    . local var v1 v2 v3 v4 v5

    . mata:
    ------------------------------------------------- mata (type end to exit) ----------------------------------------------------------------------------------------------------------------
    :
    : id = st_data(., "_ID")

    :
    : c = st_matrix("c",st_data((1,5),"`var'"))

    :
    : end
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    .
    . spmatrix spfrommata myIdist = c id

    with the error: number of rows in matname must be > 0

    Comment


    • #3
      Your Mata code generates a Stata matrix c, not a Mata matrix c. To generate the latter, simply type
      Code:
      local var v1 v2 v3 v4 v5
      mata:
      id = st_data(., "_ID")
      c = st_data((1,5),"`var'")
      end
      spmatrix spfrommata myIdist = c id
      Aside from that: Do you really just have 5 units in your id vector?
      https://twitter.com/Kripfganz

      Comment

      Working...
      X