Showing posts with label Eurostat data. Show all posts
Showing posts with label Eurostat data. Show all posts

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) 

Sep 7, 2017

Random graphs (112): Line plot

clear 
// Open Eurostat data
unzipfile "macrodata\lfsi_pt_a.zip"
insheet using lfsi_pt_a_1_Data.csv

// Prepare variables
replace value = "." if value == ":"
destring value, gen(fixedterm)
rename time year
replace geo = "France" if geo == "France (metropolitan)"
kountry geo, from(other) stuck
rename _ISO3N_ country
kountry country, from(iso3n) to(iso2c)
rename _ISO2C_ cntry

// Select data and save
keep if year >= 2004
keep fixedterm geo year cntry
save lfs_fixedterm, replace

// Open ESS data
use essround agea mnact wrkctra pspwght cntry using ESS1-7e01, clear

// Select data
keep if essround >= 2
keep if inrange(agea, 20, 64)
keep if mnact == 1

// Prepare variables
generate ess_fixedterm = (wrkctra == 2)
replace  ess_fixedterm = (ess_fixedterm * 100)
generate year = 2004 if essround == 2
replace  year = 2006 if essround == 3
replace  year = 2008 if essround == 4
replace  year = 2010 if essround == 5
replace  year = 2012 if essround == 6
replace  year = 2014 if essround == 7

// Point estimates and standard errors
statsby ess_fixedterm = _b[_cons] se = _se[_cons], clear by(cntry year): regress ess_fixedterm

// Merge Eurostat data with ESS data
merge 1:1 cntry year using lfs_fixedterm

// Select countries 
drop if inlist(cntry, "RU", "IL", "UA", "LV", "MK", "MT", "RO")

// Generate country name variable
kountry cntry, from(iso2c) 
ren NAMES_STD country

// Calculate confidence intervals
generate lb = ess_fixedterm - 1.96 * se
generate ub = ess_fixedterm + 1.96 * se

// Plot figure
sort year
twoway (rarea ub lb year, lcolor(white)) ///
       (connected ess_fixedterm year) ///
       (line fixedterm year), by(country, note("")) ///
        xtitle("") ytitle("Percentage of total employed (20{c 150}64 y)" "on temporary contract") ///
        legend(order(2 "ESS" 1 "95% CI" 3 "Eurostat") row(1)) xlabel(2004 (2) 2014)


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)

Jul 10, 2017

Using -sdmxuse- to download Eurostat data


// 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)

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)

Jun 20, 2017

Random graphs (100): Labeling lines directly

import delimited une_rt_a_1_Data.csv, clear

/*
DATASET: Unemployment by sex and age - annual average [une_rt_a]
LAST UPDATE: 14.06.17 13:10:19
EXTRACTION DATE: 18.06.17 11:35:33
SOURCE OF DATA: Eurostat
*/

drop sex age unit flagandfootnotes

// Generate country variable
kountryadd "Germany (until 1990 former territory of the FRG)" to "Germany" add
kountry geo, from(other) stuck marker
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ country_str
replace country_str = "UK" if country_str == "GB"
list country_str geo

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

twoway (line value time if country_str == "UK") ///
       (line value time if country_str == "US") ///
       (scatteri 4 2016 "United States" 3.5 2016 "United Kingdom", msymbol(none)) ///
      , legend(off) ///
        xtitle("") ytitle("Male unemployment rate, 25-74 y.") ///
        xlabel(1985(5)2015) ///
        xscale(range(1983 2023)) ///
        note(" " "{it: Source:} Eurostat, une_rt_a, date of extraction: 2017-06-18", span)

Jun 18, 2017

Random graphs (98): Shaded areas

import delimited une_rt_a_1_Data.csv, clear

/*
DATASET: Unemployment by sex and age - annual average [une_rt_a]
LAST UPDATE: 14.06.17 13:10:19
EXTRACTION DATE: 18.06.17 11:35:33
SOURCE OF DATA: Eurostat
*/

drop sex age unit flagandfootnotes

// Generate country variable
kountryadd "Germany (until 1990 former territory of the FRG)" to "Germany" add
kountry geo, from(other) stuck marker
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ country_str
replace country_str = "UK" if country_str == "GB"
list country_str geo

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

// Plot
twoway (scatteri 12 2008 12 2012, recast(area) bcolor(gs14)) ///
       (line value time if country_str == "UK") ///
       (line value time if country_str == "DE") ///
       (line value time if country_str == "US") ///
      , legend(order(2 "UK" 3 "Germany" 4 "US") ///
               pos(7) ring(0)) ///
        xtitle("") ytitle("Male unemployment rate, 25-74 y.") xtick(1983(1)2016) ///
        xlabel(1985(5)2015) ///
        note(" " "{it: Source:} Eurostat, une_rt_a, date of extraction: 2017-06-18", span)

Dec 1, 2016

Random graphs (92): Line plot

import delimited "lfsi_grt_a_1_Data.csv", clear

replace value = "" if value == ":"

destring value, gen(percserv)

twoway ///
       (line percserv time if geo == "United Kingdom") ///
       (line percserv time if geo == "Netherlands") ///
       (line percserv time if geo == "Sweden") ///
       (line percserv time if geo == "Germany (until 1990 former territory of the FRG)") ///
       (line percserv time if geo == "Finland") ///
       (line percserv time if geo == "Portugal") ///
       (line percserv time if geo == "Hungary") ///
       (line percserv time if geo == "Bulgaria"), ///
       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: 2016-12-01", span)

Feb 22, 2016

Random graphs (60): Line plots

import delimited C:\internet\isoc_bdek_di_1_Data.csv, clear

// Generate country variable
kountryadd "Germany (until 1990 former territory of the FRG)" to "Germany" add
kountry geo, from(other) stuck marker
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ country_str
replace country_str = "UK" if country_str == "GB"

replace country_str = "EU25" if geo == "European Union (25 countries)"
replace country_str = "EU27" if geo == "European Union (27 countries)"
replace country_str = "EU28" if geo == "European Union (28 countries)"
replace country_str = "EU15" if geo == "European Union (15 countries)"
drop if geo == "Euro area (EA11-2000, EA12-2006, EA13-2007, EA15-2008, EA16-2010, EA17-2013, EA18-2014, EA19)"
drop MARKER country
*list country_str geo

// Fix variables
drop ind_type // Drop constant 
replace value = "" if value == ":"          // Fix missing data indicator 
destring value, replace                     // Convert to numeric
encode indic_is, gen(indic)                 // Convert from string
label var time "Time"

// Keep relevant cases
keep if unit == "Percentage of individuals"
drop if inlist(country_str, "CH", "EU25", "EU28", "ME", "RS")
twoway (line value time if indic == 1, by(country_str, note("{it:Source:} Eurostat, isoc_bdek_di", span))), ///
        ytitle("% who access internet at least once a week") ///
        xlabel(2003 2005 2010 2015, ang(h) alternate) xtitle("") ///
        name(graph1, replace)

// All in one plot
encode country_str, gen(country)
keep if indic == 1
xtset country time, yearly
   
keep if inlist(country, 6, 7, 8, 10, 16, 19, 25, 29, 30, 34) // Reduce number of countries
xtline value, overlay xlabel(2003 2005 2010 2015, ang(h)) xtitle("") ///
              ytitle("% who access internet at least once a week") ///
              legend(pos(2)) name(graph2, replace) ///
              note("{it:Source:} Eurostat, isoc_bdek_di", span)xlabel(2003 2005 2010 2015, ang(h) alternate) xtitle("") ///
              name(graph2, replace)

Dec 19, 2014

Random graphs (41): Line plot

// DATASET: Employment rates by sex, age and nationality (%) [lfsa_ergan]
// LAST UPDATE: 27.11.14 13:37:54
// EXTRACTION DATE: 13.12.14 03:32:55
// SOURCE OF DATA: Eurostat

insheet using "lfsa_ergan_1_Data.csv", clear names

drop sex age citizen

// Generate country variable
*kountryadd "Germany (until 1990 former territory of the FRG)" to "Germany" add
kountry geo, from(other) stuck marker
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ country_str
replace country_str = "UK" if country_str == "GB"
list country_str geo

replace country_str = "EU27" if geo == "European Union (27 countries)"
replace country_str = "EU28" if geo == "European Union (28 countries)"
replace country_str = "EU15" if geo == "European Union (15 countries)"

// Fix labor force participation rate

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

twoway (line value time if country_str == "NL") ///
       (line value time if country_str == "UK") ///
       (line value time if country_str == "EU15") ///
       (line value time if country_str == "ES") ///
      , legend(label(1 "NL") ///
               label(2 "UK") ///
               label(3 "EU-15") ///
               label(4 "ES") ///
               pos(5) ring(0)) ///
        xtitle("") ytitle("Female labor force participation rate") ///
        xlabel(1995(5)2010 2013) ///
       note(" " "{it: Source:} Eurostat, lfsa_ergan, date of extraction: 2014-12-13", span)

