Stata 15 help for spset

[SP] spset -- Declare data to be Sp spatial data

Syntax

Display the current setting

spset

Set data with shapefiles

spshape2dta ... (see [SP] spshape2dta)

Set data without shapefiles

spset idvar [, options]

Modify how data are set with shapefiles

spset [idvar], modify [shpmodoptions]

Modify how data are set without shapefiles

spset, modify [modoptions]

Clear the setting

spset, clear

idvar is an existing, numeric variable that uniquely identifies the geographic units, meaning the observations in cross-sectional data and the panels in panel data.

shapefile refers to a Stata-format shapefile, specified with or without the .dta suffix. Such files usually have names of the form name_shp.dta.

options Description ------------------------------------------------------------------------- coord(xvar yvar) designate xvar and yvar as the location coordinates coordsys(coordsys) specify how coordinates are interpreted -------------------------------------------------------------------------

shpmodoptions Description ------------------------------------------------------------------------- coordsys(coordsys) change how coordinates are interpreted noshpfile break link with shapefile replace replace current geographic identifier with idvar -------------------------------------------------------------------------

modoptions Description ------------------------------------------------------------------------- coord(xvar yvar) replace location coordinates with xvar and yvar coordsys(coordsys) change how coordinates are interpreted nocoord clear coordinate settings shpfile(shapefile) establish link to shapefile -------------------------------------------------------------------------

Menu

Statistics > Spatial autoregressive models

Description

Data must be spset before you can use the other Sp commands. The spset command serves three purposes:

1. It reports whether the data are spset and if so, how.

2. It sets the spatial data for the first time.

3. It modifies how the data are spset at any time.

Data that are spset are called Sp data.

Options

coord(xvar yvar) and nocoord specify coordinates. coord() specifies the variables recording the x and y coordinates or the longitude and latitude. nocoord specifies that previously set coordinates be forgotten.

coord(xvar yvar) creates or replaces the contents of Sp variables _CX and _CY.

coord() and nocoord are allowed only if the data are not linked to a shapefile. If you want to use different coordinates than the shapefile provides, break the connection to the shapefile by typing

. spset, modify noshpfile

and then use spset, modify coord(xvar yvar). You can later use spset, modify shpfile(shapefile) to reestablish the link. Relinking to the shapefiles reestablishes the original coordinates stored in _CX and _CY.

coordsys(coordsys) specifies how to interpret coordinates. You may specify coordsys() regardless of whether you are linked to a shapefile. coordsys() syntax is

coordsys(planar) (default) coordsys(latlong) (kilometers implied) coordsys(latlong, kilometers) coordsys(latlong, miles)

coordsys(latlong) specifies latitude and longitude coordinates. kilometers and miles specify the units in which distances should be calculated. Distances for planar coordinates are always in the units of the planar coordinates.

modify specifies that existing spset settings are to be modified. Omitting modify means that the data are being spset for the first time.

You can modify Sp settings as often as you wish.

clear clears all Sp settings. It drops the variables _ID, _CX, and _CY that spset previously created.

replace replaces the current geographic identifier with idvar.

noshpfile breaks the link to the Stata-format shapefile, the file that usually has shapefile_shp.dta. Data that were linked to a shapefile will be just as if they had never been linked to it. Before breaking the link, you should make a note of the shapefile's name:

. spset (make a note of the shapefile's name) . spset, modify noshpfile

The shapefile might have been named shapefile_shp.dta. You will need the name later should you wish to reestablish the link.

shpfile(shapefile) and drop are for linking or relinking to a shapefile. To reestablish the link to the shapefile that was just unlinked above, you would type

. spset, modify shpfile(shapefile_shp)

Not only will the shapefile be relinked, but the coordinates stored in _CX and _CY will be restored, too.

shpfile() will refuse to link the shapefile if the data in memory contain observations for _ID values not found in the shapefile. In this case, specify shpfile() and drop if you are willing to drop the extra observations from the data in memory.

Examples

Setup . copy http://www.stata-press.com/data/r15/homicide1990.dta . . copy http://www.stata-press.com/data/r15/homicide1990_shp.dta . . use homicide1990

Check the Sp setting of the data . spset

Convert the coordinates to latitude and longitude and measure the distance in miles . spset, modify coordsys(latlong, miles)

Stored results

spset stores the following in r():

Macros r(sp_ver) 1 r(sp_id) _ID r(sp_id_var) varname or empty r(sp_shp_dta_path) path to _shp.dta file r(sp_shp_dta) shapefile_shp.dta r(sp_cx) _CX or empty r(sp_cy) _CY or empty r(sp_coord_sys) planar or latlong r(sp_coord_sys_dunit) kilometers or miles if r(sp_coord_sys) = latlong


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index