1 Star 0 Fork 161

huangleiabcde / mostly-harmless-replication

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Figure 6-1-1.do 3.12 KB
一键复制 编辑 原始数据 按行查看 历史
vikjam 提交于 2015-05-14 12:33 . label typo fixed; formatting
clear all
set more off
/* Set random seed for replication */
set seed 1149
/* Number of random variables */
local nobs = 100
set obs `nobs'
gen x = runiform()
gen y_linear = x + (x > 0.5) * 0.25 + rnormal(0, 0.1)
gen y_nonlin = 0.5 * sin(6 * (x - 0.5)) + 0.5 + (x > 0.5) * 0.25 + rnormal(0, 0.1)
gen y_mistake = 1 / (1 + exp(-25 * (x - 0.5))) + rnormal(0, 0.1)
graph twoway (lfit y_linear x if x < 0.5, lcolor(black)) ///
(lfit y_linear x if x > 0.5, lcolor(black)) ///
(scatter y_linear x, msize(vsmall) msymbol(circle) mcolor(black)), ///
title("A. Linear E[Y{sub:0i}|X{sub:i}]") ///
ytitle("Outcome") ///
xtitle("x") ///
xline(0.5, lpattern(dash)) ///
scheme(s1mono) ///
legend(off) ///
saving(y_linear, replace)
graph twoway (qfit y_nonlin x if x < 0.5, lcolor(black)) ///
(qfit y_nonlin x if x > 0.5, lcolor(black)) ///
(scatter y_nonlin x, msize(vsmall) msymbol(circle) mcolor(black)), ///
title("B. Nonlinear E[Y{sub:0i}|X{sub:i}]") ///
ytitle("Outcome") ///
xtitle("x") ///
xline(0.5, lpattern(dash)) ///
scheme(s1mono) ///
legend(off) ///
saving(y_nonlin, replace)
graph twoway (lfit y_mistake x if x < 0.5, lcolor(black)) ///
(lfit y_mistake x if x > 0.5, lcolor(black)) ///
(function y = 1 / (1 + exp(-25 * (x - 0.5))), lpattern(dash)) ///
(scatter y_mistake x, msize(vsmall) msymbol(circle) mcolor(black)), ///
title("C. Nonlinearity mistaken for discontinuity") ///
ytitle("Outcome") ///
xtitle("x") ///
xline(0.5, lpattern(dash)) ///
scheme(s1mono) ///
legend(off) ///
saving(y_mistake, replace)
graph combine y_linear.gph y_nonlin.gph y_mistake.gph, ///
col(1) ///
xsize(4) ysize(6) ///
graphregion(margin(zero)) ///
scheme(s1mono)
graph export "Figure 6-1-1-Stata.png", replace
/* End of file */
exit
1
https://gitee.com/huangleiabcde/mostly-harmless-replication.git
git@gitee.com:huangleiabcde/mostly-harmless-replication.git
huangleiabcde
mostly-harmless-replication
mostly-harmless-replication
master

搜索帮助