Skip to content

Commit abe06a7

Browse files
author
Michael Stepner
committed
Merge branch 'release/0.70beta1'
2 parents 88e77df + f79dce1 commit abe06a7

19 files changed

Lines changed: 1356 additions & 412 deletions

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
map_shapefiles/
2-
map_shapefiles_creation_code/
3-
raw_data/
1+
map_shapefiles/*.dta
2+
raw_data/
3+
tests/

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
maptile: simple mapping in Stata
2+
--------------------------------
3+
4+
[See the project webpage for more information.](http://michaelstepner.com/maptile "maptile: a Stata program that makes mapping easy")

UNLICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com
2+
3+
program define _maptile_county1990
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+
stateoutline ///
9+
]
10+
11+
if ("`mergedatabase'"!="") {
12+
merge 1:m county using `"`geofolder'/county1990_database_clean"', nogen update replace
13+
exit
14+
}
15+
16+
if ("`map'"!="") {
17+
18+
if ("`stateoutline'"!="") {
19+
cap confirm file `"`geofolder'/state_coords_clean.dta"'
20+
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
21+
else if (_rc==601) {
22+
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
exit 198
24+
}
25+
else {
26+
error _rc
27+
exit _rc
28+
}
29+
}
30+
31+
spmap `var' using `"`geofolder'/county1990_coords_clean"' `map_restriction', id(id) ///
32+
`legopt' legend(pos(5) size(*1.8)) ///
33+
clmethod(custom) ///
34+
clbreaks(`min' `clbreaks' `max') ///
35+
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
36+
oc(black ...) ndo(black) ///
37+
os(vvthin ...) nds(vvthin) ///
38+
`polygon' ///
39+
`spopt'
40+
41+
* Save graph
42+
if `"`savegraph'"'!="" {
43+
* check file extension using a regular expression
44+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45+
46+
* deal with different filetypes appropriately
47+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51+
else graph export `"`savegraph'"', `replace'
52+
}
53+
54+
}
55+
56+
end

map_shapefiles/cz_maptile.ado

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com
2+
3+
program define _maptile_cz
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+
stateoutline ///
9+
]
10+
11+
if ("`mergedatabase'"!="") {
12+
merge 1:m cz using `"`geofolder'/cz_database_clean"', nogen
13+
exit
14+
}
15+
16+
if ("`map'"!="") {
17+
18+
if ("`stateoutline'"!="") {
19+
cap confirm file `"`geofolder'/state_coords_clean.dta"'
20+
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
21+
else if (_rc==601) {
22+
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
exit 198
24+
}
25+
else {
26+
error _rc
27+
exit _rc
28+
}
29+
}
30+
31+
spmap `var' using `"`geofolder'/cz_coords_clean"' `map_restriction', id(id) ///
32+
`legopt' legend(pos(5) size(*1.8)) ///
33+
clmethod(custom) ///
34+
clbreaks(`min' `clbreaks' `max') ///
35+
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
36+
oc(black ...) ndo(black) ///
37+
os(vvthin ...) nds(vvthin) ///
38+
`polygon' ///
39+
`spopt'
40+
41+
* Save graph
42+
if `"`savegraph'"'!="" {
43+
* check file extension using a regular expression
44+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45+
46+
* deal with different filetypes appropriately
47+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51+
else graph export `"`savegraph'"', `replace'
52+
}
53+
54+
}
55+
56+
end

map_shapefiles/state_maptile.ado

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

map_shapefiles/zip3_maptile.ado

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com
2+
3+
program define _maptile_zip3
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+
stateoutline ///
9+
]
10+
11+
if ("`mergedatabase'"!="") {
12+
merge 1:m zip3 using `"`geofolder'/zip3_database_clean"', nogen
13+
exit
14+
}
15+
16+
if ("`map'"!="") {
17+
18+
if ("`stateoutline'"!="") {
19+
cap confirm file `"`geofolder'/state_coords_clean.dta"'
20+
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
21+
else if (_rc==601) {
22+
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
exit 198
24+
}
25+
else {
26+
error _rc
27+
exit _rc
28+
}
29+
}
30+
31+
spmap `var' using `"`geofolder'/zip3_coords_clean"' `map_restriction', id(id) ///
32+
`legopt' legend(pos(5) size(*1.8)) ///
33+
clmethod(custom) ///
34+
clbreaks(`min' `clbreaks' `max') ///
35+
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
36+
oc(black ...) ndo(black) ///
37+
os(vvthin ...) nds(vvthin) ///
38+
`polygon' ///
39+
`spopt'
40+
41+
* Save graph
42+
if `"`savegraph'"'!="" {
43+
* check file extension using a regular expression
44+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45+
46+
* deal with different filetypes appropriately
47+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51+
else graph export `"`savegraph'"', `replace'
52+
}
53+
54+
}
55+
56+
end

map_shapefiles/zip5_maptile.ado

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
*! 31jan2014, Michael Stepner, michaelstepner@gmail.com
2+
3+
program define _maptile_zip5
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+
stateoutline ///
9+
]
10+
11+
if ("`mergedatabase'"!="") {
12+
merge 1:m zip5 using `"`geofolder'/zip5_database_clean"', nogen update replace
13+
exit
14+
}
15+
16+
if ("`map'"!="") {
17+
18+
if ("`stateoutline'"!="") {
19+
cap confirm file `"`geofolder'/state_coords_clean.dta"'
20+
if (_rc==0) local polygon polygon(data(`"`geofolder'/state_coords_clean"') ocolor(black) osize(thin ...))
21+
else if (_rc==601) {
22+
di as error `"stateoutline option requires 'state_coords_clean.dta' in the geofolder"'
23+
exit 198
24+
}
25+
else {
26+
error _rc
27+
exit _rc
28+
}
29+
}
30+
31+
spmap `var' using `"`geofolder'/zip5_coords_clean"' `map_restriction', id(id) ///
32+
`legopt' legend(pos(5) size(*1.8)) ///
33+
clmethod(custom) ///
34+
clbreaks(`min' `clbreaks' `max') ///
35+
fcolor(`mapcolors') ndfcolor(`ndfcolor') ///
36+
oc(black ...) ndo(black) ///
37+
os(vvthin ...) nds(vvthin) ///
38+
`polygon' ///
39+
`spopt'
40+
41+
* Save graph
42+
if `"`savegraph'"'!="" {
43+
* check file extension using a regular expression
44+
if regexm(`"`savegraph'"',"\.[a-zA-Z0-9]+$") local graphextension=regexs(0)
45+
46+
* deal with different filetypes appropriately
47+
if inlist(`"`graphextension'"',".gph","") graph save `"`savegraph'"', `replace'
48+
else if inlist(`"`graphextension'"',".ps",".eps") graph export `"`savegraph'"', mag(`=round(100*`resolution')') `replace'
49+
else if (`"`graphextension'"'==".png") graph export `"`savegraph'"', width(`=round(3200*`resolution')') `replace'
50+
else if (`"`graphextension'"'==".tif") graph export `"`savegraph'"', width(`=round(1600*`resolution')') `replace'
51+
else graph export `"`savegraph'"', `replace'
52+
}
53+
54+
}
55+
56+
end

map_shapefiles_creation_code/generate_cz_shapefile.do

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
* generate_cz_shapefile.do: Merges 1990 County shapefile into a 1990 CZ shapefile
2+
3+
*** Version history:
4+
* 2014-01-31, Michael Stepner
5+
* 2013-07-14, Michael Stepner
6+
* 2013-07-05, Michael Stepner* 2013-04-15, Shelby Lin/*******************************
7+
8+
** DEPENDENCIES **
9+
- mergepoly.ado, installed from SSC by running: ssc install mergepoly
10+
11+
** INPUT FILES **
12+
- cw_cty_czone.dta
13+
Provided by David Dorn at http://www.cemfi.es/~dorn/data.htm -- file [E6]
14+
- county1990_database_clean.dta & county1990_coords_clean.dta
15+
Based on source file "co99_d90_shp.zip", provided by U.S. Census Bureau at http://www.census.gov/geo/maps-data/data/cbf/cbf_counties.html
16+
Generated by "import_county1990_shapefile.do"
17+
** OUTPUT FILES **- cz_database_clean.dta- cz_coords_clean.dta*******************************/
18+
global root "/Users/michael/Documents/git_repos/maptile"
19+
global raw "$root/raw_data"
20+
global out "$root/map_shapefiles"
21+
global code "$root/map_shapefiles_creation_code"
22+
set more off
23+
24+
25+
*** Step 1: Use Dorn County -> CZ crosswalk to merge CZ variable onto county database
26+
use "$raw/cw_cty_czone.dta", clear
27+
rename cty_fips county
28+
rename czone cz
29+
keep county cz
30+
31+
merge 1:m county using "$out/county1990_database_clean", assert(3) nogen
32+
compress
33+
34+
35+
*** Step 2: Merge county polygons into CZs
36+
37+
mergepoly id using "$out/county1990_coords_clean", ///
38+
coordinates("$out/cz_coords_clean.dta") ///
39+
by(cz) replace
40+
save "$out/cz_database_clean.dta", replace

0 commit comments

Comments
 (0)