Announcement

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

  • How to modify the spatial weight matrix created by spmat command

    Hi,
    I have an question on how to modify the spatial weight matrix created by spmat. First,many thanks for so perfect commands written by David Drukker et tal.,
    I have download the shape file for china province from http://www.gadm.org/country. The command used are as following
    Code:
    clear
    shp2dta using CHN_adm1, database(china) coordinates(chinaxy) genid(id) gencentroids(c) replace
    use china,clear
    spmap using chinaxy, id(id)
    drop if NAME_1 == "Xizang"
    spmap using chinaxy, id(id)
    rename x_c longitude
    rename y_c latitude
    save china, replace
    
    *** creat rook contiguity weight matrix
    spmat contiguity c_china using chinaxy, id(id) rook  replace
    spmat save c_china using ccounty.spmat
    spmat drop ccounty
    spmat use ccounty1 using ccounty.spmat
    **export weight matrix to txt file
    spmat export ccounty1 using weight.txt,replace
    spmat summarize ccounty1, links
    From the above results we can see that
    Code:
    warning: spatial-weighting matrix contains 1 island
    In fact, Hainan province in China is island from geographical position. I assume that Hainan (id = 9) and Guangdong (id=6) province
    has a common boundary, so I should modify the spatial weight matrix.Following the http://econweb.umd.edu/~prucha/paper...PMAT(2013).pdf,
    the codes used as following
    Code:
    spmat import weight_revise using weight.txt, replace
    spmat getmatrix weight_revise w
    
    mata:w[6,9]=1
    mata:w[9,6]=1
    spmat putmatrix weight_revise1 w, normalize(row) replace
    
    spmat summarize weight_revise1, links
    However, the above codes are not working well. Many thanks for any suggestions.

    Best regards,
    wanhaiyou




  • #2
    Could anyone help with me out of this question? Thanks very much!

    Best regards,
    wanhaiyou

    Comment


    • #3
      This works for me.

      Code:
      shp2dta using CHN_adm1, database(china) coordinates(chinaxy) genid(id) gencentroids(c) replace
      use china, clear
      drop if NAME_1 == "Xizang"
      spmat contiguity c_china using chinaxy, id(id) rook replace
      spmat getmatrix c_china w
      mata:w[6,9]=1
      mata:w[9,6]=1
      spmat putmatrix c_china w, normalize(row) replace
      spmat summarize c_china, links detail

      Comment


      • #4
        Originally posted by Rafal Raciborski (StataCorp) View Post
        This works for me.

        Code:
        shp2dta using CHN_adm1, database(china) coordinates(chinaxy) genid(id) gencentroids(c) replace
        use china, clear
        drop if NAME_1 == "Xizang"
        spmat contiguity c_china using chinaxy, id(id) rook replace
        spmat getmatrix c_china w
        mata:w[6,9]=1
        mata:w[9,6]=1
        spmat putmatrix c_china w, normalize(row) replace
        spmat summarize c_china, links detail
        Thanks very much for your helo,Rafal
        Yes,the above codes are working well. I have an question. How could I obtain the non-normalization spatial weight matrix using spmat.
        The spatial weight matrix created by spmat is the row-normalized matrix, each element in row i is divided by the sum of row i's elements (default).

        Best regards,
        wanhaiyou

        Comment


        • #5
          The default is a non-normalized matrix, simply skip the normalize(row) option.

          Comment


          • #6
            Originally posted by Rafal Raciborski (StataCorp) View Post
            The default is a non-normalized matrix, simply skip the normalize(row) option.
            Thanks very much,Rafal.
            I am sorry for my mistake. I display the w after running
            Code:
             spmat putmatrix c_china w, normalize(row) replace
            You are right,the default is a non-normalized matrix
            Code:
             shp2dta using CHN_adm1, database(china) coordinates(chinaxy) genid(id) gencentroids(c) replace
            use china, clear
            drop if NAME_1 == "Xizang"
            spmat contiguity c_china using chinaxy, id(id) rook replace
            spmat getmatrix c_china w
            mata:w[6,9]=1
            mata:w[9,6]=1
            mata:st_matrix("w",w)
            matlist w
            Thanks!
            Best regards,

            wanhaiyou

            Comment


            • #7
              Hello Its Rajarshi,
              Please anyone help me out with the following problem.
              I have a shape file downloaded in my desktop with name "IND_adm5" (with all associated .dbf, .shp files). I want to read this shape file with shp2dta command in stata and then using spmat package, I want to create spatial weights matrices. I am unable to load the shape file "IND_adm5" from my desktop to stata..

              Could anybody help me out with this?

              Comment

              Working...
              X