Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: What wrong with this ML model command?


From   Quang Nguyen <[email protected]>
To   [email protected]
Subject   Re: st: What wrong with this ML model command?
Date   Thu, 9 Apr 2009 04:20:52 -1000

I am sorry. Here is the correct code:

 * define KT 1992 SPT specification with no errors
>
> cap program drop MLkt0_1
>
> program define MLkt0_1
> args lnf alpha lambda gamma
> tempvar choiceA prob0_a prob1_a prob0_b prob1_b
>
> tempvar  ya0 ya1 yb0 yb1 y_a0 y_a1 y_b0 y_b1 euA euB euDiff euRatio tmp
>
> quietly {
> generate int `choiceA' = $ML_y1
> generate double `tmp' = (($ML_y2^`gamma')+($ML_y3^`gamma'))^(1/`gamma')
> generate double `prob0_a' = ($ML_y2^`gamma')/`tmp'
> generate double `prob1_a' = ($ML_y3^`gamma')/`tmp'
>
> replace `tmp' = (($ML_y4^`gamma')+($ML_y5^`gamma'))^(1/`gamma')
>
> generate double `prob0_b' = ($ML_y4^`gamma')/`tmp'
>
> generate double `prob1_b' = ($ML_y5^`gamma')/`tmp'
>
> generate double `y_a0' = $ML_y6
>
> generate double `y_a1' = $ML_y7
>
> generate double `y_b0' = $ML_y8
>
> generate double `y_b1' = $ML_y9
>
> generate double `ya0' =.
>
> replace `ya0' = ( `y_a0')^(`alpha') if `y_a0'>=0
>
> replace `ya0' = -`lambda'*(-`y_a0')^(`alpha') if `y_a0'<0
> generate double `ya1' = .
> replace `ya1' = ( `y_a1')^(`alpha') if `y_a1'>=0
> replace `ya1' = -`lambda'*(-`y_a1')^(`alpha') if `y_a1'<0
> generate double `yb0' = .
> replace `yb0' = ( `y_bo')^(`alpha') if `y_b0'>=0
> replace `yb1' = ( `y_b1')^(`alpha') if `y_b1'>=0
> generate double `euA' = (`prob0_a'*`ya0')+(`prob1_a'*`ya1')
> generate double `euB' = (`prob0_b'*`yb0')+(`prob1_b'*`yb1')
> replace `lnf' = ln(normal( `euDiff')) if `choiceA'==1
> replace `lnf' = ln(normal(-`euDiff')) if `choiceA'==0
> }
> end
>





On Thu, Apr 9, 2009 at 4:13 AM, Quang Nguyen <[email protected]> wrote:
> Thanks Glenn for your kind help. I appreciate it. The "set trace on"
> is helpful. I think it is probably a good idea if I post the code here
> so you guys can help me out.
>
> Many thanks!
>
> Here is the code:
>
>


> * define KT 1992 SPT specification with no errors
>
> cap program drop MLkt0_1
>
> program define MLkt0_1
> args lnf alpha lambda gamma
> tempvar choiceA prob0_a prob1_a prob0_b prob1_b
>
> tempvar  ya0 ya1 yb0 yb1 y_a0 y_a1 y_b0 y_b1 euA euB euDiff euRatio tmp
>
> quietly {
> generate int `choiceA' = $ML_y1
> generate double `tmp' = (($ML_y2^`gamma')+($ML_y3^`gamma'))^(1/`gamma')
> generate double `prob0_a' = ($ML_y2^`gamma')/`tmp'
> generate double `prob1_a' = ($ML_y3^`gamma')/`tmp'
>
> replace `tmp' = (($ML_y4^`gamma')+($ML_y5^`gamma'))^(1/`gamma')
>
> generate double `prob0_b' = ($ML_y4^`gamma')/`tmp'
>
> generate double `prob1_b' = ($ML_y5^`gamma')/`tmp'
>
> generate double `y_a0' = $ML_y6
>
> generate double `y_a1' = $ML_y7
>
> generate double `y_b0' = $ML_y8
>
> generate double `y_b1' = $ML_y9
>
> generate double `ya0' =.
>
> replace `ya0' = ( `y_a0')^(`alpha') if `y_a0'>=0
>
> replace `ya0' = -`lambda'*(-`y_a0')^(`alpha') if `y_a0'<0
> generate double `ya1' = .
> replace `ya1' = ( `y_a1')^(`alpha') if `y_a1'>=0
> replace `ya1' = -`lambda'*(-`y_a1')^(`alpha') if `y_a1'<0
> generate double `yb0' = .
> replace `yb0' = ( `y_bo')^(`alpha') if `y_b0'>=0
> replace `yb1' = ( `y_b1')^(`alpha') if `y_b1'>=0
> generate double `euA' = (`prob0_a'*`ya0')+(`prob1_a'*`ya1')
> generate double `euB' = (`prob0_b'*`yb0')+(`prob1_b'*`yb1')
> replace `lnf' = ln(normal( `euDiff')) if `choiceA'==1
> replace `lnf' = ln(normal(-`euDiff')) if `choiceA'==0
> }
> end
>
>
> On Thu, Apr 9, 2009 at 3:43 AM, Glenn Goldsmith
> <[email protected]> wrote:
>> Hi Quang,
>>
>> It looks like a problem with your MLkt0_1 function. You often get this sort
>> of error if you try to use an undefined local macro as a name. Using -set
>> trace on- before running the command should allow you to identify the
>> problem.
>>
>> HTH,
>>
>> Glenn.
>>
>> Quang Nguyen <[email protected]> wrote:
>>
>> Dear All,
>>
>> I had a program called MLkt0_1 to estimate three parameters alpha,
>> lamda, and gamma. However, as I rum the following command:
>>
>> ml model lf MLkt0_1 (alpha: choiceA  p_a0  p_a1  p_b0  p_b1  y_a0
>> y_a1  y_b0 y_b1 =) (lamda:) (gamma:), cluster(id) maximize
>> technique(nr)
>>
>>
>> There's message saying that "," is not a valid name. Do you know what
>> may cause this?
>>
>> Many thanks!
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>
>
>
> --
> "My father gave me the greatest gift anyone could give another person,
> he believed in me." - Jim Valvano
>
--
"My father gave me the greatest gift anyone could give another person,
he believed in me." - Jim Valvano

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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