cap program drop intervention
program define intervention


	syntax [varlist] [if] [in], cyr(integer)
	marksample touse /*, zeroweight strok novarlist */
	*** Implement intervention scenarios
	*** cyr: current year
	*** revised on Dec 19, 2007
	*** Aug 30, 2008 - change the intervention scenarios


  noi tab `touse'

	*****************************************
	* Record status before intervention - Aug 31,2008
	*****************************************
 	foreach x in smoken diabe hibpe obese {
        noi dis "******* RECORD OLD ********"
 		cap drop old_`x'
 		gen old_`x' = `x'
 	}

  if length(trim("$interventions")) > 0 {
  	* Run some interventions
  	noi di "******** Running Interventions ********"
  	foreach intervene in $interventions {
  		noi di _column(10) "`intervene'"
  		noi `intervene'_intervene if `touse', cyr(`cyr')
  	}
  }
  else {
  	* No interventions to run
  }

    /* Haven't fixed yet *

	********************* Reduction scenarios **************************
	*** Hypertension


	else if "`scenario'" == "Diab_Hibpe"  {

        local rd = 0.75
		replace treat_hibpe_evr = 1 if hibpe == 1 & died == 0 & `touse'
		replace treat_hibpe = hibpe == 1 & died == 0 & ltreat_hibpe_evr == 0 & normal(x_hibpe2004) >= `rd' if `touse'
		replace hibpe = 0 if (treat_hibpe | treat_hibpe_eff) & `touse'
		replace treat_hibpe_eff = 1 if old_hibpe == 1 & hibpe == 0 & `touse'

        local rd = 0.75
		replace treat_diabe_evr = 1 if diabe == 1 & died == 0 & `touse'
		replace treat_diabe = diabe == 1 & died == 0 & ltreat_diabe_evr == 0 & normal(x_diabe2004) >= `rd' if `touse'
		replace diabe = 0 if (treat_diabe | treat_diabe_eff) & `touse'
		replace treat_diabe_eff = 1 if old_diabe == 1 & diabe == 0 & `touse'
	}
	*/
	****************************
	* Aug 30, 2008 - update cases of diseases, quiting smoking or becoming obese
	****************************
	* Aug 31, Ever conditions for the summary of cases averted *
	quietly{
		foreach x in smoken diabe hibpe obese {
		  cap drop llf`x'
			gen llf`x' = lf`x'
			replace lf`x' = lf`x' + 1 if old_`x'== 1 & `x' == 0
			* If relapse, for EBM scenarios
			* replace lf`x' = 0 if `x' == 1
		}
 	}

end