Oct 18, 2013

Random graphs (17): Differences in percentages across groups

clear

// Read in data

/// Employment (main characteristics and rates) - annual averages [lfsi_emp_a]
/// Last update: 10-07-2013 
/// Employment rate (20 to 64 years) 

input str33 geo total male female
"European Union (28 countries)" 68.4 74.5 62.3
"European Union (27 countries)" 68.5 74.6 62.4
"Belgium" 67.2 72.7 61.7
"Bulgaria" 63.0 65.8 60.2
"Czech Republic" 71.5 80.2 62.5
"Denmark" 75.4 78.6 72.2
"Germany" 76.7 81.8 71.5
"Estonia" 72.1 75.2 69.3
"Ireland" 63.7 68.1 59.4
"Greece" 55.3 65.3 45.2
"Spain" 59.3 64.5 54.0
"France" 69.3 73.8 65.0
"Croatia" 55.4 60.6 50.2
"Italy" 61.0 71.6 50.5
"Cyprus" 70.2 76.1 64.8
"Latvia" 68.2 70.2 66.4
"Lithuania" 68.7 69.4 67.9
"Luxembourg" 71.4 78.5 64.1
"Hungary" 62.1 68.1 56.4
"Malta" 63.1 79.0 46.8
"Netherlands" 77.2 82.5 71.9
"Austria" 75.6 80.9 70.3
"Poland" 64.7 72.0 57.5
"Portugal" 66.5 69.9 63.1
"Romania" 63.8 71.4 56.3
"Slovenia" 68.3 71.8 64.6
"Slovakia" 65.1 72.8 57.3
"Finland" 74.0 75.5 72.5
"Sweden" 79.4 81.9 76.8
"United Kingdom" 74.2 80.0 68.4
"Iceland" 81.8 84.4 79.1
"Norway" 79.9 82.4 77.3
"Switzerland" 82.0 87.9 76.0
end

/// Create country variable
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
replace _ISO2C_ = "EU-27" if geo == "European Union (27 countries)"
replace _ISO2C_ = "EU-28" if geo == "European Union (28 countries)"
replace _ISO2C_ = "GB" if geo == "United Kingdom"
replace _ISO2C_ = "EL" if geo == "Greece"
drop ctry
ren _ISO2C_ cntry

drop if inlist(cntry, "EU-28", "IS", "CH", "NO")

graph dot male female, over(cntry, sort(total) ///
      label(angle(v))) vertical exclude0 ///
   legend(label(1 "Males") label(2 "Females") ring(0)) ///
   ytitle("Employment rate among 20-64 year-olds," "2012") ///
   yline(75) text(76 12 "Europe 2020 target") ///
   note( ///
          "{it:Source:} Eurostat, lfsi_emp_a, date of extraction: 2013-08-04" ///
          "{it:Note:} Countries sorted by total employment rates", span)

Mar 26, 2013

Random graphs (11): Visualizing multiple group differences

// Prepare data

// Formal care use by income quintiles, households with a child
input str5 geo inc1 inc3 inc5
AT 10 7 9
BE 17 38 57
BG 0 10 15
CH 9 27 53
CY 16 19 30
CZ 3 3 4
DE 21 22 23
DK 87 72 83
EE 16 22 14
EL 6 11 12
ES 29 30 45
FI 18 27 41
FR 15 60 64
HR 6 8 13
HU 7 14 15
IE 8 12 34
IS 37 44 34
IT 17 26 28
LT 2 16 10
LU 23 34 56
LV 7 24 11
MT 0 16 15
NL 27 55 70
NO 34 57 53
PL 0 2 4
PT 14 44 36
RO 5 5 13
SE 44 56 32
SI 41 39 38
SK 2 5 0
UK 20 50 53
EU-27 17 34 36
end

// Encode country variable
encode geo, gen(country)

// Create country variable sortet by the size of the income gap
gen diff = inc5 - inc1 // Income gap
egen order = rank(-diff), unique  // Create rank variable
labmask order, value(country) decode // Assign value
  // labels of country to variable order based on its values
