Announcement

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

  • Maximum Likelihood - unknown function 1-() error

    Hello,

    I defined the following maximum likelihood program for bivariate probit model.

    program define mybiprobt
    args lnf theta1 theta2 theta3
    tempvar TH
    quietly gen double `TH'=((exp(`theta3')-exp(-`theta3'))/(exp(`theta3')+exp(-`theta3')))
    quietly replace `lnf'=(ln(binorm(-`theta1',-`theta2',`TH'))-ln((1–(normprob(-‘theta2'))^131)^(1/48))) if $ML_y1==0 & $ML_y2==0
    quietly replace `lnf'=(ln(binorm(-`theta1',`theta2',-`TH'))-ln((1–(normprob(-‘theta2'))^131)^(1/48))) if $ML_y1==0 & $ML_y2==1
    quietly replace `lnf'=(ln(binorm(`theta1',-`theta2',-`TH'))-ln((1–(normprob(-‘theta2'))^131)^(1/48))) if $ML_y1==1 & $ML_y2==0
    quietly replace `lnf'=(ln(normprob(`theta2')-binorm(-`theta1',`theta2',-`TH'))-ln((1–(normprob(-‘theta2'))^131)^(1/48))) if $ML_y1==1 & $ML_y2==1
    end

    STATA gave me an error "unknown function 1-()" after

    . quietly replace `lnf'=(ln(binorm(-`theta1',-`theta2',`TH'))-ln((1–(normprob(-‘theta2'))^131)^(1/48))) if $ML_y1==0 & $ML_y2==0

    I read on a previous STATA list, William Gould of Stata Corp once stated "Never code 1-normprob(z). Code instead normprob(-z), which is far more accurate."

    However, as you can see in the above code, I have 1-(normprob(z)^131) instead of 1-normprob(z).
    It cannot be easily converted it into a form without using 1-() and I cannot think of any solution so far.

    On the other hand, I see sometimes people use 1-normprob(z) in their program without encountering errors.

    I read "Maximum Likelihood Estimation with Stata", but I haven't found a solution so far.

    If anyone could suggest me a way to avoid the error, I would very much appreciate it.

    Hitomi


  • #2
    Hitomi,

    I don't think your problem has anything to do with maximum likelihood or with 1-normprob(). For starters, the leading single quote in 1–(normprob(-‘theta2') is not the right type (use the same ones as you used earlier in the equation).

    You should still be mindful of Bill Gould's advice regarding 1-normprob(), but the problem he is warning about is one of accuracy, not one that will result in a syntax error.

    Regards,
    ​Joe

    Comment


    • #3
      Hi

      As Joe points out, there is a syntax error in your code concerning `theta2'. I would add that you should not use the normprob() function as it is out of date (type help normprob()). Use the normal() function instead.
      Best
      Christophe

      Comment


      • #4
        Hitomi,

        It's hard to tell whether you fixed the single quotes in the theta2 references. However, fixing those will not entirely fix your problem. It turns out the problem is with the minus sign in 1(normprob(x). Somehow you ended up with a dash(–) instead of a hyphen(-), which is what Stata needs for a minus sign.

        Here is your code:
        Code:
        -ln((1–(normprob(-‘theta2'))^131)^(1/48))
        Here is what you need:
        Code:
        -ln((1-(normprob(-`theta2'))^131)^(1/48))
        Sometimes very subtle problems can cause very confusing errors.

        Regards,
        Joe

        Comment


        • #5
          Glad it worked...It was actually kind of lucky that I spotted it. I was testing out the code and getting the same error you were, but then when I pressed PageUp to try the code again, I noticed that the command window had replaced the errant dash with some other character, which is when I started to get suspicious.

          Comment

          Working...
          X