g1=rbinom(100000, 1, 0.3) #模拟数据
c1=rnorm(100000, mean=10, sd=2)
c2=rbinom(100000, 2, 0.4)
u=rnorm(100000, mean = 10, sd = 2)
exi=rnorm(100000, mean = 0, sd = 1)
eyi=rnorm(100000, mean = 0, sd = 1)
probit_x=0.3*g1+0.2*c1-0.3*c2+u+exi-13
probit_data=as.data.frame(cbind(g1,c1,c2,u,probit_x))
for (j in 1:100000){
if (probit_data$probit_x[j]>0) probit_data$x[j]=1 else probit_data$x[j]=0
}
问题在于最后一步,本人想根据probit_x的正负在生成一个变量X,按照我的办法特别慢,求一个简单的办法。不胜感激!