// Run-of-the-mill dot plot
twoway dot inc1 inc3 inc5 order, vertical ///
      legend(label(1 "1{sup:st} income quintile (poorest)") ///
   label(2 "3{sup:rd} income quintile") ///
   label(3 "5{sup:th} income quintile (richest)") ///
   order(3 2 1) ring(0) pos(12)) ///
   msymbol(th oh t) ///
      xlabel(1/32, valuelabels ang(v)) /// // turn on labels
      xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the difference */
            /* between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap1, replace)
// Without dots
scatter inc1 inc3 inc5 order,   ///
   legend(label(1 "1{sup:st} income quintile (poorest)") ///
          label(2 "3{sup:rd} income quintile") ///
          label(3 "5{sup:th} income quintile (richest)") ///
         order(3 2 1) ring(0) pos(12)) ///
   msymbol(th oh t) ///
   xlabel(1/32, valuelabels ang(v)) /// // turn on labels
   xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the difference /*
           */between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap2, replace)
// With numbers instead of symbols
   // Not sure whether this is the most elegant move
reshape long inc, i(geo) j(j)

twoway (dot inc order if j == 1, mlabel(j) mlabpos(0) msymbol(i))  ///
           (dot inc order if j == 3, mlabel(j) mlabpos(0) msymbol(i))  ///
           (dot inc order if j == 5, mlabel(j) mlabpos(0) msymbol(i)),  ///
      legend(label(1 "1 1{sup:st} income quintile (poorest)") ///
             label(2 "3 3{sup:rd} income quintile") ///
             label(3 "5 5{sup:th} income quintile (richest)") ///
             order(3 2 1) ring(0) pos(12)) ///
   xlabel(1/32, valuelabels ang(v)) /// // turn on labels
      xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the difference /*
           */ between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap3, replace)
// With ordinal numbers and without dots
label define j 1 "1{sup:st}" 3 "3{sup:rd}" 5 "5{sup:th}" 
label value j j 

twoway (dot inc order if j == 1, mlabel(j) mlabpos(0) msymbol(i) ndots(0))  ///
       (dot inc order if j == 3, mlabel(j) mlabpos(0) msymbol(i) ndots(0))  ///
       (dot inc order if j == 5, mlabel(j) mlabpos(0) msymbol(i) ndots(0)),  ///
      legend(label(1 "1{sup:st} income quintile (poorest)") ///
             label(2 "3{sup:rd} income quintile") ///
             label(3 "5{sup:th} income quintile (richest)") ///
             order(3 2 1) ring(0) pos(12)) ///
   xlabel(1/32, valuelabels ang(v)) /// // turn on labels
      xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the difference /*
           */ between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap4, replace)
// With arrows
reshape wide // Get data back into old format

twoway (pcarrow inc5 order inc1 order) ///
       (scatter inc5 order) ///
 ,   legend(label(2 "5{sup:th} income quintile (richest)") ///
           label(1 "Difference between the 5{sup:th} /*
                           */ and 1{sup:st} income quintile") ///
     order(1 2) ring(0) pos(12)) ///
     xlabel(1/32, valuelabels ang(v)) /// // turn on labels
      xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the /*
           */ difference between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap5, replace)
