Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: optimize with unequality constraints

 From Alberto Dorantes To statalist@hsphsun2.harvard.edu Subject st: optimize with unequality constraints Date Sun, 1 Apr 2012 09:41:24 -0500

```Hi all.
Is there a way to specify unequality constraints to the optimize function
in Mata?
I have f(p) as a function to maximize. I found a way to put an
equality constraint
(the sum of p[i] is equal to one), but I could not specify the non-negative
constraint to each p[i] (p[i]>0).

I read in Statalist that using logs can solve the problem, but I have not
figure out how to transform my p vector to logs since I', afraid that my
function will not work correctly.

To be more specific, here is my code:

mata:
void retorno_ajustado(real scalar todo, real vector p,
real vector R, real matrix COV,
{
ret= p*R' / sqrt(p*COV*p')
}

S = optimize_init()
optimize_init_evaluatortype(S, "d0")
optimize_init_params(S,(0,1))
C=J(1,2,1)
c=(1)
COV=st_matrix("COVA")
R = [0.28, 0.19]
optimize_init_argument(S,1,R)
optimize_init_argument(S,2,COV)
optimize_init_constraints(S,(C,c))
optimize(S)
optimize_result_params(S)
optimize_result_value(S)
end

(COVA is a Var-Cov matrix of 2x2)