Announcement

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

  • nl using a function evaluator program

    Hello to all,

    I want to estimate the parameters of a nonlinear equation via a function evaluator program. For this purpose, first, I simulate the data involved in the function:
    Code:
    gen demand= rnormal(100,40)
    
    gen price=0.3 * (demand/10)^(2.5-1) + rnormal(0, 1)
    And then I employed the function evaluator program as the following:

    Code:
    capture program drop nlces
    
    program nlces
    
    version 12
    
     syntax varlist(min=2 max=2) [if], at(name)    
    
    //Retrieve the Stata variables from the varlist, use local statements
    
     local price: word 1 of `varlist'
    
     local demand: word 2 of `varlist'
    
    //Retrieve the parameters from the matrix specified in at(name), use:
    
    //and reference the parameters as local macros within the program.
    
    tempname a c
    
     scalar `a' = `at'[1,1]
    
     scalar `c' = `at'[1,2]
    
    // Some temporary variables
    
     tempvar dterm
    
     gen double `dterm' =(`demand'/10)^(`c'-1) `if'
    
     // Now fill in dependent variable
    
     replace `price' = `a'*`dterm' `if'
    
    end
    
    
    
    
     //Call nl like this, specifying initial values for some or all of the parameters:
    
    nl ces @ price demand, parameters(a c)///
    
    initial(a 0.0001 c 1)
    However I got the error “nlces returned 198, verify that nlces is a function evaluator program”


    I dont see the problem, as I have used the same kind of program with a ces production function and it works perfectly. Can someone help me to solve this? Thank you in advance!

  • #2
    Please cross-reference your earlier thread so that interested people do not duplicate previous comments.

    Comment


    • #3
      @Nick Cox

      I am a new user and I dont know how to cross-reference, if you mean this: https://www.statalist.org/forums/for...or-please-help

      In any case, this can be considered as another question and I am trying to learn how nl works in several cases, I dont see how the previous question can help me to solve this. Yes, I agree that the using the command nl alone is solving the questing without the need of this. And I also know that ml will bring the same results if I am assuming that the errors are normal. But please, help me to learn.

      Thanks!

      Comment


      • #4
        That is a cross-reference exactly as requested.

        I have already made several suggestions on your project and don't have anything else to add. Trying to debug a complicated solution when there is a simple solution just does not appeal to me. Sorry.

        This thread is naturally wide open to anyone else

        Comment


        • #5
          Nick Cox there is nothing to add to this post if you do not want. Still do not understand why then to take the time to answer that my question does not make sense instead of leaving the space to others to hep it. I am learning techniques and I am using examples just to learn. Its funny how knowledge seems difficult to share once you have it. Thank you in any case and lets hope someone can just simple help a beginner. Best.

          Comment


          • #6
            Where do I say that your question "does not make sense"? I've only said that I have made several comments on your project and don't wish to add to them.

            https://www.statalist.org/forums/help#adviceextras #1 gives the advice repeated in #2 in this thread: if you start a new thread related to an old one, then give a cross-reference. You may have missed that advice, but it is there. As you are anxious to learn, learning about Statalist procedures is part of that.

            Comment


            • #7
              Hi Veridiana,
              I think we have gone off track on your original post. So perhaps your question re-statement requires a different question.
              1. I cannot make more comments on the -nl- program evaluator, since I have never used it myself. I prefer -ml-.
              2. -ml- does not require normality assumption. The way it works, it can be used to estimate any kind of m-estimator. Including Non-linear least squares. However, you need to add the option robust, if you use it as a non-linear least squares estimator.
              3. I think the problem with the example you provide is not related to the evaluator but with the data generation.

              As I mentioned earlier in the other post, the way you generate your data "demand" also creates negative values on that variable. because of that, the expression "demand^{a}" will be numerically undetermined whenever "demand" is negative, which appears as missing values for the -nl- maximizer.

              Unfortunately, -nl- and -ml-, do not handle well missing values like that. Usually, missing values indicate that a particular solution (for the parameters) is not a feasible solution, and tries to warn you, and keep you away from that. But in this case, because your example is will always have missing values, there is nothing -ml- can do.

              For your specific example,
              you can either use a different data generating process:

              gen demand= abs(rnormal(100,40))

              Or Impose some data restriction when you call your model estimator

              nl ces @ price demand if demand>1 , parameters(a c) initial(a 0.0001 c 1)

              HTH

              Comment

              Working...
              X