Announcement

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

  • error message "=invalid name" encountered

    Hi,

    I'm trying to estimate the following model with mle, but I keep receiving "=invalid name" message. I don't know what went wrong. I checked my program many times. The syntax is consistent with what I read in the manual. Any help?

    The evaluator:

    program define mylike88
    version 11
    args todo b lnf g
    tempvar theta1 theta21 theta22 theta31 theta32 theta41 theta42 theta51 theta52
    mleval `theta1'=`b', eq(1)
    mleval `theta21'=`b', eq(2)
    mleval `theta22'=`b', eq(3)
    mleval `theta31'=`b', eq(4)
    mleval `theta32'=`b', eq(5)
    mleval `theta41'=`b', eq(6)
    mleval `theta42'=`b', eq(7)
    mleval `theta51'=`b', eq(8)
    mleval `theta52'=`b', eq(9)

    tempvar lnfj M1 M2 pd11 pd12 pd13 pw11 pw12 pw13 pd21 pd22 pd23 pw21 pw22 pw23 prob1 prob2 ///
    x11 x12 x13 x21 x22 x23 y11 y12 y13 y21 y22 y23 g111 g112 g113 g121 g122 g123 ///
    g211 g212 g213 g221 g222 g223 g311 g312 g313 g321 g322 g323 g411 g412 g413 g421 ///
    g422 g423 g511 g512 g513 g521 g522 g523 g611 g612 g613 g621 g622 g623 g711 g712 ///
    g713 g721 g722 g723 g811 g812 g813 g821 g822 g823 g911 g912 g913 g921 g922 g923
    quietly gen double `M1'=sqrt(`theta21'^2*`theta41'^2+1)
    quietly gen double `M2'=sqrt(`theta22'^2*`theta42'^2+1)
    quietly gen double `pd11'=normprob((-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32'-`theta22'*`theta42'*(-1.7321))/`M2')
    quietly gen double `pd12'=normprob((-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32')/`M2')
    quietly gen double `pd13'=normprob((-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32'-`theta22'*`theta42'*1.7321)/`M2')
    quietly gen double `pd21'=normprob((`theta1'+`theta22'*$ML_y1-`theta21'*`theta31'-`theta21'*`theta41'*(-1.7321))/`M1')
    quietly gen double `pd22'=normprob((`theta1'+`theta22'*$ML_y1-`theta21'*`theta31')/`M1')
    quietly gen double `pd23'=normprob((`theta1'+`theta22'*$ML_y1-`theta21'*`theta31'-`theta21'*`theta41'*1.7321)/`M1')
    quietly gen double `pw11'=normalden(($ML_y1-`theta31'-`theta41'*(-1.7321))/`theta51')
    quietly gen double `pw12'=normalden(($ML_y1-`theta31')/`theta51')
    quietly gen double `pw13'=normalden(($ML_y1-`theta31'-`theta41'*1.7321)/`theta51')
    quietly gen double `pw21'=normalden(($ML_y1-`theta32'-`theta42'*(-1.7321))/`theta52')
    quietly gen double `pw22'=normalden(($ML_y1-`theta32')/`theta52')
    quietly gen double `pw23'=normalden(($ML_y1-`theta32'-`theta42'*1.7321)/`theta52')

    quietly gen double `prob1'=`pd11'*`pw11'*0.1667+`pd12'*`pw12'*0.6667+ `pd13'*`pw13'*0.1667
    quietly gen double `prob2'=`pd21'*`pw21'*0.1667+`pd22'*`pw22'*0.6667+ `pd23'*`pw23'*0.1667
    quietly gen double `x11'=(-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32'-`theta22'*`theta42'*(-1.7321))/`M2'
    quietly gen double `x12'=(-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32')/`M2'
    quietly gen double `x13'=(-`theta1'+`theta21'*$ML_y1-`theta22'*`theta32'-`theta22'*`theta42'*1.7321)/`M2'
    quietly gen double `x21'=(`theta1'+`theta22'*$ML_y1-`theta21'*`theta31'-`theta21'*`theta41'*(-1.7321))/`M1'
    quietly gen double `x22'=(`theta1'+`theta22'*$ML_y1-`theta21'*`theta31')/`M1'
    quietly gen double `x23'=(`theta1'+`theta22'*$ML_y1-`theta21'*`theta31'-`theta21'*`theta41'*1.7321)/`M1'
    quietly gen double `y11'=($ML_y1-`theta31'-`theta41'*(-1.7321))/`theta51'
    quietly gen double `y12'=($ML_y1-`theta31')/`theta51'
    quietly gen double `y13'=($ML_y1-`theta31'-`theta41'*1.7321)/`theta51'
    quietly gen double `y21'=($ML_y1-`theta32'-`theta42'*(-1.7321))/`theta52'
    quietly gen double `y22'=($ML_y1-`theta32')/`theta52'
    quietly gen double `y23'=($ML_y1-`theta32'-`theta42'*1.7321)/`theta52'
    quietly gen double `g111'=normalden(`x11')*(-1/`M2')*`pw11'*0.1667
    quietly gen double `g112'=normalden(`x12')*(-1/`M2')*`pw12'*0.6667
    quietly gen double `g113'=normalden(`x13')*(-1/`M2')*`pw13'*0.1667
    quietly gen double `g121'=normalden(`x21')*(1/`M1')*`pw21'*0.1667
    quietly gen double `g122'=normalden(`x22')*(1/`M1')*`pw22'*0.6667
    quietly gen double `g123'=normalden(`x23')*(1/`M1')*`pw23'*0.1667
    quietly gen double `g211'=normalden(`x11')*($ML_y1/`M2')*`pw11'*0.1667
    quietly gen double `g212'=normalden(`x12')*($ML_y1/`M2')*`pw12'*0.6667
    quietly gen double `g213'=normalden(`x13')*($ML_y1/`M2')*`pw13'*0.1667
    quietly gen double `g221'=normalden(`x21')*((-`theta31'-`theta41'*(-1.7321))/`M1')*`pw21'*0.1667
    quietly gen double `g222'=normalden(`x22')*((-`theta31')/`M1')*`pw22'*0.6667
    quietly gen double `g223'=normalden(`x23')*((-`theta31'-`theta41'*(1.7321))/`M1')*`pw23'*0.1667
    quietly gen double `g311'=normalden(`x11')*((-`theta32'-`theta42'*(-1.7321))/`M2')*`pw11'*0.1667
    quietly gen double `g312'=normalden(`x12')*((-`theta32')/`M2')*`pw12'*0.6667
    quietly gen double `g313'=normalden(`x13')*((-`theta32'-`theta42'*(1.7321))/`M2')*`pw13'*0.1667
    quietly gen double `g321'=normalden(`x21')*($ML_y1/`M1')*`pw21'*0.1667
    quietly gen double `g322'=normalden(`x22')*($ML_y1/`M1')*`pw22'*0.6667
    quietly gen double `g323'=normalden(`x23')*($ML_y1/`M1')*`pw23'*0.1667
    quietly gen double `g411'=`pd11'*(-exp(-`y11'^2/2)*`y11'/sqrt(2*c(pi)))*(-1/`theta51')*0.1667
    quietly gen double `g412'=`pd12'*(-exp(-`y12'^2/2)*`y12'/sqrt(2*c(pi)))*(-1/`theta51')*0.6667
    quietly gen double `g413'=`pd13'*(-exp(-`y13'^2/2)*`y13'/sqrt(2*c(pi)))*(-1/`theta51')*0.1667
    quietly gen double `g421'=normalden(`x21')*(-`theta21'/`M1')*`pw21'*0.1667
    quietly gen double `g422'=normalden(`x22')*(-`theta21'/`M1')*`pw22'*0.6667
    quietly gen double `g423'=normalden(`x23')*(-`theta21'/`M1')*`pw23'*0.1667
    quietly gen double `g511'=normalden(`x11')*(-`theta22'/`M2')*`pw11'*0.1667
    quietly gen double `g512'=normalden(`x12')*(-`theta22'/`M2')*`pw12'*0.6667
    quietly gen double `g513'=normalden(`x13')*(-`theta22'/`M2')*`pw13'*0.1667
    quietly gen double `g521'=`pd21'*(-exp(-`y21'^2/2)*`y21'/sqrt(2*c(pi)))*(-1/`theta51')*0.1667
    quietly gen double `g522'=`pd22'*(-exp(-`y22'^2/2)*`y22'/sqrt(2*c(pi)))*(-1/`theta51')*0.6667
    quietly gen double `g523'=`pd23'*(-exp(-`y23'^2/2)*`y23'/sqrt(2*c(pi)))*(-1/`theta51')*0.1667
    quietly gen double `g611'=`pd11'*(-exp(-`y11'^2/2)*`y11'/sqrt(2*c(pi)))*(1.7321/`theta51')*0.1667
    quietly gen double `g612'=0
    quietly gen double `g613'=`pd13'*(-exp(-`y13'^2/2)*`y13'/sqrt(2*c(pi)))*(-1.7321/`theta51')*0.1667
    quietly gen double `g621'=normalden(`x21')*(-`theta21'*(-1.7321)/`M1'+`theta21'^3*`theta41'^2*(-1.7321)/`M1'^3)*`pw21'*0.1667
    quietly gen double `g622'=0
    quietly gen double `g623'=normalden(`x23')*(-`theta21'*(-1.7321)/`M1'+`theta21'^3*`theta41'^2*(-1.7321)/`M1'^3)*`pw23'*0.1667
    quietly gen double `g711'=normalden(`x11')*(-`theta22'*(-1.7321)/`M2'+`theta22'^3*`theta42'^2*(-1.7321)/`M2'^3)*`pw11'*0.1667
    quietly gen double `g712'=0
    quietly gen double `g713'=normalden(`x13')*(-`theta22'*(-1.7321)/`M2'+`theta22'^3*`theta42'^2*(-1.7321)/`M2'^3)*`pw13'*0.1667
    quietly gen double `g721'=`pd21'*(-exp(-`y21'^2/2)*`y21'/sqrt(2*c(pi)))*(1.7321/`theta52')*0.1667
    quietly gen double `g722'=0
    quietly gen double `g723'=`pd23'*(-exp(-`y23'^2/2)*`y23'/sqrt(2*c(pi)))*(-1.7321/`theta52')*0.1667
    quietly gen double `g811'=`pd11'*(-exp(-`y11'^2/2)*`y11'/sqrt(2*c(pi)))*(`theta41'*(-1.7321)/`theta51'^2)*0.1667
    quietly gen double `g812'=0
    quietly gen double `g813'=`pd13'*(-exp(-`y13'^2/2)*`y13'/sqrt(2*c(pi)))*(`theta41'*(1.7321)/`theta51'^2)*0.1667
    quietly gen double `g821'=0
    quietly gen double `g822'=0
    quietly gen double `g823'=0
    quietly gen double `g911'=0
    quietly gen double `g912'=0
    quietly gen double `g913'=0
    quietly gen double `g921'=`pd21'*(-exp(-`y21'^2/2)*`y21'/sqrt(2*c(pi)))*(`theta42'*(-1.7321)/`theta52'^2)*0.1667
    quietly gen double `g922'=0
    quietly gen double `g923'=`pd23'*(-exp(-`y23'^2/2)*`y23'/sqrt(2*c(pi)))*(`theta42'*(-1.7321)/`theta52'^2)*0.1667

    quietly gen double `lnfj'=(1-$ML_y2)*ln(`prob1')+$ML_y2*ln(`prob2')
    mlsum `lnf'=`lnfj'
    if (`todo'==0 | `lnf'>=.) exit

    tempname d1 d2 d3 d4 d5 d6 d7 d8 d9
    mlvecsum `lnf'`d1'=(1-$ML_y2)/`prob1'*(`g111'+`g112'+`g113')+$ML_y2/`prob2'*(`g121'+`g122'+`g123'),eq(1)
    mlvecsum `lnf'`d2'=(1-$ML_y2)/`prob1'*(`g211'+`g212'+`g213')+$ML_y2/`prob2'*(`g221'+`g222'+`g223'),eq(2)
    mlvecsum `lnf'`d3'=(1-$ML_y2)/`prob1'*(`g311'+`g312'+`g313')+$ML_y2/`prob2'*(`g321'+`g322'+`g323'),eq(3)
    mlvecsum `lnf'`d4'=(1-$ML_y2)/`prob1'*(`g411'+`g412'+`g413')+$ML_y2/`prob2'*(`g421'+`g422'+`g423'),eq(4)
    mlvecsum `lnf'`d5'=(1-$ML_y2)/`prob1'*(`g511'+`g512'+`g513')+$ML_y2/`prob2'*(`g521'+`g522'+`g523'),eq(5)
    mlvecsum `lnf'`d6'=(1-$ML_y2)/`prob1'*(`g611'+`g612'+`g613')+$ML_y2/`prob2'*(`g621'+`g622'+`g623'),eq(6)
    mlvecsum `lnf'`d7'=(1-$ML_y2)/`prob1'*(`g711'+`g712'+`g713')+$ML_y2/`prob2'*(`g721'+`g722'+`g723'),eq(7)
    mlvecsum `lnf'`d8'=(1-$ML_y2)/`prob1'*(`g811'+`g812'+`g813')+$ML_y2/`prob2'*(`g821'+`g822'+`g823'),eq(8)
    mlvecsum `lnf'`d9'=(1-$ML_y2)/`prob1'*(`g911'+`g912'+`g913')+$ML_y2/`prob2'*(`g921'+`g922'+`g923'),eq(9)
    matrix `g'=(`d1',`d2',`d3',`d4',`d5',`d6',`d7',`d8',`d9')
    end

    Then I run:

    ml model d1 mylike88 (theta1: inc ownership1=age sex educ2-educ8) /theta21 /theta22 (theta31:age sex educ2-educ8 minority party ind2-ind16 emp_type2-emp_type7 emp_nature2-emp_nature4 prov2-prov10 city county city_county)(theta32:age sex educ2-educ8 minority party ind2-ind16 emp_type2-emp_type7 emp_nature2-emp_nature4 prov2-prov10 city county city_county) /theta41 /theta42 /theta51 /theta52
    ml max

    And the result:

    initial: log likelihood = -<inf> (could not be evaluated)
    feasible: log likelihood = -532728.66
    rescale: log likelihood = -27995.494
    rescale eq: log likelihood = -15471.403
    = invalid name
    r(198);

    Oddly the evaluator works for the first four lines, so I guess the problem is not within my evaluator. I have tried everything and run out of ideas. Advices and suggestions are sincerely appreciated.

    Many thanks in advance!

    Andrew
    Last edited by andrewsun; 22 Nov 2014, 16:04.
Working...
X