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


From   Henk-Wim de Boer <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: RE: Discrete choice in MATA
Date   Fri, 21 Jun 2013 12:53:36 +0200

Hi Tim,

The reason for this is that I am using simulated maximum likelihood, where I use 10 draws from the wage distribution. In addition, I extended our basic labour supply model with 4 additional alternatives for childcare. 
I end up with 24 alternatives for singles and 144 alternatives for couples. I estimate the model, using a large rich dataset, with a lot of alternatives and parameters. Consequently, the estimation for couples takes approximately 4 days. In the future, I want to increase the number of draws from the wage distribution as well and therefore I want to speed up the estimation. 

I tried so by deriving the first and second order derivatives analytically (ml model d1 and d2) but this did not work for multiple draws from the wage distribution. The model only converges if I allow for 1 draw and not for multiple draws. It seems that rounding errors prevent the model from converging (the first derivative is close to 0 and remains close to 0). Now I want to program it in Mata.

Henk-Wim

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Timothy Mak
Sent: 21 June 2013 04:12
To: [email protected]
Subject: st: RE: Discrete choice in MATA

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/

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


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