Skip to content

Instantly share code, notes, and snippets.

@jmoy
Created June 7, 2017 06:02
Show Gist options
  • Save jmoy/a36e2399418d8bdb18e649d4b8f698db to your computer and use it in GitHub Desktop.
Save jmoy/a36e2399418d8bdb18e649d4b8f698db to your computer and use it in GitHub Desktop.
import numpy as np
import numpy.random as nr
def gen(N):
X = nr.choice([0,1],size=N,p=[0.6,0.4])
D = nr.choice([0,1],size=N,p=[0.6,0.4])
epsi = nr.uniform(0,2,N)
Y = X+D*epsi
return X,D,epsi,Y
def estim(D,Y):
Y0 = np.average(Y[D==0])
Y1 = np.average(Y[D==1])
return Y1-Y0
X,D,epsi,Y = gen(10000)
estim(D,Y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment