Announcement

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

  • multiple observations in the same area

    Dear Statalists,

    I made a spatial weight matrix with inverse distance weights, which contains missing values. The main reason is that many observations are located in the same area. For example,


    LATNUM LONGNUM
    Obs A -11.65457 34.1931
    Obs B -11.65457 34.1931

    As a result, there are missing values in the generated matrix. When I try to run this using :
    spmat idistance I LONGNUM LATNUM, id( id ) dfunction(dhaversine) normalize(minmax) replace
    ​​​​​​​
    I got this error "Two or more observations have the same coordinates"




    As an alternative, I used this code from other thread posted in this forum.

    clear mata

    mata:
    id = st_data(., "DHSCLUST")
    location = st_data(., ("LONGNUM", "LATNUM"))
    N = st_nobs()
    M = J(N, N, 0)
    for (i=1; i<=N; i++) {
    for (j=1; j<i; j++) {
    delta = location[i,.] - location[j,.]
    M[i,j] = M[j,i] = 1/sqrt(delta*delta')
    }
    }
    M
    st_matrix("weightmatrix_women", M)
    end

    But this also generate missing values in the matrix.
    If somebody knows how to sort this out, it would be very helpful for me.

    Kind regards,

    Kim
Working...
X