Apr 19, 2018

Random graphs (131): Scatterplot

sdmxuse data ESTAT, clear dataset(crim_pris_cap) dimensions(A.PRIS_ACT_CAP.P_HTHAB.)
drop unit indic_cr freq 
rename value prison
tempfile x
replace geo = "UK" if geo == "UKC-L"
save `x', replace

sdmxuse data ESTAT, clear dataset(spr_exp_sum) start(2008) end(2015) dimensions(A.TOTALNOREROUTE.PC_GDP..)
drop spdeps unit freq
rename value spending

merge 1:1 geo time using `x', keep(match) nogenerate
replace geo = "GR" if geo == "EL"

kountry geo, from(iso2c)
rename NAMES_STD country

regress prison spending if time == "2015"
local r2 = round(`e(r2)', .01) * 100
twoway (scatter prison spending if time == "2015", mlabel(country)) ///
       (lfit prison spending if time == "2015"), ///
        ytitle("Prison population per 100,000 inhabitants") ///
        xtitle("Total social spending as % of GDP") ///
        legend(order(2 "Linear fit, explained variance = `r2'%") pos(1) ring(0)) ///
        name(f2015, replace)