Announcement

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

  • Spatial weight matrix of distance in the Mata

    Hello,
    I would like to know how to generate spatial weight matrix of distance in the Mata. Could I do that? Which command to use?
    I'm trying to generate the matrix in STATA, with the following command:

    spatwmat, name(W) xcoord(longitude) ycoord(latitude) band(0 5) standardize

    However, being a very large matrix (5564x5564), the STATA is locking and does not generate the matrix.
    Anyone have suggestions to help me?
    Thank you.

  • #2
    Rafaella --

    Something like the following should do the trick (I hope I haven't messed up the distance calculation!) On my computer, I can make a 6000 by 6000 distance matrix, but I then have a little trouble doing anything with it. Anyways:

    Code:
    clear all
    mata
    real matrix distances(real colvector x, real colvector y) {
        D=J(rows(x),rows(x),.)
        for (i=1;i<=rows(x);i++) D[i,]=sqrt((x:-x[i]):^2:+(y:-y[i]):^2)'
        return(D)
    }
    
    /* Test */
    /* Column vectors of coordinates required */
    
    x=runiform(6000,1)
    y=runiform(6000,1)
    
    D=distances(x,y)
    end
    Hope that helps!

    Matt

    Comment


    • #3
      Hi Matt,

      I will test the programming that you suggested.
      Thank you so much for the return.
      Rafa.

      Comment

      Working...
      X