Stata 12 Graphics |
Dawn Koffman |
Office of Population Research Princeton University |
人口金字塔條形圖繪制
- sysuse pop2000, clear
- replace maletotal = -maletotal
- #delimit ;
- twoway bar maletotal agegrp, horizontal ||
- bar femtotal agegrp, horizontal
- title("US Male and Female Population by Age, Year 2000")
- note("Source: US Census Bureau, Census 2000, Tables 1, 2 and 3", span);
- #delimit cr
- sysuse pop2000, clear
- replace maletotal = -maletotal
- replace maletotal = maletotal / 1000000
- replace femtotal = femtotal / 1000000
- #delimit ;
- twoway bar maletotal agegrp, horizontal ||
- bar femtotal agegrp, horizontal
- title("US Male and Female Population by Age, Year 2000")
- note("Source: US Census Bureau, Census 2000, Tables 1, 2 and 3", span)
- xtitle("Population in Millions") ytitle("Age Group Number")
- xlabel( -12 "12" -10 "10" -8 "8" -6 "6" -4 "4" 4(2)12)
- ylabel(1(1)17, angle(0))
- legend(order(1 "Male" 2 "Female"));
- #delimit cr
- sysuse pop2000, clear
- replace maletotal = -maletotal
- replace maletotal = maletotal / 1000000
- replace femtotal = femtotal / 1000000
- gen zero = 0
- #delimit ;
- twoway bar maletotal agegrp, horizontal bfc(gs7) blc(gs7) ||
- bar femtotal agegrp, horizontal bfc(gs11) blc(gs11) ||
- scatter agegrp zero, mlabel(agegrp) mlabcolor(black) msymbol(none)
- title("US Male and Female Population by Age, Year 2000")
- note("Source: US Census Bureau, Census 2000, Tables 1, 2 and 3", span)
- xtitle("Population in Millions") ytitle("Age Group Number")
- ytitle("") yscale(noline) ylabel(none)
- xlabel( -12 "12" -10 "10" -8 "8" -6 "6" -4 "4" 4(2)12)
- legend(off) text(15 -8 "Male") text(15 8 "Female");
- #delimit cr
注:關(guān)于人口金字塔的繪制可參閱 演示教程命令集及Pyramid命令修改
/*Chernoff 臉譜圖*/
- * Chernoff faces
- * Few cases, each face is a row case.
- use "http://www.princeton.edu/~otorres/chernoff.dta", clear
- *ssc install chernoff //chernoff移至gr0038下
- findit gr0038 //安裝
- chernoff, hdark(gdppc) bdens(trade) nose(unemp) mcurv(polity2) order(gdppc) ilabel(country)
- // Circle using function
- #delimit ;
- twoway (function y = sqrt(1 -(x)^2),
- range(-1 1) lwidth(thick) lcolor(red))
- (function y = -sqrt(1 - (x)^2),
- range(-1 1) lwidth(thick) lcolor(red)), aspect(1);