Bob,
To get you're existing code to work, you need to pass "i" to your -eval0()-
function as an argument, using -optimize_init_arguments()- (see -help
mf_optimize- for details). You'll also need to modify -eval0()- slightly to
take the argument.
E.g.
*************************************************
void eval0(todo, x, real scalar i, v, g, H)
{
z = st_data(i,"z")
v = -(x-z)^2
}
for(i=1;i<=st_nobs();i++) {
S = optimize_init()
optimize_init_evaluator(S, &eval0())
optimize_init_params(S, 0)
optimize_init_argument(S,1,i)
x = optimize(S)
st_store(i,"x2",x)
}
*************************************************
In theory you could also accomplish this sort of thing without using
explicit loops, by coding a v-type evaluator that optimizes for a
(row)vector x rather than a scalar. But that's likely to be a pretty
inefficient way of proceeding here.
Hope that's somewhat useful.
Glenn.
*
* 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/