Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Curve fitting with nl log4, how to put constraints on parameters

From   Jennyfer Wolf <>
Subject   st: Curve fitting with nl log4, how to put constraints on parameters
Date   Mon, 14 Nov 2011 16:39:27 +0100


I am trying to do curve fitting for survey estimates over time with
the nl:log4... command (y = b0 + b1/(1 + exp(-b2*(x-b3))).
This logistic function seems to me to be the most realistic shape to
describe the data.

However, in some cases (e.g. when I only have survey estimates that
are quite linear over time but the last estimate is going a bit down)
I would need to constraint b2 that it cannot become negative (if not I
get a curve which is strongly declining which is very unlikely to be
true and is not supported by my data). I wrote the formula (instead of
log4) so I could try to get only positive values for b2 with for
example "invlogit({lnb2})

1. Would this be a valid thing to do?

However, when I try the two commands which I thought should give me
the same results:

nl log4:[VARNAME] [VARNAME] if country=="maldives"


nl ([VARNAME]={b0}+{b1}/(1+exp(-{
b2}*([VARNAME]-{b3}))) if country=="maldives")

I get different estimates (e.g. if I use the second formula I only get
a value for b0).

2. Could you give me advise on how to do curve fitting by using this
function with the constraint that the b2 does not get negative?

Thank you very much.

Best wishes,

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index