// 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})
Showing posts with label European Values Study. Show all posts
Showing posts with label European Values Study. Show all posts
Jun 16, 2017
Random graphs (97): Choropleth map
Labels:
Choropleth map,
European Values Study,
keep,
Random graphs,
shp2dta,
spmap
Aug 18, 2015
Random Graphs (50): Dot graphs with confidence intervals
// Create temporary object
tempname bqlrer
// Define postfile
postfile `bqlrer' count str100 commandline str100 descri str10 entity ///
prev prev_loci prev_hici differ differ_loci differ_hici ///
loed mide hied ratio_ ratio_loci ratio_hici n ///
using "results\results", replace
// Count variable
local count = 0
// Levels for loop
levelsof entity, local(entity_levels)
*di `entity_levels'
// Loop: 1 round per entity
foreach Y of local entity_levels {
local entity_level = "`Y'"
di "`entity_level'"
*qui sum poorhealth if entity == "`Y'"
*scalar proportion = r(mean)
// Model 1: OV: PSRH lowest2, adjusted -- Prevalence rate only, education not in model
qui logit poorhealth c_age c_female if entity == "`Y'"
di _rc
if _rc == 0 {
*prev prev_loci prev_hici
qui margins if entity == "`Y'", post
scalar prev = 100 * _b[_cons]
scalar prev_loci = 100 * (_b[_cons] - 1.96 * _se[_cons])
scalar prev_hici = 100 * (_b[_cons] + 1.96 * _se[_cons])
di `prev'
di `prev_loci'
di `prev_hici'
}
// Model 2: OV: PSRH lowest2, adjusted
local count = `count' + 1
local desc "DV: Poor health (bottom 2), IV: Education, Age, Sex"
qui logit poorhealth i.education c_age c_female if entity == "`Y'"
local commandline = e(cmdline)
di _rc
if _rc == 0 {
// Differences Model 2
qui margins r.education if entity == "`Y'"
scalar differ = -10 * _b[r3vs1.education]
scalar differ_loci = -10 * (_b[r3vs1.education] + (1.96 * _se[r3vs1.education]))
scalar differ_hici = -10 * (_b[r3vs1.education] - (1.96 * _se[r3vs1.education]))
// Predicted probabilities Model 2
qui margins i.education if entity == "`Y'", post
matrix preds = r(table)
scalar loed = preds[1,1]
scalar mide = preds[1,2]
scalar hied = preds[1,3]
matrix drop preds
// Ratios Model 2
qui nlcom _b[1.education]/_b[3.education], post
scalar ratio_ = _b[_nl_1]
scalar ratio_loci = _b[_nl_1] - 1.96 * _se[_nl_1]
scalar ratio_hici = _b[_nl_1] + 1.96 * _se[_nl_1]
}
else {
scalar differ = -99
scalar differ_loci = -99
scalar differ_hici = -99
scalar ratio_ = -99
scalar ratio_loci = -99
scalar ratio_hici = -99
scalar loed = -99
scalar mide = -99
scalar hied = -99
}
post `bqlrer' (`count') (`"`commandline'"') ("`desc'") ("`Y'") ///
(prev) (prev_loci) (prev_hici) ///
(differ) (differ_loci) (differ_hici) ///
(loed) (mide) (hied) ///
(ratio_) (ratio_loci) (ratio_hici) (e(N))
}
// Fit one model for entire EVS
// Model 1: OV: PSRH lowest2, adjusted -- Prevalence rate only, education not in model
qui logit poorhealth c_age c_female [pw = eu_weight] if survey == "EVS"
qui margins if survey == "EVS", post
scalar prev = 100 * _b[_cons]
scalar prev_loci = 100 * (_b[_cons] - 1.96 * _se[_cons])
scalar prev_hici = 100 * (_b[_cons] + 1.96 * _se[_cons])
di `prev'
di `prev_loci'
di `prev_hici'
// Model 2: OV: PSRH lowest2, adjusted
local count = `count' + 1
local desc "DV: Poor health (bottom 2), IV: Education, Age, Sex"
qui logit poorhealth i.education c_age c_female /*[pw = eu_weight]*/ if survey == "EVS"
local commandline = e(cmdline)
// Differences Model 2
qui margins r.education if survey == "EVS"
scalar differ = -10 * _b[r3vs1.education]
scalar differ_loci = -10 * (_b[r3vs1.education] + (1.96 * _se[r3vs1.education]))
scalar differ_hici = -10 * (_b[r3vs1.education] - (1.96 * _se[r3vs1.education]))
// Predicted probabilities Model 2
qui margins i.education if survey == "EVS", post
matrix preds = r(table)
scalar loed = preds[1,1]
scalar mide = preds[1,2]
scalar hied = preds[1,3]
matrix drop preds
// Ratios Model 2
qui nlcom _b[1.education]/_b[3.education], post
scalar ratio_ = _b[_nl_1]
scalar ratio_loci = _b[_nl_1] - 1.96 * _se[_nl_1]
scalar ratio_hici = _b[_nl_1] + 1.96 * _se[_nl_1]
local Y = "EVS"
post `bqlrer' (`count') (`"`commandline'"') ("`desc'") ("`Y'") ///
(prev) (prev_loci) (prev_hici) ///
(differ) (differ_loci) (differ_hici) ///
(loed) (mide) (hied) ///
(ratio_) (ratio_loci) (ratio_hici) (e(N))
postclose `bqlrer'
// Create data set with FIPS codes and state names
preserve
tempfile codescheme
egen pickone = tag(entity)
keep if pickone
keep entity entity_num
save `codescheme'
restore
// Merge FIPS codes to results
use results\results, clear
merge 1:1 entity using `codescheme', keepusing(entity entity_num)
drop _merge
label var count "Generic counter"
label var commandline "Command line"
label var descri "Description of model fitted"
label var entity "Entity (string)"
label var prev "Proportion poor health"
label var prev_loci "Proportion 95 % CI (lower)"
label var prev_hici "Proportion 95 % CI (higher)"
label var loed "Proportion poor health lower educ."
label var mide "Proportion poor health mid educ."
label var hied "Proportion poor health higher educ."
label var differ "Difference lower educated - higher"
label var differ_loci "Difference 95 % CI (lower)"
label var differ_hici "Difference 95 % CI (higher)"
label var ratio_ "Ratio lower educated / higher"
label var ratio_loci "Ratio 95 % CI (lower)"
label var ratio_hici "Ratio 95 % CI (higher)"
label var n "Size of entity sample"
// Save results, also as csv-file
save results\results, replace
outsheet using "results\results.csv", comma replace nolabel
use results\results, replace
// Create US identifier
gen usa = 0
replace usa = 1 if regexm(entity, "US-")
replace entity = "{bf:Europe}" if entity == "EVS"
egen order_ratio = rank(-ratio_), unique
labmask order_ratio, value(entity)
egen order_differ = rank(-differ), unique
labmask order_differ, value(entity)
egen order_prev = rank(-prev), unique
labmask order_prev, value(entity)
twoway (dot prev order_prev if usa == 0, horizontal ndots(20)) ///
(dot prev order_prev if usa == 1, horizontal ndots(20)) ///
(rspike prev_loci prev_hici order_prev, horizontal) ///
, ///
legend(label(1 "Europe") label(2 "US") label(3 "95% CI") pos(1) ring(0)) ///
ylabel(1/97, valuelabels ang(h) labsize(*.65)) ///
ytitle("") ///
xtitle("Prevalence poor health") ///
name(prevalence, replace) ///
xsize(2.7) ysize(10)
generate ratio_loci_p = ratio_loci // Shorten CI's to make graph fit better
replace ratio_loci_p = 0 if ratio_loci_p < 0
generate ratio_hici_p = ratio_hici
replace ratio_hici_p = 6 if ratio_hici_p > 6
twoway (dot ratio_ order_ratio if usa == 0, horizontal ndots(20) msymbol(smplus)) ///
(dot ratio_ order_ratio if usa == 1, horizontal ndots(20) msymbol(smx)) ///
(rspike ratio_loci_p ratio_hici_p order_ratio, horizontal) ///
, ///
legend(label(1 "Europe") label(2 "US") label(3 "95 % CI") pos(1) ring(0)) ///
ylabel(1/97, valuelabels ang(h) labsize(*.65)) ///
xscale(range(0 6)) xlabel(0 1 3 5) ///
ytitle("") ///
xtitle("Relative" "inequalities") ///
xline(1) ///
xline(1.81019, lpattern(dash)) ///
name(relative, replace) ///
xsize(2.7) ysize(10)
generate differ_loci_p = differ_loci // Shorten CI's to make graph fit better
replace differ_loci_p = -1 if differ_loci_p < -1
twoway (dot differ order_differ if usa == 0, horizontal ndots(20) msymbol(smplus)) ///
(dot differ order_differ if usa == 1, horizontal ndots(20) msymbol(smx)) ///
(rspike differ_loci_p differ_hici order_differ, horizontal) ///
, ///
legend(label(1 "Europe") label(2 "US") label(3 "95 % CI") pos(1) ring(0)) ///
xscale(range(0 30)) xlabel(0(10)30) ///
ylabel(1/97, valuelabels ang(h) labsize(*.65)) ///
ytitle("") ///
xtitle("Absolute" "inequalities") ///
xline(6.8754, lpattern(dash)) ///
name(absolute, replace) ///
xsize(2.7) ysize(10)
twoway (dot prev order_prev if usa == 0, horizontal ndots(20) msymbol(smplus)) ///
(dot prev order_prev if usa == 1, horizontal ndots(20) msymbol(smx)) ///
(rspike prev_loci prev_hici order_prev, horizontal) ///
, ///
legend(label(1 "Europe") label(2 "US") label(3 "95% CI") row(1) pos(12) size(vsmall) region(lwidth(vthin) lcolor(black)) bmargin(tiny) colgap(*.3)) ///
ylabel(1/97, valuelabels ang(h) labsize(*.65)) ///
ytitle("") ///
xtitle("Prevalence" "poor health") ///
xline(11.26938, lpattern(dash)) ///
name(prevalence_leg, replace) ///
xsize(2.7) ysize(10)
// 8.27 × 11.69
*graph combine prevalence absolute relative, xsize(8.27) ysize(10) col(3) name(comb, replace)
grc1leg prevalence_leg absolute relative, xsize(8.27) ysize(10) col(3) imargin(small) legendfrom(prevalence_leg) name(oneleg, replace) pos(6) span // ignores size-commands
graph display oneleg, xsize(6.27) ysize(9.69) // Thus redraw so that size commands take effect
Subscribe to:
Posts (Atom)

