# Re: st: Fitting the logistic curve to a time-series

 From Maarten buis To statalist@hsphsun2.harvard.edu Subject Re: st: Fitting the logistic curve to a time-series Date Fri, 21 Jul 2006 10:30:34 +0100 (BST)

```--- Serguei Kaniovski asked:
> How can I fit the logistic curve to a time-series "q" so that
> I can control the asymptotes, i.e. I what the fitted curve to
> level out at the value of q=0.04?

Serguei:
You can do that with the -nl- command which estimates a nonlinear
least squares model. See the example below. You don't have to fix
the minimum and maximum, you can also estimate them. Even if you
want to fix them this may be useful as a model to compare with
for e.g. a likelihood ratio test, BIC and AIC, or just graphically,
as is also shown in the example below.

The parameter in my example called {min} is the lower asymptote,
{max} is the higher asymptote, {b1} is the slope, and {b2} is the
year where the curve is halfway between {min} and {max}.

HTH,
Maarten

*---------------begin example----------------
set more off
capture drop _all
input year	q
1981	.01102246
1982	.01127048
1983	.01152055
1984	.0118841
1985	.01211535
1986	.01247724
1987	.0129496
1988	.01321121
1989	.01319597
1990	.01362598
1991	.014358
1992	.01417304
1993	.01437101
1994	.01509818
1995	.01539195
1996	.01586584
1997	.01686939
1998	.01767208
1999	.01880662
2000	.01914837
2001	.02034989
2002	.02122596
2003	.02201964
2004	.02243478
2005	.02346839
2006	.02428688
end

twoway line q year

nl ( q = .04/(1+exp(-{b1}*(year-{b2=2000}))) )
est store const
predict qconst
label var qconst "min and max constrained"

nl ( q = {min=0} + {max=.04}/(1+exp(-{b1}*(year-{b2=2000}))) )
nl log4: q year
est store minmax
predict qminmax
label var qminmax "min and max not constrained"

twoway line q qconst qminmax year
/* The graph shows that the unconstrained
model fits better */

lrtest const minmax
/* hypothesis that min = 0 and
max = .4 is rejected */

est stats const minmax
/* AIC and BIC also show that the
unconstrained model fits better */
*----------------end example ----------------

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

___________________________________________________________
Try the all-new Yahoo! Mail. "The New Version is radically easier to use" – The Wall Street Journal
http://uk.docs.yahoo.com/nowyoucan.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```