Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating Data Structure To Estimate Multinomial Logit via Programming


From   Ulrich Kohler ge <kohler@wz-berlin.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Generating Data Structure To Estimate Multinomial Logit via Programming
Date   Thu, 27 Oct 2005 10:01:20 +0200

suppose you dataset is

id country temp hum
1  1 24 45
2  2 26 55
3  2 26 55
4  3 29 65
etc.

One solution might be then:

. // Store the Properties of the Alternatives 
. preserve
. by country, sort: keep if _n==1
. ren country alt
. keep alt temp hum
. tempfile cov
. sort alt
. save `cov'

. // Construct Choice-Sets
. restore 
. keep id country
. expand 3 
. by id, sort: gen alt = _n
. gen choice = alt == country

. // Merge Properties of the Alternatives back-in
. sort alt
. merge alt using `cov'

many regards
uli

PS: Personaly, I would add the quality of restaurants to the theoretical 
model, with values France 100, Spain 99, and Germany 4.23 ;-)

Stata User wrote:
> I have observations of 4  holiday passengers choosing between going on
> holiday
> in 3 different countries: Germany, France and Spain. So country is the
> categorical
> choice variable. This categorical choice variable  has 2 attributes:
> temperature and
> humidity. This is how the data structure looks like now (simplified
> example)
>
>
>
> 		Table 1:Data Structure Now
>
> 	   | 	Choice (country)   |	Temperature  |	Humidity	  |		   |
>
> Passenger 1  |	Germany	          |	24	    |	45              |
> Passenger 2  |	France	          |	26 	    |           55              |
> Passenger 3  |	France	          |	26	    |	55              |
> Passenger 4  |	Spain	          |	29	    |	65              |
>
>
> Now I want to replace the categorical choice variable 'country' with a
> dichotomous
> choice variable. This means when a passenger chooses Germany and he does
> not choose France and Germany, we observe three decisons of the passenger
> which will be coded with '1' for Germany and '0' for France and Spain. So
> this below in
> Table 2 is the data structure I desire. Since I have too much data, I have
> to find a
> programming solution in order to transform Table 1 into Table 2.
>
>
> 		Table 2: Desired Data Structure via Programming
>
> 	     |   Dichotomous     |     Categorical choice |  Temperature   |
>
> Humidity   |
>
>                      |   choice variable   |      variable               |
>
> Observation 1  |	1	|	Germany	|	24    |	45       |
> Observation 2  |	0	|	France	|	26    |	55       |
> Observation 3  |	0	|	Spain	|	29    |	65       |
> Observation 4  |	0	|	Germany	|	24    |	45       |
> Observation 5  |	1	|	France	|	26    |	55       |
> Observation 6  |	0	|	Spain	|	29    |	65       |
> Observation 7  |	0	|	Germany	|	24    |	45       |
> Observation 8  |	1	|	France	|	26    |	55       |
> Observation 9  |	0	|	Spain	|	29    |	65       |
> Observation 10|	0	|	Germany	|	24    |	45       |
> Observation 11|	0	|	France	|	26    |	55       |
> Observation 12|	1	|	Spain	|	29    |	65       |
>
>
> Thank you for your help,
>
> Stata User 2005 from Europe
>
> _________________________________________________________________
> Die neue MSN Suche Toolbar mit Windows-Desktopsuche. Suchen Sie
> gleichzeitig im Web, Ihren E-Mails und auf Ihrem PC! Jetzt neu!
> http://desktop.msn.de/ Jetzt gratis downloaden!
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

-- 
kohler@wz-berlin.de
+49 (030) 25491-361
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index