Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: mle stata program
From
Matthew J Baker <[email protected]>
To
[email protected]
Subject
Re: st: mle stata program
Date
Tue, 8 Mar 2011 07:06:56 -0500 (EST)
It looks as though there could be two potential problems: one
with the Stata programming, and the other with the likelihood
function. To address the first problem, it looks like you are
calling the second dependent variable incorrectly. Rather than:
ml model lf myml (Y = x q r) /theta /sigma
You probably want something like:
ml model lf myml (Y x= q r) /theta /sigma
or even
ml model lf myml (Y=q r) (x=) ()
The second problem is it looks like you have forgotten a squared
term in the likelihood function (I'm guessing that you are trying
to estimating a normal, linear model with heteroskedasticity). So
it should read:
`lnf'=-0.5 * ln(`w')-0.5*($ML_y1-`xb')^2/`w'
Not
`lnf'=-0.5 * ln(`w')-0.5*($ML_y1-`xb')/`w'
Here is a little fictional program that seems to have the desired
effect:
// Begin program:
clear*
set obs 10000
set seed 8675309
gen q=invnormal(runiform())
gen r=invnormal(runiform())
gen v=invnormal(runiform())
scalar t=1.7
scalar s=1.1
gen w=v^2*t^2+s^2
gen y=1+.1*q+.2*r+sqrt(w)*invnormal(runiform())
capture program drop myml
program myml
version 9.2
args lnf xb theta sigma
tempvar w
quietly {
gen double `w'=$ML_y2^2*`theta'^2+`sigma'^2
replace `lnf'=-.5*ln(`w')-.5*($ML_y1-`xb')^2/`w'
}
end
ml model lf myml (y= q r) (v= ) ()
ml check
ml maximize
// end program
Hope that helps!
Matt Baker
Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY
---- Original message ----
>Date: Tue, 8 Mar 2011 10:47:41 +0800
>From: [email protected] (on behalf of Jian
Zhang <[email protected]>)
>Subject: Re: st: mle stata program
>To: [email protected]
>Cc: Matthew J Baker <[email protected]>
>
>there is actually only one equation. The ml model is: ml
model lf
>myml (Y = x q r) /theta /sigma
>
>x, q and r are the set of independent variables (i.e., Z). The
>complicated thing is that x, as one individual independent
variable,
>enters the log likelihood function by itself, appearing in the log
>likelihood function as: (xi^2* theta^2 + sigma^2). In the
program, I
>use $ML_y2 to indicate x.
>
>Anything wrong? thanks
>
>Jian
>
>On Tue, Mar 8, 2011 at 3:54 AM, Matthew J Baker
><[email protected]> wrote:
>> I can't find anything wrong with the program, but I am a
little
>> confused as to why "w" is introduced as a variable and then
>> replaced. Might it be better to do something like:
>>
>> program myml
>> version 9.2
>> args lnf xb theta sigma
>> tempvar w
>> quietly {
>> gen double `w'=$ML_y2^2*`theta'^2+`sigma'^2
>> replace `lnf'=-0.5 * ln(`w')-0.5*($ML_y1-`xb')/`w'
>> }
>> end
>>
>> Also, what does the corresponding ml model statement look
like
>> for the program?
>>
>> Best regards,
>>
>> Matt Baker
>>
>> Dr. Matthew J. Baker
>> Department of Economics
>> Hunter College and the Graduate Center, CUNY
>>
>> ---- Original message ----
>>>Date: Mon, 7 Mar 2011 15:35:23 +0000
>>>From: [email protected] (on behalf of
>> Alfonso Miranda <[email protected]>)
>>>Subject: Re: st: mle stata program
>>>To: Statalist <[email protected]>
>>>
>>>Dear Jian,
>>>
>>>What is $ML_y2^2? Do you have more than one equation?
>>>
>>>Best,
>>>
>>>Alfonso.
>>>
>>>
>>>On 07/03/2011 15:23, "Jian Zhang" <[email protected]>
>> wrote:
>>>
>>>> Hello all,
>>>>
>>>> below is the loglikelihood function i'd like to maximize
with
>> stata.
>>>> I wrote some program but it did not work. Could some
one
>> give me some
>>>> help?
>>>>
>>>> the log likelihood function for the ith observation: lnYi=-
0.5 *
>>>> ln(2pi) - 0.5ln(xi^2* theta^2 + sigma^2) -0.5 (lnYi -
Beta*
>> Zi)^2
>>>> /(xi^2* theta^2 + sigma^2), where Yi is the dependent
>> variable, Zi is
>>>> the set of independent variables and xi is ONE
independent
>> variable
>>>> from the set Zi. pi, theta and sigma are the parameters
to
>> be
>>>> estimated via ml
>>>>
>>>> Corresponding to the log likelihood function is the
program I
>> wrote:
>>>>
>>>> program myml
>>>> version 9.2
>>>> args lnf xb w theta sigma
>>>> quietly {
>>>> replace `w'=$ML_y2^2*`theta'^2+`sigma'^2
>>>> replace `lnf'=-0.5 * ln(`w')-0.5*($ML_y1-`xb')/`w'
>>>> }
>>>> end
>>>>
>>>> But Stata said the program does not work. Is there
>> something wrong
>>>> with the program?
>>>>
>>>> Many thanks!
>>>>
>>>> Jian
>>>>
>>>> *
>>>> * 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/
>>>
>>>
>>>*
>>>* 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/
>>
>> *
>> * 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/
>>
>
>*
>* 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/
*
* 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/