# Thread: compute true values monte carlo simulation

1. OK, thanks again!

2. Hi there,

In continuation to what I posted before in this thread, I'm still confused about the following:

suppose data is generated as:

W1=rnorm(n,0,1)
W2=runif(n,-2,2)
W3=rnorm(n,1,1)
A <- rbinom(n,1, .5)
Y <- 3.5*A - .75*W1 - 1.5*W2 - .75*W3 + 1.75*(A*W3) + rnorm(n)

where A is a treatment variable. Then the true treatment effect is 5.25, which can be seen straightaway from Y (3.5+1.75) or can be computed as shown in previous posts by MC simulation.

Now, when A is changed to :
A <- rbinom(n,1, 1/(1+exp(-(.4*W1 + .5*W2 + .4*W3))))
it is not as straightforward right?

so I figured the treatment effect can be computed as follows (in R):

n=10000
n.sim=500
y1 =rep(NA,n.sim)
y0 =rep(NA,n.sim)
for (s in 1:n.sim){
W1=rnorm(n,0,1)
W2=runif(n,-2,2)
W3=rnorm(n,1,1)
A <- rbinom(n,1, 1/(1+exp(-(.4*W1 + .5*W2 + .4*W3))))
Y <- 3.5*A - .75*W1 - 1.5*W2 - .75*W3 + 1.75*(A*W3) + rnorm(n)
dat=as.data.frame(cbind(A,Y))
y1[s]=mean(dat\$Y[A==1])
y0[s]=mean(dat\$Y[A==0])
}
mean(y1)-mean(y0)

which gives a treatment effect of approximately 4.08

however, I'm not sure this is correct??