*! version 1.1.0 Stephen P. Jenkins, May 2001
*! Split-population survival ('cure') model, discrete-time

program define spsur_ll
	version 6
	args todo b lnf
	tempvar t1 t2 sum ST ST_1 ht hT I1 I2 last c
	mleval `I1' = `b', eq(1)
	mleval `I2' = `b', scalar eq(2)

	quietly {

	ge double `c' = 1/(1+exp(-`I2'))
	ge double `ht' = 1-exp(-exp(`I1'))

	by $S_MLE_id: ge double `sum' = exp(sum(ln(1-`ht')))
	by $S_MLE_id: ge double `ST' = `sum'[_N] if _n==_N
	by $S_MLE_id: ge double `ST_1' = cond(_N==1,1, /*
		*/ cond(_n==_N & _N>1,`sum'[_N-1],.) )
	by $S_MLE_id: ge double `hT' = `ht'[_N] if _n==_N
	by $S_MLE_id: ge byte `last' = 1 if _n==_N


	mlsum `lnf' = cond($ML_y1,(ln(1-`c')+ln(`hT')+ln(`ST_1')), /*
			*/ ln(`c'+(1-`c')*`ST')) if `last'==1

	if `lnf' ==.  {exit}

	}

end