*! version 1.0.0 18Jan93 Royston; STB-11 sg1.4 program define nlexp3 version 3.0 if "`1'"=="?" { mac def S_2 /* */ "3-parameter asymptotic regression, $S_E_depv=b0+b1*b2^`2'" mac def S_1 "b0 b1 b2" /* Approximate initial values by estimating upper asymptote if growth is positive, otherwise lower asymptote ($b0). */ local fac 1.1 /* fudge factor for asymptote */ 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) reg `Y' `2' `exp' if _b[`2']>0 { if `max'<0 { mac def b0 = `max'/`fac' } else { mac def b0 = `max'*`fac' } replace `Y' = log($b0-`Y') reg `Y' `2' mac def b1 = -exp(_b[_cons]) } else { if `min'<0 { mac def b0 = `min'*`fac' } else { mac def b0 = `min'/`fac' } replace `Y' = log(`Y'-$b0) reg `Y' `2' mac def b1 = exp(_b[_cons]) } } mac def b2 = exp(_b[`2']) exit } replace `1'=$b0+$b1*$b2^`2' end