Hi Statalist,

I am trying to minimize the below objective function in Stata using optimize command in order to estimate m and n. But, I having a tough time to write the objective function.
sum ((A-B-(m-n)*(wc*A-wC*B)- n* (wc* (1-G_near)/Apdf - (1-GG)/Bpdf))^2)

I tried the below code, but did not get what I expected. Any help would be appreciated. Thanks!
Code:
a = st_data(.,"A_near")
b = st_data(.,"G_near")
c = st_data(.,"Apdf_near")
d = st_data(.,"B")
e = st_data(.,"GG")
f = st_data(.,"Bpdf")
g = st_data(.,"wC")
h = st_data(.,"wc")


void myeval(todo, p, a, b, c, d, e, f,g,h, opt,S,H)
{
m = p[1]
n = p[2]

opt = sum((a-d-(m-n)*(h*a-g *d)-n*(h *((1:-b):/c)-g *(1:-e):/f)):^2)
}
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(wC GG B) double Bpdf int nbidder float(wc G_near A_near) double Apdf_near
 .09301207 .00053518865  .0748278  .0602234952547114 2 .03862784 .0005366247 .04292616 .05693702920208285
   .178657   .001070664 .07697561 .06195721358048675 2  .0241337 .0010735376  .0440171 .05769971760416821
 .12923165  .0016064268 .08090728 .06538882418743933 2  .1563326 .0016107393  .0440171 .05769971760416821
 .06555109  .0021424768 .09154756 .07366921292444421 2 .29573992   .00214823 .09017445 .09163196749500602
.032069378   .002947093 .12422522 .09576766770922014 2  .4114528  .002686011 .09017445 .09163196749500602
  .3071286  .0032154424 .12944987 .09932511791771523 2  .2414842 .0032240814 .11403993 .10556013439954556
  .3658912  .0037523585 .14428443 .10858489728427703 2  .4810045  .003762443 .11403993 .10556013439954556
 .21328142    .00482706 .15038234 .11147477332017262 2  .1758451  .004840039 .12271439 .10975102905271232
    .45325   .005902923  .1663317 .11723071716814493 2  .5664513  .005918804 .13202655 .11398269124038349
 .02353744   .006441291  .1691902 .11803267701459642 2  .6048799  .006458625 .14183159 .11843745610814434
end