Announcement

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

  • error of "spmatrix create contiguity"

    Hello everyone,

    I am trying to run a model with spatial lags of the dependent variable using spxtregress in Stata 17. I would like to create a neighbor contiguity matrix.

    I have two datasets. For the first, I have the variables of coordinates like; _ID, _CY and _CX with observations of 54 African countries. The second, I have my panel data with 864 observations from 2003 to 2018.
    My code used is;
    merge m:1 country using “shp_59_country2.dta”
    The results are 864 observations matched.
    But when I use this code; “spmatrix create contiguity W"
    Stata said “Some observations in master dataset are not in coordinates dataset” r(498);

    Could somebody help me with this problem?
    What have I been doing wrong?

    Thank you.
    Attached Files

  • #2
    Two issues that I see:

    1. As you have panel data, you cannot create the weighting matrix directly. The manual states:

    If you have panel data and want to create a weighting matrix, you must use an if statement with spmatrix create to restrict the data to a single time value.
    2. The error message indicates that there are some identifiers in "shp_59_country2.dta" not present in your shapefile. So check for missing values or extra identifiers across the two datasets.
    Last edited by Andrew Musau; 28 Nov 2022, 12:43.

    Comment


    • #3
      Dear Andrew Musau

      Thank you very much for your response.

      I have looked into all the missing values and adjusted them to eliminate them.
      However, that method did not work.

      On the other hand, I didn't know that I cannot create the weighting matrix directly.
      I appreciate the very useful information you have given me.
      Could you please tell me from which page I can find the manual so that I can get more detailed information?

      Thank you.

      Comment


      • #4
        Here is the link to the PDF manual entry for the command: https://www.stata.com/manuals/spspmatrixcreate.pdf. If you are able to share the datasets, I will be happy to have a look.

        Comment


        • #5
          I am so sorry for the delayed response.

          I tried using the if command as you advised, but it did not work very well. I'm sorry for all your efforts.

          I have attached the data set.
          I would be very happy if you could take a look at the data. I would appreciate any advice you could give me.
          Attached Files

          Comment


          • #6
            Attach the shapefile as well.

            Comment


            • #7
              Ok. I don't know why but I could not upload my file, so I would like you to download shapefile from this page; https://open.africa/dataset/africa-shapefiles

              Comment


              • #8
                OK, will have a look and get back to you.

                Comment


                • #9
                  Originally posted by Miranda Uchii View Post
                  I am so sorry for the delayed response.

                  I tried using the if command as you advised, but it did not work very well. I'm sorry for all your efforts.

                  I have attached the data set.
                  I would be very happy if you could take a look at the data. I would appreciate any advice you could give me.
                  It may be something with your shapefile. Try this:

                  Code:
                  //https://open.africa/dataset/africa-shapefiles
                  copy https://open.africa/dataset/dacf49f9-c71d-4a70-80c5-7b4afe1a5dc0/resource/04ed7565-614d-473e-88b9-2e9208c5cece/download/afr_g2014_2013_0.zip afr_g2014_2013_0.zip, replace
                  unzipfile afr_g2014_2013_0.zip, replace
                  spshape2dta afr_g2014_2013_0, replace
                  
                  tempfile afrshape
                  use  afr_g2014_2013_0.dta , clear
                  replace ISO3= string(_n) if missing(ISO3)
                  save `afrshape'
                  
                  use "shp_59_country2_1134_sodan.dta", clear
                  assert countrycode==ISO3
                  drop _ID- MOI
                  rename countrycode ISO3
                  merge m:1 ISO3 using `afrshape', keep(master match) nogen
                  xtset _ID year
                  spmatrix create contiguity W if year==2000
                  spset
                  and you should get

                  Code:
                  . spmatrix create contiguity W if year==2000
                    weighting matrix in W contains 7 islands
                  
                  . spset
                    Sp dataset shp_59_country2_1134_sodan.dta
                                  data:  panel
                       spatial-unit id:  _ID (equal to country)
                               time id:  year (see xtset)
                           coordinates:  _CY, _CX (latitude-and-longitude, miles)
                      linked shapefile:  afr_g2014_2013_0_shp.dta
                  Last edited by Andrew Musau; 05 Dec 2022, 19:30.

                  Comment

                  Working...
                  X