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

From |
Bob Hammond <robert_hammond@ncsu.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Using for within Mata optimize to loop over observations |

Date |
Mon, 16 Feb 2009 21:20:50 -0500 |

Glenn,

>>>>>>>>>>>>>>

>>>>>>>>>>>>>>

Bob Glenn Goldsmith wrote:

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

-- ------------------------------------------------------------------------ Bob Hammond Department of Economics North Carolina State University Office: (919) 513-2871 Fax: (919) 515-7873 http://www4.ncsu.edu/~rghammon/ * * 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/

**Follow-Ups**:**RE: st: Using for within Mata optimize to loop over observations***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: Using for within Mata optimize to loop over observations***From:*"Glenn Goldsmith" <glenn.goldsmith@gmail.com>

- Prev by Date:
**st: A problem with temporary file** - Next by Date:
**st: Quadratic regression** - Previous by thread:
**st: Using for within Mata optimize to loop over observations** - Next by thread:
**RE: st: Using for within Mata optimize to loop over observations** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |