Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Ozgur Ererdem <ozgur.ererdem@ecopa.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: Maximizing under constraint with Mata ? |
Date | Fri, 14 Sep 2012 17:32:33 +0000 |
Dear Stata users, I've been trying to implement an optimization under constraint, using the optimize() command of Mata. Both the function I'm willing to maximize and the constraint are non-linear. Below please find the code I am using to define the Lagrange function denoted as "Ref". p[K] is the Lagrange multiplier, and the other p[i]s are the unknown parameters I am looking for. I use a "d0" evaluatortype. Mata have been unable to find a solution, because it "cannot calculate numerical derivatives -- discontinuous region with missing values encountered" Am I making a mistake in the way I write the problem? Has Mata the capacity to solve these kinds of optimization problems? Thank you very much for your help. Regards void mysolver(todo, p, Ref, S,H ) {external alpha, w, M, txm, k, X delta = J(k, 1, 0) for (i=1; i<=k; i++) { delta[i] = exp(X[i] + alpha*(p[i]*1.196)) } S0 = runningsum(delta) CA = J(k, 1, 0) for (i=1; i<=k; i++) { CA[i] = p[i]*( (delta[i]/(1+S0[k]))*M ) } CAtot = runningsum(CA) CT = J(k, 1, 0) for (i=1; i<=k; i++) { CT[i] = w[i]*( (delta[i]/(1+S0[k]))*M ) } CTtot = runningsum(CT) K = k+1 Ref = J(1,1,0) Ref = CAtot[k] + p[K]*(((1-txm)*CAtot[k]) - CTtot[k]) } Özgür Kaan Ererdem Economist ECOPA Tél: +33 4 20 04 00 42 Fax: +33 5 67 69 91 06 ozgur.ererdem@ecopa.com www.ecopa.com * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/