Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | <Jean-Francois.Bertrand@fin.gc.ca> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Creating choice indicator! |
Date | Tue, 20 Mar 2012 14:53:55 -0400 |
Hi, Have you had a chance to look at the book Maximum likelihood estimation with Stata by Gould, Pitblado and Poi from Stata press? It really helped me. You can also look at Daniele Pacifico's 2009 paper entitled "A Behavioural microsimulation model with discrete labour supply for Italian couples" as the paper provides some Stata code for discrete choice model that may give you some ideas. Once it works in a panel type of approach, try the long form to see the difference. Cheers, Jean-François Bertrand -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Peter Grand Sent: March 20, 2012 2:43 PM To: statalist@hsphsun2.harvard.edu Subject: AW: st: Creating choice indicator! Dear Jean-Francois! This is exactly my intention, and already showed me that my evaluator is poorly written (although I do not know why by now) and it is no problem with my data. Again, thank you all! I have also learned a lot in terms of creating different random variables. Best, Peter Grand grand(at)ihs.ac.at Institute for Advanced Studies Stumpergasse 56 1060 Vienna ________________________________________ Von: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu]" im Auftrag von "Jean-Francois.Bertrand@fin.gc.ca [Jean-Francois.Bertrand@fin.gc.ca] Gesendet: Dienstag, 20. März 2012 19:37 Bis: statalist@hsphsun2.harvard.edu Betreff: RE: st: Creating choice indicator! Hello, If I understand correctly, this will help Peter testing his choice model. Expanding the data provides an environment similar to panel type data. When programming his function in -ml-, only one observation "per panel" will contribute to the maximum likelihood. In my experience, the long data structure or shape or form (when possible) is much faster when programming choice model in -ml-. Why? Cheers, Jean-François Bertrand -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: March 20, 2012 2:24 PM To: 'statalist@hsphsun2.harvard.edu' Subject: RE: st: Creating choice indicator! Alternatively, look upwards! ceil(5 * runiform()) Nick n.j.cox@durham.ac.uk Scott Merryman For a random integer between 1 and 5 the code should be : 1 + floor(5*runiform()) On Tue, Mar 20, 2012 at 12:32 PM, Peter Grand <grand@ihs.ac.at> wrote: > @ Scott: Exactly, thank you very much! > > @ Joerg: Sorry, if I have not been able to correctly specify my request. > > Again, thank you for your efforts! > Scott Merryman [scott.merryman@gmail.com] > Something like this? > > > clear > set obs 5 > gen id = _n > expand 5 > sort id > > bys id: gen order = _n > gen chosen = 0 > levelsof id, local(levels) > foreach l of local levels { > if runiform() < .5 { //probability that id is chosen > local a = round(1 +4*runiform(),1) > qui replace chosen= 1 if order == `a' & id == `l' //1 of 5 > alternatives is chosen > > } > } > drop order > l On Tue, Mar 20, 2012 at 11:51 AM, Peter Grand <grand@ihs.ac.at> wrote: >> How can I create a random binary variable which indicates either only one chosen alternative or none of them within an id variable, e.g. 5 choices for each individual id : >> >> >> id chosen >> 1 0 >> 1 0 >> 1 1 >> 1 0 >> 1 0 >> 2 0 >> 2 0 >> 2 0 >> 2 0 >> 2 0 >> 3 0 >> 3 1 >> 3 0 >> 3 0 >> 3 0 >> * * 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/