Skip to content

Instantly share code, notes, and snippets.

Created March 29, 2012 20:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/333f4a42fa4af5d77b92 to your computer and use it in GitHub Desktop.
Save anonymous/333f4a42fa4af5d77b92 to your computer and use it in GitHub Desktop.
clear
sysuse auto
set more off
set autotabgraph on
drop if rep78==.
bysort foreign: gen count=_N
gen freq=count/_N
preserve
collapse (mean) price count freq rep78, by(foreign)
twoway bar price foreign, barwidth(0.5) xlabel(-0.5 " " 0 1 1.5 " " , noticks valuelabel) ///
|| scatter price foreign, ms(none) mlabel(count) mlabpos(12) legend(off) ytitle("Average price of car", margin(right)) ///
caption("Note: The number of observations in each car type is shown on top of each bar", size(vsmall) margin(top)) ///
ylabel(6000(50)6200) name(gr1, replace)
twoway bar freq foreign, barwidth(0.5) base(0) xlabel(-0.5 " " 0 1 1.5 " " , noticks valuelabel) ///
|| scatter freq foreign, ms(none) mlabel(rep78) mlabpos(12) legend(off) ytitle("Frequency of car type", margin(right)) ylabel(0(0.2)0.8) ///
caption("Note: Average number of repairs (in 1978) for each car type is shown on top of each bar", size(vsmall) margin(top)) ///
name(gr2, replace)
restore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment