Showing posts with label sdmxuse. Show all posts
Showing posts with label sdmxuse. Show all posts

Sep 26, 2018

Random graphs (140): Line plot

sdmxuse data OECD, clear dataset(FAMILY) dimensions(GBR.TOTAL.FAM3) start(1960) end(2018)
destring time, gen(year)
twoway line value year, xtitle("") ytitle("% of births outside of marriage")

Jul 12, 2018

Random graphs (133): Line plot

// Get divorce rate
sdmxuse data ESTAT, dataset(demo_ndivind) dimensions(A.DIVMARPCT.EU28) clear
drop freq
rename value divorce
tempname divorce
save `divorce', replace

// Get out-of-wedlock births
sdmxuse data ESTAT, dataset(demo_find) dimensions(A.NMARPCT.EFTA) clear
rename value emb

// Merge both data sets
merge 1:1 time using `divorce', nogenerate
destring time, replace

// Standardize
generate emb100 = (emb/5.6) * 100 // EMB in 1970
generate divorce100 = (divorce/11.3) * 100 // Divorce in 1970

// Plot
drop if time < 1970
twoway (line emb100 time) ///
       (line divorce100 time) ///
       (scatteri 410 2011 "Increase in divorce rate in Europe", msymbol(i) mlabpos(9)) ///
       (scatteri 679 2016 "Increase in extramarital birth rate in Europe", msymbol(i) mlabpos(9)) ///
      , ytitle("1970 = 100") xlabel(1970 (10) 2010) ylabel(100 (100) 700) xtitle("") legend(off) xsize(7)

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)

Feb 19, 2018

Random graphs (126): Turning tables into figures

sdmxuse data ESTAT, dataset(lfsa_epgar) start(2010) end(2010) clear

keep if inlist(geo, "AT", "BE", "BG", "CY", "CZ", "DK", "EE", "FI") ///
      | inlist(geo, "FR", "DE", "EL", "HU", "IE", "LT", "NL", "NO") ///
      | inlist(geo, "PL", "PT", "ES", "SE", "CH", "UK") 
keep if age == "Y_GE15"

replace geo = "GR" if geo == "EL"
kountry geo, from(iso2c)
rename NAMES_STD country

drop if sex == "T"
replace sex = "Men" if sex == "M"
replace sex = "Women" if sex == "F"
encode reason, gen(reasonno)
label var reasonno "Reasons for part-time work"

label define reasonno 1 "Care activities" ///
                      2 "Other personal reasons" ///
                      3 "Own illness, disability" 4 "Education, training" ///
                      5 "Could not find full-time job" 6 "Other", modify

replace value = value * 10
expand value
drop if missing(value)

tabplot reasonno country, by(sex, ///
                          note("{it:Note:} Bars and numbers indicate percentage of part-time workers per country" ///
                               "{it:Source:} Eurostat, lfsa_egpar, data refer to 2010.")) ///
                          percent(sex country) ///
                          showval(mlabsize(tiny) format(%6.0f)) xtitle("") ///
                          xlabel(, angle(vertical) labsize(small)) name(figure2, replace)

Feb 13, 2018

Random graphs (125): Bar graphs

clear
sdmxuse data ESTAT, dataset(lfsa_epgar)

keep if time == "2010"
keep if inlist(geo, "AT", "BE", "BG", "CY", "CZ", "DK", "EE", "FI") ///
      | inlist(geo, "FR", "DE", "EL", "HU", "IE", "LT", "NL", "NO") ///
      | inlist(geo, "PL", "PT", "ES", "SE", "CH", "UK") 
keep if age == "Y_GE15"

replace geo = "GR" if geo == "EL"
kountry geo, from(iso2c)
rename NAMES_STD country

drop if sex == "T"
replace sex = "Men" if sex == "M"
replace sex = "Women" if sex == "F"
encode reason, gen(reasonno)
label define reasonno 1 "Looking after children or incapacitated adults" ///
                      2 "Other family or personal responsibilities" ///
                      3 "Own illness or disability" 4 "In education or training" ///
                      5 "Could not find a full-time job" 6 "Other", modify
twoway bar value reasonno, horizontal by(country sex, ///
           cols(4) note("{it:Source:} Eurostat, lfsa_epgar, 2010. Respondents 15 years or older.", size(vsmall)) ///
     title("Reasons for part-time work")) ///
           ylabel(1/6, val)  ///
           ytitle("") xtitle("% of part-time workforce") ysize(12) xsize(8) 

Dec 2, 2017

Random graphs (120): Uncluttered line plots

// Use OECD data
sdmxuse data OECD, dataset(IDD) clear attributes

// Generate country variable
kountry location, from(iso3c)
rename NAMES_STD country

// Generate year variable
destring time, gen(year)

// Keep relevant data
keep if measure == "GINI"
keep if age == "TOT"
keep if definition == "CURRENT"
keep if inlist(country, "Netherlands", "Germany", "United Kingdom", "United States")
drop if methodo == "METH2012"

sort country year
twoway (connected value year if country == "Germany") ///
       (line value year if country == "Netherlands", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United Kingdom", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United States", lcolor(gs10) lpattern(solid)) ///
      , legend(off) name(pa, replace) title(Germany) xtitle("") ytitle("Income inequality") ///
        ylabel(, format(%6.2f)) 
twoway (connected value year if country == "Netherlands") ///
       (line value year if country == "Germany", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United Kingdom", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United States", lcolor(gs10) lpattern(solid)) ///
      , legend(off) name(pb, replace) title(Netherlands) xtitle("") ytitle("Income inequality") ///
        ylabel(, format(%6.2f)) 
twoway (connected value year if country == "United Kingdom") ///
       (line value year if country == "Germany", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "Netherlands", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United States", lcolor(gs10) lpattern(solid)) ///
      , legend(off) name(pc, replace) title(United Kingdom) xtitle("") ytitle("Income inequality") ///
        ylabel(, format(%6.2f)) 
twoway (connected value year if country == "United States") ///
       (line value year if country == "Germany", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "Netherlands", lcolor(gs10) lpattern(solid)) ///
       (line value year if country == "United Kingdom", lcolor(gs10) lpattern(solid)) ///
      , legend(off) name(pd, replace) title(United States) xtitle("") ytitle("Income inequality") ///
        ylabel(, format(%6.2f))
    
graph combine pa pb pc pd, col(2) name(fig1, replace)

Jul 28, 2017

Random graphs (107): Line plot using -sdmxuse-


// Download data
sdmxuse data ESTAT, dataset(lfsi_grt_a) clear attributes

// Select desired timelines
keep if indic_em == "SERV_RT"
keep if sex == "T"
destring time, gen(year)
rename value percserv

// Plot
twoway ///
       (line percserv year if geo == "UK") ///
       (line percserv year if geo == "NL") ///
       (line percserv year if geo == "SE") ///
       (line percserv year if geo == "DE") ///
       (line percserv year if geo == "FI") ///
       (line percserv year if geo == "PT") ///
       (line percserv year if geo == "HU") ///
       (line percserv year if geo == "BG"), ///
       legend(order(1 "United Kingdom" 2 "The Netherlands" ///
                    3 "Sweden" 4 "Germany" 5 "Finland" ///
                    6 "Portugal" 7 "Hungary" 8 "Bulgaria") pos(2)) ///
       xtitle("") ytitle("Percentage of workforce in the service sector") ///
       xlabel(1992 1995(5) 2010 2014) ///
       note(" " "{it:Source:} Eurostat, lfsi_grt_a, date of extraction: 2017-07-27", span)