由于坛友没有给出数据,我模拟了一份数据来作图,最终效果如下:
Stata代码如下:
- **************************生成模拟数据******************************
- clear
- set obs 20
- set seed 123456
- gen e = rnormal() // e~N(0,1)
- gen x = rnormal(80,30) // x~N(0,3^2)
- gen y1 = .
- replace y1 = 1.1091*x -10.2+ e
- gen y2=.
- replace y2 = 0.7486*x +25.069+ e
-
- *****************************作图********************************
- #delimit ;
- twoway (scatter y1 x,msymbol(s)) (lfit y1 x)
- (scatter y2 x,msymbol(d)) (lfit y2 x)
- ,
- xlabel(0(20)140) ylabel(0(20)140,grid angle(0))
- legend(order(3 "PL_gfcf" 1 "PL_cons") col(1) ring(0)
- pos(11) region(fcolor(none) lpattern(blank)))
- text(74 98 "y = 1.1091x -10.2" "R{sup:2}=0.992" 90 65
- "y = 0.7486x +25.069" "R{sup:2}=0.844")
- scheme(s1mono);
- #delimit cr
代码如下:
- **************************生成模拟数据******************************
- clear
- set obs 20
- set seed 123456
- gen e = rnormal(1,5) // e~N(0,1)
- gen x = rnormal(80,30) // x~N(80,30^2)
- gen y1 = .
- replace y1 = 1.1091*x -10.2+ e
- gen y2=.
- replace y2 = 0.7486*x +25.069+ e
- *****************************作图********************************
- #delimit ;
- twoway (scatter y1 x,msymbol(s) mcolor(red)) (lfit y1 x,lcolor(red) lwid(*1.8))
- (scatter y2 x,msymbol(d) mcolor(ebblue)) (lfit y2 x,lcolor(ebblue) lwid(*1.8))
- ,
- ylabel(0(20)140,grid angle(0)) xlabel(0(20)140) xtitle("")
- legend(order(3 "PL_gfcf" 1 "PL_cons") col(1) ring(0)
- pos(11) region(fcolor(none) lpattern(blank)))
- text(74 98 "y = 1.1091x -10.2" "R{sup:2}=0.992",color(red))
- text(90 65 "y = 0.7486x +25.069" "R{sup:2}=0.844" ,color(ebblue));
- #delimit cr
大家觉得这三幅图一样吗?Stata绘图还是很强大的哦!觉得对你有帮助的话,点个赞,评个分,支持一下,谢谢!