* fwl.do

clear
capture log close
set seed 1500
set obs 4000

* generate data
gen age = rnormal(25,2)
gen gpa = runiform(1,4)

sum gpa
replace gpa=gpa-r(mean)

gen y0 = 15000 + 0.5*age + 1.5*gpa + rnormal(1000,250)
gen y1 = y0 + 1500

gen delta = y1-y0 // ATE = 1500

gen d = 0
replace d = 1 in 1/1500

gen earnings = d * y1 + (1-d) * y0

* step 1: auxilary regression
reg d age gpa
predict dhat

* step 2: residualize dhat
gen dtilde = d-dhat

* step 3: regression

reg earnings dtilde
reg earnings age gpa d