*! version 1.0.0 18Jan93 Royston; STB-11 sg1.4 program define nllog4 version 3.0 if "`1'"=="?" { mac def S_2 "4-parameter logistic function, $S_E_depv=b0+b1/(1+exp(-b2*(`2'-b3)))" mac def S_1 "b0 b1 b2 b3" /* Approximate initial values by estimating upper and lower asymptotes. */ local fac 1.1 /* fudge factor for asymptotes */ local exp "$S_E_wgt $S_E_exp" tempvar Y quietly { gen `Y' = $S_E_depv $S_E_if $S_E_in sum `Y' `exp' local min = _result(5) local max = _result(6) if `max'<0 { local b = `max'/`fac' } else { local b = `max'*`fac' } if `min'<0 { local a = `min'*`fac' } else { local a = `min'/`fac' } } replace `Y' = log((`Y'-`a')/(`b'-`Y')) reg `Y' `2' mac def b2 = _b[`2'] mac def b3 = -_b[_cons]/$b2 mac def b0 `a' mac def b1 = `b'-`a' exit } replace `1'=$b0+$b1/(1+exp(-$b2*(`2'-$b3))) end