# Re: st: nonlinear constraints

 From Richard Williams To statalist@hsphsun2.harvard.edu, statalist@hsphsun2.harvard.edu Subject Re: st: nonlinear constraints Date Wed, 14 Feb 2007 07:03:14 -0500

```At 06:11 AM 2/14/2007, Maarten buis wrote:
```
```--- Valérie Orozco:
> I also want to impose nonlinear constraints and I don't find
> any way to do it.

The only way to impose non-linear constraints in Stata is to
write your own -ml- program in which the constraint is hard
coded. An example of such a program can be found in the appendix
of (Hauser and Andrew 2006), though it has some bad programming
style, especially doing some intermediate calculations by
creating a variable that is a float and not a double. These
models tend to have a pretty hard time converging, and appear to
be particularly sensitive to loss of precision in intermediate
calculations.
```
As Maarten notes, the program printed in the Hauser and Andrew paper is sub-optimal because it does not use double precision. Part of their code is

program define pplogit
tempname theta
version 6
args lnf theta1 theta2 theta3
gen `theta' = `theta1' + `theta3' + (`theta2'*`theta3')
quietly replace `lnf' = ln(exp(`theta')/(1+exp(`theta'))) if
\$ML_y1==1
quietly replace `lnf' = ln(1/(1+exp(`theta'))) if \$ML_y1==0
end

If anyone is using it, I've found that this relatively simple tweak makes it run much more quickly and (presumably) accurately.

program define pplogit
tempvar theta
version 6
args lnf theta1 theta2 theta3
gen double `theta' = `theta1' + `theta3' + (`theta2'*`theta3')
quietly replace `lnf' = ln(exp(`theta')/(1+exp(`theta'))) if \$ML_y1==1
quietly replace `lnf' = ln(1/(1+exp(`theta'))) if \$ML_y1==0
end

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc

*
* 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/