sungmoo 发表于 2013-1-30 13:21 
*样本分布函数图像的近似画法
use work,clear
g y=1
衷心感谢您的回复:
原来cumul是这么用的,以前没看到option里的equal (generate equal cumulatives for tied values),英文不好啊。另学到:做cumul,bysort的次关键词要加括号,很重要。您原作的这步
* Replace each cluster with n copies of the cluster
expandcl 2,cluster(y) generate(c)用于generate duplicates (2 copies),先y=1,之后再做替换(0,1判定识别),高啊~~
我原来是导到R里面去实现的(把y1,y2放到一个变量y下,分时间time=1和2),又学一招。
另,原图还有些细节:限制了y的范围,并标识了贫困线
改1(基于您原作):
use work,clear
global x=500000
generate y=1
* Replace each cluster with n copies of the cluster
expandcl 2,cluster(y) generate(c)
replace y=y1*(c==1)+y2*(c==2)
replace c=c*10+cat
* equal: generate equal cumulatives for tied values
bysort c (y): cumul y if y<=$x,equal generate(p)
forv c=1/4{
#d ;
twoway
line p y if c==1*10+`c' & y<=$x,sort ||
line p y if c==2*10+`c' & y<=$x, sort
title(cat=`c')
legend(ring(0) pos(4) col(1) region(lcolor(white))
label(1 "time 1") label(2 "time 2"))
xline(109663)
saving(g`c',replace)
;
#d cr
}
#d;
graph combine g1.gph g2.gph g3.gph g4.gph,
title("CDFs for two-time income in four categories"
"truncated at 500,000")
note("the vertical line is the poverty line (at 109,663)")
;
#d cr
graph export cdf.pdf,replace
所意以一图一目了然:
改2:(不用expandcl,直接用cumul,eq分别做y1,y2的cumulative shares)
use work,clear
global x=500000
forv i=1/2{
* (y`i'): the parentheses must be there!
bysort cat (y`i'): cumul y`i' if y`i'<=$x, eq g(p`i')
}
forv c=1/4{
#d ;
twoway
line p1 y1 if cat==`c' & y1<=$x,sort ||
line p2 y2 if cat==`c' & y2<=$x, sort
title(cat=`c')
legend(ring(0) pos(4) col(1) region(lcolor(white))
label(1 "time 1") label(2 "time 2"))
xline(109663)
saving(g`c',replace)
;
#d cr
}
#d;
graph combine g1.gph g2.gph g3.gph g4.gph,
title("CDFs for two-time income in four categories"
"truncated at 500,000")
note("the vertical line is the poverty line (at 109,663)")
;
#d cr
graph export cdf.pdf,replace
同图