Announcement

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

  • Problem with Spatial Weight Matrix for spreg

    Hello everyone,

    I'm working with Stata 13.1 and created a spatial weight matrix using spmat. In the next step, I merged a dataset with the attribute data of the shapefile with another cross-section dataset. However, I get two error messages when I want to conduct a regression. A short version of my do-file:

    shp2dta using D:\.....\Shapefile\TM_WORLD_BORDERS-0.3.shp, database(usdb) coordinates(uscoord) genid(id)

    use usdb, clear

    merge 1:1 WBCode using "D:\...\test.dta"
    drop if _merge==1

    *** Contiguity Matrix
    spmat contiguity W using uscoord , id(id) normalize(minmax)

    *** Inverse Distance Matrix

    spmat idistance I LON LAT, id(id) dfunction(dhaversine) normalize(minmax)

    spmat save W using W.spmat
    spmat save I using I.spmat

    *** Regression
    spreg ml y x, id(id) dlmat(W, eig) elmat(W, eig)
    y has missing values
    drop if y==.

    spreg ml y x, id(id) dlmat(W, eig) elmat(W, eig)
    ids in spmat object W do not match ids in variable id
    In case of missing values: Why is spreg not using listwise deletion?

    Regarding the second error: Giving that I merged both datasets perfectly and dropped the units that are not in both datasets: Why is Stata not able to match both ids? I tried for hours to solve the problem but I'm really lost here.

  • #2
    Hi Andre, did you solve these? I'm having the same exact problems!

    Comment


    • #3
      Listwise deletion is difficult here because Stata would also have to delete the corresponding rows and columns of the spatial weights matrix. Since this is not automatically done by spreg, you might try to drop observations with missing values already before forming the spatial weights matrix with spmat.
      https://www.kripfganz.de/stata/

      Comment


      • #4
        A solution I have done is to work without polygons when I have missing values in the dependent variable. Instead of polygons you should use centroids, and then it's possible to delete manually the missing values

        Comment

        Working...
        X