Announcement

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

  • Spset returns error after Shapefile and Panel Data Merge despite data being xtset?

    I am trying to merge a shapefile with a panel data (i=location and j=month). Despite following the instructions in intro 4 here: https://www.stata.com/manuals/sp.pdf (particularly step 7b on page 35), the procedure still returns an error - it refuses to recognize the data as a panel.

    Code:
    . use "C:\Users\achan\Dropbox\Research\demon\data\inter\Census_2011D.dta"
    
    . spset
      Sp dataset Census_2011D.dta
                    data:  cross sectional
         spatial-unit id:  _ID (equal to census_no)
             coordinates:  _CY, _CX (latitude-and-longitude, kilometers)
        linked shapefile:  Census_2011D_shp.dta
    
    . use "C:\Users\achan\Dropbox\Research\demon\data\inter\radpanel2015m.dta"
    (Excludes pixels>2800, Delhi merged to one dist/state, 2015 Annual VIIRS Mask)
    
    . xtset
           panel variable:  census_no (strongly balanced)
            time variable:  yrmonth, 627 to 695
                    delta:  1 unit
    
    . spbalance
      (data strongly balanced)
    
    . sum
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
       census_no |     43,677    322.8562    184.4444          0        640
        OBJECTID |     43,677         317    182.7332          1        633
             rad |     43,677    12659.59    18284.97          0   351883.8
         yrmonth |     43,677         661    19.91672        627        695
    
    . merge m:1 census_no using "C:\Users\achan\Dropbox\Research\demon\data\inter\Census_2011D.dta"
    
        Result                           # of obs.
        -----------------------------------------
        not matched                             0
        matched                            43,677  (_merge==3)
        -----------------------------------------
    
    . spset
      Sp dataset radpanel2015m.dta
                    data:  cross sectional
         spatial-unit id:  _ID (equal to census_no)
             coordinates:  _CY, _CX (latitude-and-longitude, kilometers)
        linked shapefile:  Census_2011D_shp.dta
    variable _ID does not uniquely identify the observations
        Do these data need to be xtset?
    r(459);
    
    . xtset
           panel variable:  census_no (strongly balanced)
            time variable:  yrmonth, 627 to 695
                    delta:  1 unit
    Thanks.

  • #2
    Hi Branon,

    I am trying a similar thing with panel data and facing the same issue. I wonder whether you found any solution to it.

    Best,

    Fouzia

    Comment


    • #3
      Dear Fouzia and Branon

      I am having the same problem with my cross-section data. Has any of you managed to find the solution to this problem?

      Comment


      • #4
        Did anyone get an answer to this? I'm having a similar issue merging a shapefile with panel data following the manual. Stata is returning the same error r(459) mentioned above.

        Comment


        • #5
          To fix this error, you can either xtset _ID time then spset, or spset your panel variable.

          Using Branon's example, after merging with Stata-format shapefile, try the following commands:

          xtset _ID yrmonth
          spset

          or

          xtset
          spset census_no
          Last edited by Annie Peng; 21 Jul 2020, 17:32.

          Comment


          • #6
            Thank you @Annie Peng

            Comment


            • #7
              Annie Peng, many thanks. The Stata manual makes it sound like Stata automatically changes the xtset id variable, but it seems like we actually need this extra step to change it.

              Comment

              Working...
              X