Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zero root of one single equation

    Hi.

    I want to find the zero root of one single equation. I know how to find roots for a system of nonlinear equations. I also know the mm_root() function. But in my case, this function returns just a missing value. My code is as follows:

    Code:
    mata
    mata clear
     function myfunc(n, k1, t1, t3, p) return(-k1+ (n/(1-p))*(((1-t1)*k1/n)^(1-p))-n*((1-t3)^(1/p-1))*(p/(1-p)))
     k1 = 52000
     t1 = 0.07
     t3 = 0.5
     p=1/(0.8+1)
     mm_root(n=., &myfunc(), 0, 1000000, 0, 1000, k1, t1, t3, p)
     n
    end
    So the problem seems to be that the functions evaluates to missing at some point in the algorithm. Solving the same equation in Matlab or Julia works fine, but I need to use stata here.

    So I end up with two questions:
    1) Did I do something wrong when applying the mm_root() function?
    2) Are there any alternatives?

    Thank you for your help!



  • #2

    There are two problems with your code:

    1. Your lower limit for the search is n = 0 but your function contains a term in k1/n, which is undefined at n = 0. Up the lower-limit.
    2. You have too few iterations. Up the value to, say, 10,000.

    Note: Long-standing Statalist practice is to register with full, real names, first and last (FAQ Section 6). Please re-register; use the CONTACT US button at the bottom right of the screen. The FAQ also ask that we identify the source of contributed commands. mm_root() is a function in Ben Jann's moremata package, available via ssc.
    Last edited by Steve Samuels; 22 Feb 2015, 21:50.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      Actually, it looks like 1,000 iterations was fine (I needed a higher number in some experiments with other values), Therefore th missing value was for n was due entirely to the the zero lower limit.
      Last edited by Steve Samuels; 22 Feb 2015, 22:46.
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment

      Working...
      X