// With a line
twoway (rspike inc5 inc1 order) ///
       (scatter inc5 order) ///
       (scatter inc1 order, msymbol(oh)) ///    
       (scatter inc3 order, msymbol(th)) ///    
 ,   legend(label(3 "1{sup:st} income quintile (poorest)") ///
            label(2 "5{sup:th} income quintile (richest)") ///
            label(1 "Difference between the 5{sup:th} /*
                           */ and 1{sup:st} income quintile") ///
      label(4 "3{sup:rd} income quintile") ///
      order(2 4 3) ring(0) pos(12)) ///
     xlabel(1/32, valuelabels ang(v)) /// // turn on labels
      xtitle("") ///
   ytitle("% formal care use of households with" ///
          "a child younger than 3 years of age") ///
   caption("Note: Countries sorted by the size of the difference /*
           */ between the 5{sup:th} and 1{sup:st} quintile" ///
           "Source: EU-SILC 2010", span) ///
   name(incomegap6, replace)

Mar 18, 2013

Merging quarterly time-series data with monthly time series data

version 12
set more off
clear

// DATASET: GDP and main components - Current prices [namq_gdp_c]
// LAST UPDATE: 15.03.13 20:50:29
// EXTRACTION DATE: 18.03.13 18:04:00
// SOURCE OF DATA: Eurostat

insheet using "namq_gdp_c_1_Data.csv", comma clear names
 
// Generate country variable
kountryadd "Germany (until 1990 former territory of the FRG)" to "Germany" add
kountry geo, from(other) stuck
ren _ISO3N_ country
kountry  country, from(iso3n) to(iso2c)
ren  _ISO2C_ country_str
replace country_str = "UK" if country_str == "GB"
list country_str geo
 
// Fix GDP variable
replace value = "" if value == ":"          // Fix missing data indicator 
replace value = subinstr(value, " ", "",.)  // Remove blank (thousands separator)
destring value, replace                     // Convert to numeric

// Drop unecessary variables and clean up data set
drop s_adj unit indic_na flagandfootnotes country
order country_str geo time value
sort geo time

// Generate monthly time variable
    
   // Generate quarterly time variable first
gen current_time_point_q = quarterly(time, "YQ")
    
   // Convert to months
gen current_time_point = mofd(dofq(current_time_point_q))
format current_time_point %tm
    
   // Carry forward first monthly observation
expand 3                                      // Create 2 duplicates of each case
by geo time, s: gen counter = _n - 1          // Count duplicates,
                                              // original    = 1 - 1 = 0
                                              // duplicate 1 = 2 - 1 = 1        
                                              // duplicate 2 = 3 - 1 = 2
replace current_time_point = current_time_point + counter
drop current_time_point_q counter time
 
// Cleaning up 
ren value gdp
label var gdp "GDP per capita (quarterly)"
keep country_str current_time_point gdp
save gdp.dta, replace
 
// Open master data set and merge
use unmepl.dta, clear 
merge 1:1 country_str current_time_point using gdp.dta 
keep if _merge == 3  
 
// Create semi-ugly plot for illustration 
keep if country_str == "NL" 
label var total_unempl_nsa "Unemployment rate (monthly)" 
 
tsset  current_time_point 
twoway (tsline gdp, yaxis(1)) /// 
       (tsline total_unempl_nsa, yaxis(2)) /// 
    , legend(ring(0)) /// 
      ytitle("Euros per inhabitant", axis(1)) /// 
   ytitle("Percentage points", axis(2)) /// 
   tlabel(2004m1 (6) 2009m12, angle(45)) /// 
   ttitle("Months")

Random graphs (9): Bar graphs

clear

// Copy and paste data from here:
// http://epp.eurostat.ec.europa.eu/cache/
// ITY_PUBLIC/3-07032013-AP/EN/3-07032013-AP-EN.PDF

input str30 geo ///
      teachers_primary ///
   teachers_secondary ///
   teachers_tertiary ///
   physicians ///
   managers
EU27 85 59 40 45 33
Belgium 81 61 45 36 30
Bulgaria 94 78 48 . 37
"Czech Republic" 97 58 36 54 26
Denmark 69 . . 45 28
Germany 84 50 39 42 30
Estonia 93 73 . 74 36
Ireland 85 65 . 39 34
Greece . . . 39 23
Spain 75 50 40 51 30
France 83 54 36 41 40
Italy 96 63 36 37 25
Cyprus 83 59 39 . 15
Latvia 93 80 59 74 45
Lithuania 96 79 55 70 39
Luxembourg 74 50 43 30 25
Hungary 96 65 38 54 41
Malta 85 43 30 37 24
Netherlands 85 50 40 45 30
Austria 90 53 38 44 27
Poland 85 66 43 57 39
Portugal 80 68 44 51 34
Romania 86 67 46 69 31
Slovenia 97 66 39 59 38
Slovakia 89 71 44 56 31
Finland 79 58 50 55 32
Sweden 82 52 43 45 35
"United Kingdom" 87 60 43 45 35
Iceland 81 52 47 33 41
Liechtenstein 78 44 27 . .
Norway 74 50 43 43 32
Switzerland 81 40 37 36 33
end

// Label variables
label var geo "Country"
label var teachers_primary "Female teachers in primary education"
label var teachers_secondary "Female teachers in upper secondary education"
label var teachers_tertiary "Female academic staff in tertiary education"
label var physicians "Female physicians (2010)"
label var managers "Female managers"

// Country variable
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
replace _ISO2C_ = "EU-27" if geo == "EU27"
drop ctry
ren _ISO2C_ cntry

drop if cntry == "LI"

// Draw graph
graph hbar managers, over(cntry, sort(1) desc) ///
  xsize(5.5) ysize(8) ///
  caption("Source: Eurostat News Release 37/2013", span) ///
/*note("Includes both corporate managers ///
  and managers of small enterprises", span)*/ ///
  ytitle("Proportion of female managers in 2011")

// Black bar created via the graph editor

Mar 15, 2013

Random graphs (7): Differences in percentages across groups

*findit labutil // For the -labmask- command
*ssc install kountry

clear 
version 12 
  
// Download date from Eurostat, lfsa_eppga 
// Part-time employment as percentage of the total employment 
// From 15 to 64 years

input str60 geo m2011 f2011
EU27 8.1 31.6
Belgium 9.2 43.3
Bulgaria 2.0 2.4
"Czech Republic" 1.8 8.5
Denmark 14.2 37.0
Germany 9.0 45.1
Estonia 5.0 13.5
Ireland 12.5 35.2
Greece 4.2 10.0
Spain 5.9 23.4
France 6.5 29.9
Italy 5.5 29.3
Cyprus 6.1 12.1
Latvia 7.0 10.4
Lithuania 6.6 9.9
Luxembourg 4.3 35.9
Hungary 4.4 8.8
Malta 5.3 25.6
Netherlands 24.3 76.5
Austria 7.8 43.4
Poland 4.7 10.4
Portugal 7.0 13.7
Romania 8.7 10.1
Slovenia 7.1 12.2
Slovakia 2.6 5.6
Finland 9.4 19.0
Sweden 12.3 39.3
"United Kingdom" 11.0 42.2
Iceland 9.9 31.7
Norway 13.7 42.1
Switzerland 12.4 59.4
end 
 
// Country 
kountry geo, from(other) stuck
ren _ISO3N_ ctry
kountry ctry, from(iso3n) to(iso2c)
kountryadd "Former Yugoslav Republic of Macedonia, the" to "Macedonia" add
replace _ISO2C_ = "EU-27" if geo == "EU27" 
drop ctry
ren _ISO2C_ cntry 
  // Create non-string version of country variable
encode cntry, gen(country)
 
// Drop unnecessary cases
drop if cntry == "MK"
drop if cntry == "HR" 
drop if cntry == "TR" 

// First attempts:
graph bar f2011 m2011, over(cntry, sort(1) desc label(angle(90))) ///
      legend(label(2 "Men") label(1 "Women")) ///
   xsize(8.25) ysize(4)
// A bar graph is too cluttered

graph dot f2011 m2011, over(cntry, sort(1) desc) ///
      legend(label(2 "Men") label(1 "Women")) ///
   xsize(8.25) ysize(4)
// Can I have that vertically as well?

twoway dot m2011 f2011 country, vertical ///
      legend(label(1 "Men") label(2 "Women") ring(0) pos(1)) ///
   xlabel(1/31, valuelabels ang(v)) ///    // turn on labels
   xtitle("") ///
   ytitle("% part-time of total employment in 2011") ///
   caption("Source: Eurostat, lfsa_eppga, 2013-03-15", span) ///
   xsize(8.25) ysize(4)
// Can I sort countries by size of the gender gap?

// Set up sort order
gen diff = f2011 - m2011  // Gender gap
egen order = rank(-diff), unique  // Create rank variable
labmask order, value(country) decode // Assign value
  // labels of country to variable order based on its values
   
// Create graph
twoway dot m2011 f2011 order, vertical ///
      legend(label(1 "Men") label(2 "Women") ring(0) pos(1)) ///
   xlabel(1/31, valuelabels ang(v)) ///    // turn on labels
   xtitle("") ///
   ytitle("% part-time of total employment in 2011") ///
   caption("Source: Eurostat, lfsa_eppga, 2013-03-15", span) ///
   xsize(8.25) ysize(4)

Aug 9, 2012

Random graphs (1): Complex scatterplot


#delimit ;
twoway (scatter change2006_10 childcare if time == 2010
                                          & age == 2
                                     & duration == 3,
        mlab(geo2) mlabpos(0) msymbol(i)

     /* Make sure to use mlabpos(0), not mlabpos(central) */
     /* With mlabpos(central), all markers will be slightly off */

        yscale(range(-12 12))), // Slightly rescale y-axis
        xline(30) yline(0)    // Add horizontal and vertical lines
        xtitle("Performance"
           "(% of children under 3 in formal childcare in 2010)")
        ytitle("Progress"
           "(Percentage point change 2006{char 150}10)")
        text(-12 72 "Losing momentum")
        text( 12 70 "Moving further ahead")
        text(-12 10 "Falling further behind")
        text( 12  5 "Catching up")
        title("Progress towards the Barcelona targets,
               2006{c 150}2010")
        subtitle("Children under three years of age")
        note("Data: Eurostat database (ilc_caindformal),
              extraction date Aug 7, 2012", span);
        // 'span' makes sure that the note
        // starts on the very left side
#delimit cr