Announcement

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

  • Inverse distance weights matrix

    Hi,

    I have the following problem: I want to apply spatial autoregression for voting results of one party across almost 3000 municipalities. It makes sense to assume that the municipalities which are closer to each other affect each other more than those which are further. Hence, I would suppose that inverse distance weights matrix is the proper matrix to account for the effect. However, currently I only have a matrix which measures real travel distances between the municipalities and another matrix which measures real travel times between the municipalities.

    When I conduct the spatial autoregression with these matrices, coefficients for some explanatory variables become less significant than in the basic OLS model which probably supports my argument that we should work with the inverse weights versions of the matrices (and probably also supports the argument of the existing spatial dependencies).

    What I need now is to take an inverse for all my values in the matrices.

    It works just fine if I do it for one municipality:

    "replace v2=1/v2 if v2!=0" (I have 0s in diagonal)

    However, I would have to replicate this command 2928 times up to my variable "v2929":

    "replace v2929=1/v2929 if v2929!=0"

    Is there a command in Stata to conduct the "replace" for all my 2928 municipalities (v2-v2929)? Or any other way to solve my problem?

    Thank you very much.

    Michal

  • #2
    Did you try the user-written spmat command (part of the sppack package)? It has the capacity to create inverse-distance spatial-weights matrices.
    Code:
    ssc describe sppack
    Further reading:
    https://twitter.com/Kripfganz

    Comment


    • #3
      Thanks for the tip, Sebastian. The solution was easy after all - I just had to add "idistance" to the "spmat" command which automatically converted all the values in the matrix:

      spmat import SPWMat using Vzd2017.csv, idistance replace normalize(row)

      Comment

      Working...
      X