Announcement

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

  • Is there a way to export contiguity weight matrix as .gal file?

    Hello,

    I apologize if I missed it somewhere, but please help me. Is there a way, after I create a spatial weight matrix (contiguity) using Stata's option spmatrix create spmatrix create to export this matrix, but in .gal format so that I can import it in GeoDa?

    Now I do not need it, but it would be useful for .gwt files too.

    Thank you a lot for your help.

  • #2
    I would suggest using the user-written spmat command to create a spatial-matrix object and exporting as such:

    Code:
    // create a toy spmat object
    set seed 10101
    mata:
        n = 100
        W = runiform(n,n) :> .9
        _makesymmetric(W)
        _diag(W,0)
    end
    spmat putmatrix spobj W, replace norm(row)
    
    // example of .gal file
    spmat export spobj using mydata.gal, nlist replace
    type mydata.gal, lines(11)
    
    // example of .gwt file
    spmat getmatrix spobj W
    capture erase mydata.gwt
    mata:
        fh = fopen("mydata.gwt", "w")
        n = rows(W)
        for (i=1; i<=n; i++) {
            for (j=1; j<=n; j++) {
                if (W[i,j]) {
                    line = sprintf("%g %g %g",i,j,W[i,j])
                    fput(fh,line)
                }
            }
        }
        fclose(fh)
    end
    type mydata.gwt, lines(11)
    
    // clean up
    capture erase mydata.gal
    capture erase mydata.gwt

    Comment


    • #3
      Thank you a lot

      Comment

      Working...
      X