I have a shapefile that in addition to the coordinates etc, has monthly data on nighttime lights for districts in India. I am trying to import the shapefile into Stata 15 SE , and convert it to a panel while preserving the spatial properties. I want to use census_no (district identifiers) for later work.
The main code is pasted below
After spset (sixth-last line), I get an error, "variable _ID does not uniquely identify the observations"
I also tried spset census_no but that does not help either:
You can see now that it has lost all the coordinate and linked shapefile info.
Thanks.
The main code is pasted below
Code:
spshape2dta "`where'\lights\rad_dist", saving(rad_dist) replace use rad_dist label data "rad_dist excludes pixels>2800 and Delhi has been merged to one dist/state" rename census_no censusno drop census_* rename censusno census_no spset census_no, modify replace spset, modify coordsys(latlong, kilometers) save, replace *Beginning reshape reshape long avg, i(census_no) j(yyyymm) rename avg rad tostring yyyymm, generate(monthstr) *Breaking up Years and Months gen yearstr=substr(monthstr,1,4) gen mthstr=substr(monthstr, 5,2) destring yearstr, generate(year) destring mthstr, generate(month2) gen double yrmonth=ym(year, month2) label var yrmonth "Stata Formatted(SIF) YYYYMM" xtset census_no yrmonth spset label var rad "Night Lights" *note rad: These are the cleaned Night lights- i.e. pixel values greater than 2800 changed to null and values lower than zero replaced with zero. drop yearstr mthstr monthstr rename month2 month save radpanel, replace
Code:
. xtset census_no yrmonth panel variable: census_no (strongly balanced) time variable: yrmonth, 627 to 695 delta: 1 unit . spset Sp dataset data: cross sectional spatial-unit id: _ID (equal to census_no) coordinates: _CY, _CX (latitude-and-longitude, kilometers) linked shapefile: rad_dist_shp.dta variable _ID does not uniquely identify the observations Do these data need to be xtset? r(459); end of do-file
Code:
. xtset census_no yrmonth panel variable: census_no (strongly balanced) time variable: yrmonth, 627 to 695 delta: 1 unit . spset census_no Sp dataset data: panel spatial-unit id: _ID (equal to census_no) time id: yrmonth (see xtset) coordinates: none linked shapefile: none
Thanks.