论文:Latent variables and propensity score matching a simulation study …
stata实现
cd D:\stata_workspace
clear all
set seed 191010
set obs 5000
*set memory 50M
matrix m = (0,0,0)
*matrix sd = (sqrt(2),1,1)
*drawnorm X1 X2 X3, n(2000) means(m) sds(sd)
matrix co = (2, 1, -1 \ 1, 1, -0.5 \ -1, -0.5 ,1)
drawnorm X1 eta X2, n(5000) means(m) cov(co)
gen X3 = rnormal(0,1)
summarize
*stata 绘图: https://zhuanlan.zhihu.com/p/32432932
*ModelA
gen U1 = rnormal(0,1)
gen D1 = 1 if U1 > 0.5
replace D1 = 0 if U1 <= 0.5
logit D1 X1 X2 X3
predict y1_hat
twoway(kdensity y1_hat if D1==1)(kdensity y1_hat if D1==0)
*Mode