Bookmark and Share

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: RE: Discrete choice in MATA


From   Timothy Mak <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Discrete choice in MATA
Date   Fri, 21 Jun 2013 10:12:27 +0800

Hi, 

Discrete choice models are well-covered by Stata commands such as -clogit- and -asclogit-. 
http://www.ats.ucla.edu/stat/stata/seminars/stata10/choice_models.htm 

Why do you want to implement them yourself? 

Tim

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Henk-Wim de Boer
Sent: 20 June 2013 22:37
To: '[email protected]'
Subject: st: Discrete choice in MATA

Hello,

I am relatively new at MATA and I am trying to program maximum likelihood estimation for my discrete choice model.
The labour supply model allows for 6 labour supply alternatives at the individual level and an example is included below for an individual:

Id            h         y_1            l
 1            0            2           80
1             8            4           72
1             16           6           64
1             24           8           56
1             32          10           48
1             40          12           40

The model can be estimated by maximum likelihood, where the log likelihood is as follows: ln(L) = ln{ exp(xb)/sum(exp(xb)) } over all individuals. 
This works well in STATA by using ml model but I now want to program it in MATA. The difficulty here is constructing the denominator, i.e  the summation of exp(xb) over all alternatives.

My code is as follows:

mata

st_view(X=0,.,("lny_1", "lnl"))
st_view(y=0,.,("choice"))

void logistic(todo, p, y, X, lf, g, H)
{
b = p[1, (1::cols(X))]'    /* Transpose such that b is a column vector*/

denom = colsum(exp(X*b)) /*HERE I NEED TO SUM OVER THE ALTERNATIVES PER INDIVIDUAL , WHICH DOES NOT WORK FOR ME*/

lf = y' * ln(exp(X*b)/denom)

}


S = optimize_init()
optimize_init_evaluator(S, &logistic())
optimize_init_params(S, (0, 0))     /* One extra element. Starting values are (0, 0)*/
optimize_init_argument(S, 1, y)
optimize_init_argument(S, 2, X)
p = optimize(S)

p

end

Can anyone please help me out?

Henk-Wim de Boer



--
================================================================================
Dit bericht kan informatie bevatten die niet voor u is bestemd. Indien u niet
de geadresseerde bent of dit bericht abusievelijk aan u is toegezonden, wordt
u verzocht dat aan de afzender te melden en het bericht te verwijderen.
De Staat aanvaardt geen aansprakelijkheid voor schade, van welke aard ook, die
verband houdt met risico's verbonden aan het elektronisch verzenden van
berichten.

This message may contain information that is not intended for you. If you are
not the addressee or if this message was sent to you by mistake, you are
requested to inform the sender and delete the message. The State accepts no
liability for damage of any kind resulting from the risks inherent in the
electronic transmission of messages.
================================================================================

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index