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]
st: Logit maximum likelihood in mata code
From
nick bungy <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Logit maximum likelihood in mata code
Date
Fri, 19 Apr 2013 08:34:12 +0100
Dear Statalist,
I'm having trouble setting up the optimizer to find the maximum likelihood of a logit model. I'm still learning the syntax and set up of mata, though I've tried to follow 'help mf_optimize' as best I can.
Could someone assist in where I am going wrong with the code?
----------
sysuse auto, clear
mata
st_view(x=0,.,("weight"))
st_view(y=0,.,("foreign"))
x=x,J(rows(x),1,1)
void logistic(todo, p, y, x, llf, g, H)
{
b = p[1,1::2]
One =J(rows(x),1,1)
llf = y'*log(One:/One+exp(-(x*b)))+(One-y)'*log(One:/One+exp(-(x*b)))
}
S = optimize_init()
optimize_init_evaluator(S, &logistic())
optimize_init_params(S, 0)
optimize_init_argument(S, 1, y)
optimize_init_argument(S, 2, x)
optimize_init_which(S,"max")
p = optimize(S)
-----------
Many thanks,
Nicholas
*
* 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/