Jul 10, 2017

Random graphs (101): Sparklines

import delimited une_rt_a_1_Data.csv, clear

/*
DATASET: Unemployment by sex and age - annual average [une_rt_a]
LAST UPDATE: 03.07.17 07:40:41
EXTRACTION DATE: 09.07.17 23:38:36
SOURCE OF DATA: Eurostat
*/

drop if geo == "United States"
keep if unit == "Percentage of active population"
drop sex age unit flagandfootnotes


// Generate country variable
kountry geo, from(other) stuck 
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ cntry
replace cntry = "UK" if cntry == "GB"

// Fix unemployment rate
replace value = "" if value == ":"          // Fix missing data indicator 
destring value, replace                     // Convert to numeric

// Line plot
twoway (line value time), by(geo,  ///
                             note(" " "{it: Source:} Eurostat, une_rt_a, date of extraction: 2017-07-09", span)) ///
                          xlabel(1990 (10) 2010) xtick(1987 (1) 2016) xmtick(1990 (5) 2015) ///
                          xtitle("") ytitle("Male unemployment rate, 25-74 y.") ///
                          name(byplot, replace)

twoway (line value time if cntry == "ES")  ///
       (line value time if cntry == "FR")  ///
       (line value time if cntry == "IE")  ///
       (line value time if cntry == "BE")  ///
       (line value time if cntry == "NL")  ///
       (line value time if cntry == "UK")  ///
      , legend(order(1 "Spain" 2 "France" 3 "Ireland" ///
                     4 "Belgium" 5 "Netherlands" 6 "UK")) ///
        note(" " "{it: Source:} Eurostat, une_rt_a, date of extraction: 2017-07-09", span) ///
        xlabel(1990 (5) 2015) xmtick(1987 (1) 2016) ///
        xtitle("") ytitle("Male unemployment rate, 25-74 y.") ///
        name(lineplot, replace)
   
// Sparklines
sparkline value time, over(geo) xlabel(1990 (5) 2015) xmtick(1987 (1) 2016) ///
                      ytitle("") xtitle("") title("Male unemployment rate, 25-74 y.") ///
                      subtitle("") ///
                      note(" " "{it: Source:} Eurostat, une_rt_a, date of extraction: 2017-07-09", span) ///
                      name(sparklines, replace) 

graph combine sparklines byplot lineplot, col(1) ysize(15) xsize(6)