Announcement

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

  • Saving spatial weight matrix from spmat

    Dear Stata users,

    I would kindly like to ask you two things related to the command "spmat". Thank you very much

    I have created my spatial weight matrix (inverse distance) for my dataset of 17 regions through:

    "spmat idistance W longitude latitude, id(ID) dfunction(dhaversine)" (where "W" is the spatial-weighting object)

    1) I kindly wanted to ask you (forgive me if this is a stupid question) how I could compute different threshold distances to test for spatial autocorrelation with the weight matrix, that is, for instance, set to zero all the values of the weight matrix whose distance is, e.g., higher than 100 kms.

    2) Also (second question) I was wondering if it is possible to calcolate the Moran's I statistic for deriving the optimal distance through the command "spmat" (I only found Moran's I from "spatwmat"). This because I have to derive the optimal threshold distance (beyond which there is no more spatial effect anymore).

    Thank you very much and best wishes for a great 2016 to everyone!

    Kodi
    Last edited by Kodi Hannon; 31 Dec 2015, 10:21.

  • #2
    Ps: I apolgise, please do not consider point 1), but just point 2).

    So, my problem is that I would like to derive a Moran's I statistic for my dataset of provinces through the spmat command. If someone can help me with that I would really be gratteful. Thank you very much.

    Comment


    • #3
      At the moment, spmat does not offer an option to calculate Moran's I. However, it is pretty straightforward to calculate Moran's I in Mata by hand. Below I replicate Moran's I from this example using this formula:

      Code:
      use http://www.ats.ucla.edu/stat/stata/faq/ozone.dta, clear
      spatwmat, name(ozoneweights) xcoord(lon) ycoord(lat) band(0 3)
      spatgsa av8top, weights(ozoneweights) moran
      mat list r(Moran)
      
      mata:
          w = st_matrix("ozoneweights")               /* spatial-weighting matrix */
          N = cols(w)
          x = st_data(.,"av8top")
          x = x:-mean(x)                              /* demeaned variable        */
          num = N*sum(w:*(J(1,N,x):*J(N,1,x')))       /* numerator                */
          den = sum(w)*sum(x:^2)                      /* denominator              */
          m = num/den
          printf("Moran's I is: %g\n",m)
      end
      The variance can be calculated in a similar way.

      Comment


      • #4
        Dear Rafal,

        thank you very much for your very kind reply! (and best wishes for an happy 2016!)

        I would just kindly ask you two more things: I think there is a typying error in the computation of the numerator ( num = N*sum(w:*(J(1,N,x):*J(N,1,x'))) ), since it gives me error..

        Also, in using this typing in mata, how can I set different distance bands?

        Thank you very much!

        Kodi
        Last edited by Kodi Hannon; 01 Jan 2016, 11:12.

        Comment


        • #5
          I apologize, please do not consider my previous reply.

          I solved the issue.

          Again, thank you very much!

          Kodi

          Comment

          Working...
          X