Announcement

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

  • spset after merge: spatial details disappear

    Dear All,

    I posted some time ago a similar post. I thought to have solved my problem, but it is still there. I use stata15. Basically, I convert a shapefile into a stata one using spshape2dta. It works fine:

    Code:
     spshape2dta shapecountries
      (importing .shp file)
      (importing .dbf file)
      (creating _ID spatial-unit id)
      (creating _CX coordinate)
      (creating _CY coordinate)
    
      file shapecountries_shp.dta created
      file shapecountries.dta     created
    If I spset the file shapecountries.dta I get:

    Code:
    
    spset
      Sp dataset shapecountries.dta
        data:  cross sectional
        spatial-unit id:  _ID
        coordinates:  _CX, _CY (planar)
        linked shapefile:  shapecountries_shp.dta
    Then I try to merge this file using another one:

    Code:
    merge m:m NAME using vp1
    
        Result                           # of obs.
        -----------------------------------------
        not matched                  3
        from master                   0  (_merge==1)
        from using                     3  (_merge==2)
    
        matched                       248  (_merge==3)
        -----------------------------------------
    Finally, I check that everything is fine with the spset (as far as I read, although I modify the file somehow - as merging it with another one - it should preserve the previous spset):

    Code:
    spset
    invalid panel setting
    Type xtset to view panel data settings.

    Why this is the case? Do you have any suggestion? Just for your reference, I upload the files used above. Thanks in advance.

    Dario

    https://dl.dropboxusercontent.com/u/27015126/data.zip
    Last edited by Dario Maimone Ansaldo Patti; 13 Jul 2017, 16:37.

  • #2
    It looks like your vp1 dataset has a bad xtset setting. Type xtset, clear and then resave the dataset. Also, it looks like your dataset has duplicate NAME values which will cause spset to error.

    Code:
    . use vp1, clear
    
    . xtset
    variable year not found
    r(111);
    
    . xtset, clear
    
    . save, replace
    file vp1.dta saved
    
    . duplicates list NAME
    
    Duplicates in terms of NAME
    
      +----------------------------+
      | group:   obs:         NAME |
      |----------------------------|
      |      1    121   Kyrgyzstan |
      |      1    122   Kyrgyzstan |
      |      2    202     Slovakia |
      |      2    203     Slovakia |
      +----------------------------+
    
    . merge m:m NAME using shapecountries
    
        Result                           # of obs.
        -----------------------------------------
        not matched                             3
            from master                         3  (_merge==1)
            from using                          0  (_merge==2)
    
        matched                               248  (_merge==3)
        -----------------------------------------
    
    . drop if _merge == 1
    (3 observations deleted)
    
    . spset
      Sp dataset vp1.dta
                    data:  cross sectional
         spatial-unit id:  _ID
             coordinates:  _CX, _CY (planar)
        linked shapefile:  shapecountries_shp.dta
    variable _ID does not uniquely identify the observations
    r(459);
    
    . list NAME _ID if _ID == 105
    
         +----------------+
         |     NAME   _ID |
         |----------------|
    200. | Slovakia   105 |
    201. | Slovakia   105 |
         +----------------+

    Comment


    • #3
      Dear Kevin,

      thanks for your reply. Actually, my main problem was with spset. I knew NAME may not uniquely identify observations. The file vp1 comes from collapsing a panel data. Apparently, the file still contained the previous xtset.

      Thank you very much for your help.

      Best,

      Dario

      Comment

      Working...
      X