// Calculate country data
use v9 weight_g c_abrv using ZA4800_v3-0-0.dta, clear
gen cntry = substr(c_abrv, 1, 2)
gen poorhealth = (inlist(v9, 4, 5) *100) if !missing(v9)
collapse poorhealth [pweight = weight_g], by(cntry)
label var poorhealth "Poor health"
format poorhealth %6.1f // Determine no. of decimal points
saveold poorhealth, replace
// Read in map data
// Source: shapefile from http://www.naturalearthdata.com/downloads/10m-cultural-vectors/
shp2dta using "ne_10m_admin_0_countries", database(database) coordinates(coordinates) genid(id) replace
// Restrict coordinates to Europe
// Source: https://en.wikipedia.org/wiki/Extreme_points_of_Europe
use coordinates, clear
replace _Y = . if _Y < 36
replace _Y = . if _Y > 71 & !missing(_Y)
replace _X = . if _X < -28
replace _X = . if _X > 33 & !missing(_X)
saveold europecoordinates, replace
// Create data set with Europe internal borders
clonevar id = _ID
merge m:1 id using database, nogenerate
keep if CONTINENT == "Europe"
saveold europe, replace
// Merge map data with set with data to be plotted
use ISO_A2 NAME id using database, clear
rename ISO_A2 cntry
replace cntry = "FR" if NAME == "France" // Somehow not correct in map
replace cntry = "NO" if NAME == "Norway" // Somehow not correct in map
drop if cntry == "-99"
merge 1:1 cntry using poorhealth, keep(matched) nogenerate
spmap poorhealth using europecoordinates, id(id) xsize(6) ysize(4) ///
polygon(data(europe)) legstyle(2) clnumber(5) fcolor(Terrain) ///
legend(position (9) ring(0)) ///
legorder(hilo) ocolor(none ..) ///
legtitle("% poor health") legjunction({c 150})
Jun 16, 2017
Random graphs (97): Choropleth map
Labels:
Choropleth map,
European Values Study,
keep,
Random graphs,
shp2dta,
spmap
