Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: nonlinear constraints


From   Richard Williams <[email protected]>
To   [email protected], [email protected]
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: [email protected]
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/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index