/* Load the file that sets up the smoking cessation schedule */
preserve

insheet using "$workdir/Interventions/Sched_SmokingCessation.txt", delimiter("|")
mkmat asmoken, matrix(smoking_cess_sched) rownames(year)
clear

restore



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

* Smoking Cessation Intervention
* Changes probability of smoking now by asmoken

	marksample touse, zeroweight strok novarlist

	cap drop ltreat_now
	gen ltreat_now = treat_now
	replace ltreat_ever = treat_ever

	* Record Status before intervention
	cap drop old_smoken
	gen old_smoken = smoken

	* Update treatment status
	replace  treat_now = (lsmoken == 1) & died == 0  if `touse'
	replace  treat_effective = 0  if `touse'

	replace treat_ever = 1 if treat_now == 1

	* Update the probabilities
	replace psmkstat3 = 1 - min((1 - psmkstat3)*smoking_cess_sched[rownumb(smoking_cess_sched, "`cyr'"), 1], 1) if d_smkstat & treat_now
	replace treat_effective = 1 if normal(x_smkstat`cyr') < 1 - psmkstat3 & treat_now
	replace smoken = 0 if treat_effective == 1

	end