*! version 1.0.1 8Mar93 Royston; STB-12 sg1.5 program define nlgom4 version 3.0 if "`1'"=="?" { mac def S_2 "4-parameter Gompertz function, $S_E_depv=b0+b1*exp(-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(-log((`Y'-`a')/`b')) reg `Y' `2' `exp' 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*exp(-exp(-$b2*(`2'-$b3))) end