// Download data
wbopendata, clear long year(1990:2014) indicator(sh.xpd.publ.zs)
rename sh_xpd_publ_zs spending
rename iso2code country
label var spending "Health expenditure, public (% of GDP)"
// Group countries
gen lac = (inlist(country, "AR", "BS", "BB", "BZ", "BO", "BR", "CL") ///
| inlist(country, "CO", "CR", "CU", "DO", "EC", "SV", "GT") ///
| inlist(country, "GY", "HT", "HN", "JM", "MX", "NI", "PA") ///
| inlist(country, "PY", "PE", "SR", "TT", "UY", "VE"))
gen oecd = (inlist(country, "AT", "AU", "BE", "CA", "CZ", "DK", "EE") ///
| inlist(country, "FI", "FR", "DE", "HU", "IS", "IE", "IT") ///
| inlist(country, "JP", "LU", "NL", "NZ", "NO", "PL", "PT") ///
| inlist(country, "SK", "SI", "ES", "SE", "CH", "GB", "US"))
generate group = ""
replace group = "OECD" if oecd
replace group = "LAC" if lac
// Drop other countries and old data
drop if group == ""
drop if year < 1995
// Drop unnecessary variables
drop countrycode region regioncode
drop lac oecd
// Calculate average spending
sort group year country
*list, sepby(year)
bysort group year: egen avgspending = mean(spending)
*list, sepby(year)
// Calculate coefficient of variation
sort group year country
*list, sepby(year)
bysort group year: egen sdspending = sd(spending)
*list, sepby(year)
gen cvspending = (sdspending/avgspending) * 100
*list, sepby(year) abb(20)
// Calculate delta with respect to the country group
generate delta_group = (spending - avgspending) / sdspending
label var delta_group "Delta country group"
// Calculate delta with respect to the Netherlands
// Dutch spending per year
gen spending_nl = spending if country == "NL"
bysort year (spending_nl): replace spending_nl = spending_nl[_n-1] if missing(spending_nl)
// SD of Dutch spending
egen sdspending_nl = sd(spending) if country == "NL"
replace sdspending_nl = sdspending_nl[_n-1] if missing(sdspending_nl)
// Delta
generate delta_nl = (spending - spending_nl) / sdspending_nl
// Figure 5
capture drop figure5
generate figure5 = .
replace figure5 = 1 if country == "DK"
replace figure5 = 2 if country == "NL"
replace figure5 = 3 if country == "ES"
label define figure5 1 "Denmark" 2 "The Netherlands" 3 "Spain"
label value figure5 figure5
twoway line delta_nl year, by(figure5, col(1) note("") ixaxes iytitle l1title("") ///
title("Selected countries" "compared to The Netherlands")) ///
yscale(range(-3 3)) ylabel(-3 (1) 3, grid) xlabel(1995 2000 2005 2010 2014, tick) ///
l1title("") xsize(3) ysize(8) xtitle("") xmtick(1995/2014) name(figure5A, replace) ///
yline(0) nodraw
twoway line delta_group year, by(figure5, col(1) note("") ixaxes iytitle ///
title("Selected countries" "compared to OECD average") l1title("")) ///
yscale(range(-3 3)) ylabel(-3 (1) 3, grid) xlabel(1995 2000 2005 2010 2014, tick) ///
l1title("") xsize(3) ysize(8) xtitle("") xmtick(1995/2014) name(figure5B, replace) ///
yline(0) nodraw
graph combine figure5A figure5B, col(2) name(figure5, replace)
Apr 29, 2016
Random graphs (78): Line graphs using the -by- options
Labels:
bysort,
Random graphs,
Subscripting,
twoway line,
wbopendata
