Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RES: Estimation of a non-linear system of equations


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: RES: Estimation of a non-linear system of equations
Date   Thu, 20 Dec 2007 08:44:35 -0500

Henrique Neder <[email protected]>:
The FAQ by Feiveson addresses finding solutions to an equation of the
form f(x)=0 where f() is a vector-valued function of a vector x, not
estimating a nonlinear SUR model, which is done via the command
-nlsur- in Stata10:
http://stata.com/help.cgi?nlsur

As for the first problem--finding zeros of some function f(x)--there
is now a better solution in Stata 10.  Use -optimize- in Mata to
minimize the sum of elements of f(x) using evaluator type v0, or
minimize crit=f(x)'f(x) using evaluator type d0.  Or calculate the
gradient of f(x) and use d1 or v1, or the Hessian to use d2 or v2.
See
http://stata.com/help.cgi?mf_optimize
for more details.

Or consider this example:
Suppose you wanted to find the zeros in y = x^2 – 5*x + 4 and you were
too lazy to use the quadratic formula. I chose this problem, of
course, because it has multiple solutions (illustrating the importance
of starting values) and its analytic solution is so easy, whereas the
numerical methods are trickier. You could just type

void q(todo,b,crit,g,H)
{
 crit=(b^2-5*b+4)^2
}
sol=J(1,0,0)
void grid(n1,n2)
{
 external sol, p
 for (i=n1; i<=n2; i++) {
  init=i
  S=optimize_init()
  optimize_init_evaluator(S, &q())
  optimize_init_which(S,"min")
  optimize_init_evaluatortype(S,"d0")
  optimize_init_params(S,init)
  p=round(optimize(S),10e-4)
  if (!anyof(sol, p)) {
   sol=(sol,p)
  }
 }
 sol
}
grid(-10,10)

The above code does the optimization for every starting value on a
grid over the integers -10 to 10 (and saves any solutions that are new
to a Mata variable sol, then reports its values). A function that took
a vector as an argument would be no harder to specify (though the
appropriate grid search might be harder to specify).

On Dec 20, 2007 7:32 AM, Henrique Neder <[email protected]> wrote:
> I copied the following answer to FAC due to Feiveson. I hope that this help
> you. Henrique
>
> How can I use Stata to solve a system of nonlinear equations?
> Title   Using Stata to solve a system of nonlinear equations

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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