Bookmark and Share

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Optimize for 2 unknowns looping over observations using Mata


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: RE: Optimize for 2 unknowns looping over observations using Mata
Date   Tue, 6 Mar 2012 08:31:25 +0000

The error message shows that you asked Mata to use "s", but it could
not find any such beast. So, you need to look for references to "s",
which are likely to be typos or premature references. Have a careful
look at

optimize_init_evaluatortype(s,"v0")

Nick

On Mon, Mar 5, 2012 at 9:02 PM, William Pratt <[email protected]> wrote:
> Nick and Tim,
> Thank you for your comments, I greatly appreciate your suggestions.
> Defining i, changing (optimize_init_argument), and moving the location
> within the loop did produce what I would consider an improvement (less
> error responses), however I still receive "3499 s not found". Any
> additional ideas?, thank you again.
>
> William
>
> On Mon, Mar 5, 2012 at 10:56 AM, Mak, Timothy
> <[email protected]> wrote:
>>
>> Hi,
>>
>> I think it may be that you've mis-written your arguments for your function:
>>
>> Instead of (todo, p, x, lnf, g, H)
>>
>> it should be (todo, p, i, lnf, g, H)
>>
>> Still, I think a better way of writing your function would be to take your line:
>>
>>      x = st_data( i,("sige", "Ix", "divrate", "rf", "time", "ve", "sqrtT"))
>>
>> out of your function, and put it in your loop. And replace:
>>
>>        optimize_init_argument(S,1,i)
>>
>> with
>>
>>        optimize_init_argument(S,1,x)
>>
>> Hope that helps.
>>
>> Tim
>>
>> **time and sqrtT are constant
>> **sige, Ix, divrate, rf, ve
>>
>>
>> gen double a = .
>> gen double b = .
>> mata
>> void bsmp0(todo, p, x, lnf, g, H)
>>  {
>>      a = p[1]
>>      b = p[2]
>>      x = st_data( i,("sige", "Ix", "divrate", "rf", "time", "ve", "sqrtT"))
>>
>>        f1= a * exp(-x[3]*x[5])*(normal(ln(a/x[2])+x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))
>>        f2= x[2]*exp(-x[4]*x[5])*(normal(ln(a/x[2])+x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))
>>
>>        f3= (1-exp(-x[3]*x[5]))*a-x[6]
>>        f4=  ((a*b*exp(-x[3]*x[5]))/x[6])*normal(ln(a/x[2])+
>> x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))-x[1]
>>        lnf = (f1-f2)^2+(f3-f4)^2
>> }
>>  for(i=1;i<=st_nobs();i++) {
>>   S = optimize_init()
>>   optimize_init_evaluator(S, &bsmp0())
>>   optimize_init_evaluatortype(s,"v0")
>>   optimize_init_params(S,(0,0))
>>   optimize_init_argument(S,1,i)
>>  p = optimize(S)
>>  st_store(i,"va", a)
>>  st_store(i,"siga", b)
>>   }
>> end
>>
>>
>> After trying numerous combinations based on help, the mata manual and
>> online guides, I am not sure how to proceed.
>>
>> Thanks for your consideration,
>>
>> William
>>
>>
>> . mata
>> ------------------------------------------------- mata (type end to
>> exit) ----------------------------------------
>>
>> : void bsmp0(todo, p, x, lnf, g, H)
>> >  {
>> >       a = p[1]
>> >       b = p[2]
>> >       x = st_data( i,("sige", "x", "divrate", "r", "time", "ve", "sqrtT"))
>> >
>> > f1= a * exp(-x[3]*x[5])*normal(ln(a/x[2])+x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))
>> too many ')'
>> r(3000);
>> :
>> : f2= x[2]*exp(-x[4]*x[5])*normal(ln(a/x[2])+x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))
>> too many ')'
>> r(3000);
>> :
>> : f3= (1-exp(-x[3]*x[5]))*a-x[6]
>>                 <istmt>:  3499  x not found
>> r(3499);
>> :
>> : f4=  ((a*b*exp(-x[3]*x[5]))/x[6])*normal(ln(a/x[2])+
>> x[5]*(x[4]-x[3]+(b^2/2)))/(b*x[7]))-x[1]
>> too many ')'
>> r(3000);
>> :
>> : lnf = (f1-f2)^2+(f3-f4)^2
>>                 <istmt>:  3499  f1 not found
>> r(3499);
>> :
>> : }
>> expression invalid
>> r(3000);
>> :
>> :   for(i=1;i<=st_nobs();i++) {
>> >    S = optimize_init()
>> >    optimize_init_evaluator(S, &bsmp0())
>> >    optimize_init_evaluatortype(s,"v0")
>> >    optimize_init_params(S,(0,0))
>> >    optimize_init_argument(S,1,i)
>> >   p = optimize(S)
>> >   st_store(i,"va", a)
>> >   st_store(i,"siga", b)
>> >    }
>>                 <istmt>:  3499  s not found
>> r(3499);
>>
>>
>> --

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index