cap program drop DiabetesPrevention_intervene
program define DiabetesPrevention_intervene
	syntax [varlist] [if] [in], cyr(integer)

* Diabetes Prevention Intervention
* Reduces the probability of having diabetes by the "adiabe" factor

		marksample touse, zeroweight strok novarlist

	* Record Status before intervention
	cap drop old_diabe
	gen old_diabe = diabe

	* Update treatment status
	cap drop ltreat_now
	gen ltreat_now = treat_now
	replace ltreat_ever = treat_ever

	replace ltreat_diabe = treat_diabe
	replace ltreat_diabe_evr = treat_diabe_evr

	*replace treat_now = (((lobese == 1 | loverwt == 1 ) & diabdraw <= 0.25) | treat_ever == 1) & ldiabe == 0 & died == 0 if `touse'
	*replace treat_effective = 0  if `touse'
	replace treat_now = diabe == 1 & died == 0 & ltreat_ever == 0 if `touse'
	replace treat_ever = 1 if treat_now == 1
	replace treat_diabe_evr = 1 if treat_diabe == 1

	replace pdiabe  = (pdiabe) * adiabe if treat_now
	gen diabe_new  = diabe
	replace diabe_new = pdiabe > normal(-x_diabe`cyr') if treat_now
	replace treat_effective = 1 if diabe == 1 & diabe_new == 0 & treat_now
	replace diabe = 0 if treat_effective
	drop diabe_new

end