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

From |
"FEIVESON, ALAN H. (AL) (JSC-SD) (NASA)" <alan.h.feiveson@nasa.gov> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: unconstrained maximization in stata |

Date |
Fri, 28 Feb 2003 13:45:08 -0600 |

Deliana - Here is a reply that I gave to a similar question some time ago: If you want to find a value of x that maximizes an arbitrary function f(x), you might be able to fool -nl- into doing it, provided you can bound the function. Here's how. Suppose you know f(x) < f0 for all x. Then create a dummy data set with two observations as follows: clear set obs 2 gen y=1000 in 1/*(the value of f0)*/ replace y=0 in 2 /* it doesn't matter what y is on obs. 2 as long as it's different from f0 */ nl max y y The last command calls Stata's nonlinear least square -nl- program. To use it you have to write your own nl-program. Here's an example where you are trying to maximize f(x)=x*(x+2)*exp(-0.5*x)/(x+1) for x > 0. program define nlmax if "`1'" == "?" { global S_1 " Z " global Z= 1 exit } cap gen fh=. global X=exp($Z) replace fh=$X*(2+$X)*exp(-.5*$X)/(1+$X) in 1 replace fh=`2' in 2 replace `1' = fh end What this is doing is finding a value of Z = log(x) that makes f(x) come as close to 1000 as possible. Since 1000 is an upper bound on f(x), this will maximize f. Use of log(x) instead of x prevents the consideration of negative values. For example this function has a vertical asymptote at x = -1. Hope this helps. Al Feiveson -----Original Message----- From: Mark Schaffer [mailto:M.E.Schaffer@hw.ac.uk] Sent: Wednesday, October 02, 2002 11:09 AM To: statalist@hsphsun2.harvard.edu Subject: st: Numerical maximization Hi everybody. A very general question for you: What's the recommended strategy if you're writing a Stata estimator that requires numerical maximization methods but isn't maximum likelihood? And if you think you might want to make the estimator available for general use? Stata doesn't have a maximize program as such (-maximize- seems to be an ML program ... but maybe it's good enough for the task?). -findit- told me about a couple of user-written programs called -amoeba- and -quasi-. I have no experience with these, nor with the tradeoffs in writing code that rely on other people's routines. (It's great that they make their code publicly available, but we can't expect them to refrain from changing the specs if they see fit to do so, and of course that could cause your own code to fail to work.) --Mark Prof. Mark E. Schaffer Director Centre for Economic Reform and Transformation Department of Economics School of Management & Languages Heriot-Watt University, Edinburgh EH14 4AS UK 44-131-451-3494 direct 44-131-451-3008 fax 44-131-451-3485 CERT administrator http://www.som.hw.ac.uk/cert * * 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/ -----Original Message----- From: Kostova Deliana (HXX1DAK) [mailto:HXX1DAK@ups.com] Sent: Thursday, February 27, 2003 3:53 PM To: statalist@hsphsun2.harvard.edu Subject: st: unconstrained maximization in stata Hello everybody, I have been trying to maximize a multivariate function using the "amoeba" and "quasi" commands. I found that these commands work very well on some simpler functions but often produce "conformability error" messages on more complicated functions. Also, sometimes amoeba will work great for a particular function, but then if I change the value of just one of the parameters, it starts producing error messages (even though the functional form stayed the same). How can i fix this problem? Is there another way to do unconstrained maximization in Stata? Thanks a lot! Deliana * * 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/ * * 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/

- Prev by Date:
**st: xtpois, fe and constant** - Next by Date:
**st: RE: RE: unconstrained maximization in stata** - Previous by thread:
**st: easy histogram** - Next by thread:
**st: RE: RE: unconstrained maximization in stata** - Index(es):

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