working with geodata in stata

14
Working with geodata in Stata Applied reading group UC3M Jaime A. Millán UC3M & Econometría S.A. February 24, 2015 Jaime A. Millán (UC3M & Econometría S.A.) Working with geodata in Stata February 24, 2015 1 / 14

Upload: duongdan

Post on 12-Feb-2017

241 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Working with geodata in Stata

Working with geodata in StataApplied reading group UC3M

Jaime A. Millán

UC3M & Econometría S.A.

February 24, 2015

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 1 / 14

Page 2: Working with geodata in Stata

Summary

Stata has develop some tools that can be use to create and analyze georeferenced data.You can use that data to draw some (nice) maps as well.

These are some examples:

shp2dta: Import .shp data to stata formats (.dta)

spmap: Draw maps. You can add some information to the maps as well.

geocode3: “This command geocodes addresses into coordinates or reverse geocodescoordinates into addresses via Google Geocoding and provides responseinformation about the quality of the results” Ideas-Repec

traveltime3: “This command uses coordinates or addresses to retrieve distance andtravel time between two locations via Google Distancematrix.”Ideas=Repec

Other commands are spgrid, spkde, spatwmat, spatgsa, and spatlsa.

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 2 / 14

Page 3: Working with geodata in Stata

shp2dta

shp2dta using shpfilename, database(filename) coordinates(filename)[options]It takes a shape file and creates 2 dta files. The data file contains theinformation linked with the shape file. The coor contains the coordinatesof each feature in the map.

loc Shapes "departamentos_proj municipios_proj"foreach shp in ‘Shapes’ {

shp2dta using ‘fldInShp’‘shp’, replace ///data(‘fldShp’‘shp’_Data) ///coor(‘fldShp’‘shp’_Coor) ///genc(Centro) genid(ID) ///

}

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 3 / 14

Page 4: Working with geodata in Stata

spmap

spmap [attribute] [if] [in] using basemap [,basemap_optionspolygon(polygon_suboptions)line(line_suboptions)point(point_suboptions)diagram(diagram_suboptions)arrow(arrow_suboptions)label(label_suboptions)scalebar(scalebar_suboptions)graph_options

]

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 4 / 14

Page 5: Working with geodata in Stata

spmap example 1

spmap coca2002 using ‘fldShp’municipios_proj_Coor if dpto == ‘dpto’, ///id(ID) clm(u) fc(yellow red) oc(gs4 ..) legc ///ti(Municipios con cultivos de coca 2002, size(medium)) ///subtitle(‘labDept’, size(small)) ///note("Fuente: SIMCI-DNE", size(vsmall) pos(5))

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 5 / 14

Page 6: Working with geodata in Stata

spmap example 2

spmap using ‘fldShp’municipios_proj_Coor if dane == 73024, ///id(ID) fc(eggshell) oc(gs4) ///point(data(‘fldShp’TPR_ALPUJARRA_Data) select(keep if ID > 1500) ///x(x_Centro) y(y_Centro) size(vsmall) fc(none) oc(red)) ///

polygon(data(‘fldShp’cabecera_poligono_proj_Coor) ///select(keep if _ID == 878) fc(brown)) ///

ti(Municipio de Alpujarra, size(medium)) ///subtitle(Veredas en la muestra, size(small)) ///note("Fuente: Econometria - Mision Rural")

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 6 / 14

Page 7: Working with geodata in Stata

spmap example 3

spmap using ‘fldShp’municipios_proj_Coor, id(ID) ///diagram(var(prop_urb prop_rural) x(x_Centro) y(y_Centro) fcolor( gs14 green) ///size(1) legenda(on)) ///

label( x(x_Centro) y(y_Centro) label(lab) color(black) po(6) ga(*7) size(*2)) ///legend( pos(2) size(*1.5) ) ///title(Composicin de la poblacin) ///subtitle("Departamento de Arauca" "") ///note(Fuente: DANE)

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 7 / 14

Page 8: Working with geodata in Stata

geocode3

This command is linked with Google Geocoding, the base of Google maps.The ideas is to write an address in google maps and you can actually getthe coordinates. Or, if you give some coordinates to Google maps you cansee the address as well.

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 8 / 14

Page 9: Working with geodata in Stata

geocode3

From address to coordinatesgeocode3, address(varname) zip state

From coordinates to addressgeocode3, coord(varname) zip state number street ad2

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 9 / 14

Page 10: Working with geodata in Stata

Example geocode3

geocode3, address(DIR)

The problem is that you are only allowed to make 1000 queries a day.

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 10 / 14

Page 11: Working with geodata in Stata

Example geocode3

(a) Scatter graph (b) Map

Figure: We can see the results

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 11 / 14

Page 12: Working with geodata in Stata

traveltime3

It’s the same idea of geocode3, records the information information as youwere using the directions tool of google maps.

traveltime3 , start(string) end(string) mode(string) units(string)avoid(string)

start and end can be either addresses or coordinates. If you want to usecoordinates you should write a string of the shape “latitude,longitude”

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 12 / 14

Page 13: Working with geodata in Stata

Example travel time 3

traveltime3, start(p0) end(p1)

Jaime A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 13 / 14

Page 14: Working with geodata in Stata

Thanks to Juan Pablo Herrera ([email protected] )

[email protected] A. Millán (UC3M & Econometría S.A.)Working with geodata in Stata February 24, 2015 14 / 14