clear all set more off version 14.1 // Let's look at a "database file" // This is our dictionary, it contains all important meta-information use cadb, clear /* We've got States, Counties, Tracts, GeoIDs, and Names Note: See how STATE is always 06... well, let's test it */ tab STATEFP // Yup // And county? tab COUNTYFP // Lots of those... /* GeoID and Name seem redundant - GeoID looks like STATE + COUNT + TRACT let's test */ gen GEOID_NEW = STATE + COUNTY + TRACT assert GEOID == GEOID_NEW // Great! // And Name is just the tract/100 without decimal places - easy! // INTPTLAT and INTPTLON are the interpolated boundaries of polygons // they're then the midpoint of each unit of measurement (tract) // AWATER and ALAND are cool (area of water and land) but we don't need those // so... keep STATEFP COUNTYFP TRACTCE _ID // _ID is our spmap ID variable, we need it * ps: we also generate this variable in shp2dta using genid(), but they don't get to know that just yet ******************************************************************************** // Now switching to the coordinate file use cacoord, clear // yuck... there's _ID, but what's this _X and _Y. Dunno, we should plot scatter _Y _X // That took a while... kinda looks like California // This is where spmap comes in ******************************************************************************** help spmap // use database file first use cadb, clear // base map spmap using cacoord // have to remember our ID spmap using cacoord, id(_ID) // Hey, that looks pretty good! It also takes regular Stata Options spmap using cacoord, id(_ID) title("CA Census Tracts") // But there are also some options unique to spmap ******************************************************************************** use directions, clear // this represents the Google Driving Directions from San Diego to Humboldt tab _ID // no need to worry about _ID, let's look at a line line _Y _X // Perhaps that's right, perhaps not. let's look at line options for spmap ******************************************************************************** use cadb, clear // repetition makes perfect spmap using cacoord, id(_ID) help spmap // look at line options spmap using cacoord, id(_ID) line(/* new option*/ data(directions/*name of dataset*/)) // Where is it? Maybe it's in there, but it's all black // We need to add more options spmap using cacoord, id(_ID) line(data(directions) color(eltblue)) // Oh yeah, it's there. But it's still hard to see. spmap using cacoord, id(_ID) line(data(directions) color(eltblue) size(.8)) // And the cherry on top spmap using cacoord, id(_ID) line(data(directions) color(eltblue) size(.8)) title("SDSU to Humboldt State") note("~12h 38min via Google") //We can change the fill colors: spmap using cacoord, id(_ID) line(data(directions) color(eltblue) size(.8)) title("SDSU to Humboldt State") note("~12h 38min via Google") /// polygon(data(cacoord) fcolor(red)) //We can change the line colors too: spmap using cacoord, id(_ID) line(data(directions) color(eltblue) size(.8)) title("SDSU to Humboldt State") note("~12h 38min via Google") /// polygon(data(cacoord) fcolor(red) ocolor(blue)) // Now that's an ugly graph!