应用stata学习计量经济学原理
Practice 2
* Q1
clear all
* 1
sysuse uslifeexp.dta
* 2
scatter le year
scatter le year,connect(1)
scatter le year,connect(1) msymbol(i)
* 3
scatter le year, ///
ylabel(30(5)80) xlabel(1890(10)2010) ///
xtitle(year) ytitle(life expectancy) ///
title(1900-1940 US life expectancy)
* 4
twoway (scatter le_male year) (scatter le_female year), ///
title(US male and female life expectancy) ///
xtitle(year) ytitle(life expendency) ///
legend (subtitle("Legend") all cols(1) ring(0) pos(5))
* Q2
clear all
cd "F:\stata与计量经济学\week 2 计量实验"
dir
use WAGE.DTA
*1
scatter educ wage
scatter exper wage
*2
scatter educ wage if female == 1, mcolor(green) scheme(p9) msymbol(O) msize(medium)
scatter exper wage if female == 1, mcolor(blue) scheme(p8) msymbol(x) msize(medium)
Another vision
*Q1
sysuse uslifeexp, clear
scatter le year,connect(l) msymbol(i)
* connect(1): connect with straight lines
* msymbol(i): remove the points
su le
*check the range of y-axis
su year
*check the range of x-axis
scatter le year, ylabel(35(5)80) xlabel(1900(10)2000) xtitle(year) ytitle(life expectancy) title(1900-1999 US life expectancy)
twoway(scatter le_male year)(scatter le_female year), title(1900-1999 US life expectancy for male and female) xtitle(year) ytitle(life expectancy) legend(ring(0) cols(1) position(5))
*or
scatter le_male year||scatter le_female year,title(1900-1999 US life expectancy for male and female) xtitle(year) ytitle(life expectancy) legend(ring(0) cols(1) position(5))
* ring(0): represents the legend be moved inside the plot
* cols(1): only one columns of legend
* position(5): the legend will be moved to 5 o'clock position
*Q2
use wage.dta ,clear
twoway(scatter educ wage if female == 1)(scatter exper wage if female == 1)
* by default
twoway ///
(scatter educ wage if female == 1, ///
msymbol(O) mcolor(green) msize(medium) mstyle(p9)) ///
(scatter exper wage if female == 1, ///
msymbol(X) mcolor(blue) msize(medium) mstyle(p8))
* msymbol:散点形状
* mcolor: 散点颜色
* msize: 散点大小
* mstyle: 散点整体样式