|
| 1 | +*! 31jan2014, Michael Stepner, michaelstepner@gmail.com |
| 2 | + |
| 3 | +program define _maptile_state |
| 4 | + syntax , [ geofolder(string) /// |
| 5 | + mergedatabase /// |
| 6 | + map var(varname) legopt(string) min(string) clbreaks(string) max(string) mapcolors(string) ndfcolor(string) /// |
| 7 | + savegraph(string) replace resolution(string) map_restriction(string) spopt(string) /// |
| 8 | + geoid(varname) /// |
| 9 | + ] |
| 10 | + |
| 11 | + if ("`mergedatabase'"!="") { |
| 12 | + if ("`geoid'"=="state" | "`geoid'"=="") merge 1:1 state using `"`geofolder'/state_database_clean"', nogen keepusing(state id) |
| 13 | + else if ("`geoid'"=="statefips") merge 1:1 statefips using `"`geofolder'/state_database_clean"', nogen update replace |
| 14 | + else if ("`geoid'"=="statename") merge 1:1 statename using `"`geofolder'/state_database_clean"', nogen update replace |
| 15 | + else { |
| 16 | + di as error "with geography(state), geoid() must be 'state', 'statefips', 'statename', or blank" |
| 17 | + exit 198 |
| 18 | + } |
| 19 | + exit |
| 20 | + } |
| 21 | + |
| 22 | + if ("`map'"!="") { |
| 23 | + |
| 24 | + spmap `var' using `"`geofolder'/state_coords_clean"' `map_restriction', id(id) /// |
| 25 | + `legopt' legend(pos(5) size(*1.8)) /// |
| 26 | + clmethod(custom) /// |
| 27 | + clbreaks(`min' `clbreaks' `max') /// |
| 28 | + fcolor(`mapcolors') ndfcolor(`ndfcolor') /// |
| 29 | + oc(black ...) ndo(black) /// |
| 30 | + os(vthin ...) nds(vthin) /// |
| 31 | + `spopt' |
| 32 | + |
| 33 | + * Save graph |
| 34 | + if `"`savegraph'"'!="" { |
| 35 | + * check file extension using a regular expression |
| 36 | + if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0) |
| 37 | + |
| 38 | + * deal with different filetypes appropriately |
| 39 | + if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace' |
| 40 | + else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace' |
| 41 | + else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace' |
| 42 | + else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace' |
| 43 | + else graph export `"`savegraph'"', `replace' |
| 44 | + } |
| 45 | + |
| 46 | + } |
| 47 | + |
| 48 | +end |
0 commit comments