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

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

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

Subject |
st: RE: RE: RE: unconstrained maximization in stata |

Date |
Mon, 3 Mar 2003 08:25:56 -0600 |

Deliana - You can have have as many variables as you like. They would appear in the first -nl- global statement as "parameters"; e.g. global S_1 " Z X Y" then later, you might have something like cap gen fh=. global X=exp($Z) replace fh=$X*(2+$X+$Y)*exp(-.5*$X/$Z)/(1+$X+$Y+$Z) in 1 replace fh=`2' in 2 replace `1' = fh Of course, if your function is not convex or concave, you might not converge to a global max or min. How you obtain first guesses (defined in the first part of the -nl- program) would then be extremely important. Al Feiveson -----Original Messa ge----- From: Kostova Deliana (HXX1DAK) [mailto:HXX1DAK@ups.com] Sent: Friday, February 28, 2003 2:05 PM To: statalist@hsphsun2.harvard.edu Subject: st: RE: RE: unconstrained maximization in stata thank you so much Al. Is your method easily extendable to multivariate functions? I have to maximize a pretty long function with respect to 7 variables...Deliana -----Original Message----- From: FEIVESON, ALAN H. (AL) (JSC-SD) (NASA) [mailto:alan.h.feiveson@nasa.gov] Sent: Friday, February 28, 2003 2:45 PM To: 'statalist@hsphsun2.harvard.edu' Subject: st: RE: unconstrained maximization in stata 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/ * * 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: RE: RE: out-of-date commands** - Next by Date:
**st: RE: Re: equation** - Previous by thread:
**st: out-of-date commands** - Next by thread:
**st: RE: Re: equation** - Index(es):

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