// 1) Download data:
sdmxuse data ESTAT, dataset(ilc_di12) clear attributes
destring time, gen(year)
// Generate country name variable
replace geo = "GR" if geo == "EL"
kountry geo, from(iso2c) marker
rename NAMES_STD country
replace country = "Croatia" if country == "Yugoslavia"
drop if MARKER == 0 // Drop EU-28 etc. entries
drop if country == "European Union"
drop MARKER
// Identify EU-15
generate eu15 = (inlist(geo, "AT", "BE", "DK", "FI", "FR", "DE", "GR", "IE") ///
| inlist(geo, "IT", "LU", "NL", "PT", "ES", "SE", "UK"))
sparkline value year if eu15, over(country) ysize(10) ///
note(" " "{it: Source:} Eurostat, ilc_di12, date of extraction: 2017-07-10", span) ///
xlabel(1995 (10) 2015) xmtick(1995 (5) 2015) ///
xtick(1995 (1) 2016) ///
ytitle(" ") xtitle("") ///
title("Income inequality") ///
subtitle("(Gini of equivalised disposable income)") ///
name(regular, replace)
// 2) Download data as time series:
sdmxuse data ESTAT, dataset(ilc_di12) clear timeseries
destring time, gen(year)
twoway (scatter gini_hnd_uk_a year, connect(L)) ///
(scatter gini_hnd_de_a year, connect(L)) ///
, xtitle("") ///
ytitle("Income inequality" ///
"(Gini of equivalised disposable income)") ///
xlabel(1995 (5) 2015) xtick(1995 (1) 2015) ///
ylabel(25 (5) 35) ytick(25 (1) 35) ///
note(" " "{it: Source:} Eurostat, ilc_di12, date of extraction: 2017-07-10", span) ///
legend(order(1 "United Kingdom" 2 "Germany") pos(5) ring(0)) ///
name(timeseries, replace)
Showing posts with label sparkline. Show all posts
Showing posts with label sparkline. Show all posts
Jul 10, 2017
Using -sdmxuse- to download Eurostat data
Labels:
Eurostat data,
kountry,
smdxuse,
sparkline,
twoway scatter
Random graphs (102): Sparklines
use v151 year ost_west if ost_west == 1 using ZA4582_v1-0-0.dta, clear
// Year
label drop year
label var year ""
// Subjective social class
recode v151 (9 = .a "No response") ///
(8 = .b "Don't know") ///
(7 = .c "Refused") ///
(6 = .d "None of the strata") ///
(5 = 5 "Upper class") ///
(4 = 4 "Upper middle class") ///
(3 = 3 "Middle class") ///
(2 = 2 "Working class") ///
(1 = 1 "Lower class") ///
, gen(subjclass)
label var subjclass "Subjective social class"
qui tab subjclass, gen(subjx)
// Change value labels in bulk
foreach var of varlist subjx* {
local lab `: var label `var''
local lab `: di subinstr("`lab'", "subjclass==", " ", 1)'
label var `var' "`lab'"
}
// Collapse data set
// Copy variable labels before collapse
// Following:
// http://www.stata.com/support/faqs/data-management/keeping-same-variable-with-collapse/
foreach var of var subjx* {
local l`var' : variable label `var'
if `"`l`var''"' == "" {
local l`var' "`var'"
}
}
// Collapse
collapse subjx*, by(year)
// Restore value labels after collapse
foreach var of var subjx* {
label var `var' "`l`var''"
}
// Change to percentages
foreach var of var subjx* {
replace `var' = `var' * 100
}
// Sparklines
sparkline subjx* year, variablelabels xlabel(1980 (10) 2010) xmtick(1980 (2) 2014) ///
xtitle("") format(%6.1f) extremes ///
title("Subjective social class in Western Germany", span) ///
name(subjclass, replace)
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)
Labels:
Eurostat data,
kountry,
Random graphs,
sparkline,
twoway line
Subscribe to:
Posts (Atom)



