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: problem 0 likelihood ml
From
Olivier Francois <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: problem 0 likelihood ml
Date
Fri, 16 Nov 2012 15:55:15 +0000
Nick, Maarten,
Thank you very much for clarifying that.
Apologies for not spotting this problem, even though I have struggled with if before.
The probit now works, but I still have the problem if I list more than one technique.
The code has become the following:
//creating the data
clear
set more off
set seed 12345
set obs 1000
matrix C = I(4)
drawnorm z v e x, corr(C)
replace z = sqrt(2)*z
scalar a0 = 2
scalar a1 = -1
gen D = (a0 + a1*z > v)
gen Y = 0.5 - 0.5*x + e
//Probit model
apture program drop myprobit
program myprobit
version 11.2
args lnf xgam
quietly {
replace `lnf' = ln(normal(-`xgam')) if $ML_y1 == 0
replace `lnf' = ln(normal(`xgam')) if $ML_y1 == 1
}
end
ml model lf myprobit (xgam: D = z), vce(robust) technique(nr bhhh)
ml check
/*It works fine with just one technique (any), but come back with the following error if I combine more than one technique:
opt__eval_cycle(): 3301 subscript invalid
opt__eval(): - function returned error
_optimize_evaluate(): - function returned error
_mopt__evaluate(): - function returned error
mopt__check_test1(): - function returned error
_moptimize_check(): - function returned error
Mopt_check(): - function returned error
<istmt>: - function returned error
*/
________________________________________
From: [email protected] [[email protected]] on behalf of Maarten Buis [[email protected]]
Sent: Friday, November 16, 2012 10:08 AM
To: [email protected]
Subject: Re: st: problem 0 likelihood ml
On Fri, Nov 16, 2012 at 3:45 PM, Olivier Francois wrote:
> I needed to create my own likelihood function and have been running into problems. I have been trying to use program and the ml commands, but there is something I must not do correctly.
<snip>
> if $ML_y1 == 0 {
> replace `lnf' = ln(normal(-`xgam'))
> }
>
> else if $ML_y1 == 1 {
> replace `lnf' = ln(normal(`xgam'))
> }
The way you have used -if- means that it takes a scalar, in this case
the first observation of the dependent variable, and checks whether it
is 0 or 1, and applies the likelihood computation for all observations
based on that test, compare -help if- with -help ifcmd-. What you want
is to tell Stata to check for each observation whether the dependent
variable is 0 or 1 and choose the appropriate log likelihood function
accordingly. You can do that as folows:
replace `lnf' = ln(normal(-`xgam')) if $ML_y1 == 0
replace `lnf' = ln(normal( `xgam')) if $ML_y1 == 1
alternatively:
replace `lnf' = $ML_y1*ln(normal(`xgam') + (1-$ML_y1)*ln(normal(-`xgam'))
The latter will allow you to estimate a probit and a fractional probit.
Hope this helps,
Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/