Showing posts with label labsize. Show all posts
Showing posts with label labsize. Show all posts

Nov 2, 2014

Random graphs (35): Line plots

clear
import excel "art births across countries.xlsx", sheet("Data") firstrow case(lower) clear

ren a geo // Rename country ID

// Rename variables: perc_YEAR format
foreach v of varlist b-o {
   local x : variable label `v'
   rename `v' perc`x'
}

// Reshape data set to long format
reshape long perc, i(geo) j(year)

// Cross-sectional bar graph at latest point in time
by geo: egen lastobs = max(cond(!missing(perc), year, .))  // Identify year of latest observation
gen byte last = year == lastobs                            // ID variable of latest observation
// According to http://www.stata.com/support/faqs/data-management/first-and-last-occurrences/

graph hbar perc if year >= 2007 & last == 1, over(geo, sort(perc) descending) nofill /// ytitle("% ART live births among all births") ylabel(0(1)6) /// note("{it:Note:} Data refer to 2010 or latest available (no earlier than 2007)", span) /// /*title("Country differences in ART birth rates")*/ /// name(crosssec, replace)
// Create classical twoway line plot twoway (line perc year if geo == "DK", cmissing(no)) /// (line perc year if geo == "SI", cmissing(no)) /// (line perc year if geo == "BE", cmissing(no)) /// (line perc year if geo == "SE", cmissing(no)) /// (line perc year if geo == "DE", cmissing(no)) /// (line perc year if geo == "FR", cmissing(no)) /// (line perc year if geo == "IT", cmissing(no)) /// (line perc year if geo == "UK", cmissing(no)) /// (line perc year if geo == "US", cmissing(no)) /// , xlabel(1997(1)2010, ang(h) labsize(small)) xtitle("") /// ylabel(0(1)6) ytitle("% ART live births among all births") /// legend(label(1 "DK") label(2 "SI") label(3 "BE") /// label(4 "SE") label(5 "DE") label(6 "FR") /// label(7 "IT") label(8 "UK") label(9 "US") /// pos(2))
//cmissing(no) makes sure that gaps are not filled
 
// Use panel line plot functionality keep if inlist(geo, "DK", "SI", "BE", "SE", "DE", "FR", "IT", "UK", "US") encode geo, gen(country) xtset country year, yearly xtline perc, overlay xlabel(1997(1)2010, ang(h) labsize(small)) xtitle("") /// ylabel(0(1)6) ytitle("% ART live births among all births") ///
             legend(pos(2))
// Note that the gaps are much harder to spot in this plot
 

// Small multiples version
twoway (line perc year, by(geo, note("") /*title("Development of ART birth rate, selected countries")*/) cmissing(no)), ///
        xlabel(1998 (2) 2010, ang(h) labsize(small) alternate) xtitle("") ///
        ylabel(0(1)6) yscale(r(0)) ytitle("% ART live births among all births") ///
        name(longit, replace)
        // yscale(r(0)) adds missing gridline according to
        // http://www.stata.com/statalist/archive/2013-04/msg00904.html

Mar 31, 2013

Random graphs (12): Stacked bar graphs

use ahm2009_wide, clear
 
replace country_str = "EL" if country_str == "GR"
 
quietly tab contracttype, gen(contr) 
ren contr1 perma 
ren contr2 tempo 
ren contr3 selfe 
ren contr4 famil
 
collapse perma tempo selfe famil [iw=eu29weight], by(country_str)
 
replace perma = perma * 100 
replace tempo = tempo * 100 
replace selfe = selfe * 100 
replace famil = famil * 100
 
egen order = rank(-perma), unique 
labmask order, value(country_str)
 
graph hbar perma tempo selfe famil ///
   , stack /// Stack bars on top of one another
   over(order, label(labsize(*0.9))) /// // Reduce size of country abbreviations
   ytitle("Percentage first contract") /// 
   legend(label(1 "Permanent") /// 
          label(2 "Temporary") /// 
          label(3 "Self-employed") /// 
          label(4 "Family worker") /// 
          col(2) pos(6)) ///  
   xsize(8.25) ysize(10) /// 
   note("{it:Source:} EU-LFS AHM 2009 (weighted)", span) /// 
   name(contract, replace)