<>
Apart from the variable name "chosen (yes/no)", everything else is doable:
*******
clear*
input id choice_set1:mylabel choice_set2:mylabel /*
*/ choice_set3:mylabel choice_set4:mylabel /*
*/ choice_set5:mylabel choice_set6:mylabel , auto
1 A B A A B B
2 B B A B A B
end
compress
list, noobs
reshape long choice_set, i(id) j(alternative)
expand 2
bys id alternative: gen byte chosen =_n==1
bys id alternative: /*
*/ replace choice_set =cond( choice_set==1, 2, 1) /*
*/ if _n==2
sort id alternative choice
l, sepby(id alternative)
*******
HTH
Martin
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Shehzad Ali
Sent: Freitag, 4. Dezember 2009 23:02
To: [email protected]
Subject: st: wide to long form
Hi listers,
I would really appreciate some help with data structuring.
I want to change my data structure from wide to long form. The data comes
from a discrete choice experiment. Each individual is given 6 choice sets.
Each choice set has two options, A or B. Individual is asked to choose
between A and B for each choice set. The data currently looks like this:
id choice_set1 choice_set2 choice_set3 choice_set4
choice_set5 choice_set6
1 A B A
A B B
2 B B A
B A B
I want the data to look like this:
id choice_set alternative chosen (yes/no)
1 1 A 1
1 1 B 0
1 2 A 0
1 2 B 1
1 3 A 1
1 3 B 0
..
..
2 1 A 0
2 1 B 1
2 2 A 0
2 2 B 1
...
...
Any help would be greatly appreciated.
Many thanks,
Shehzad
*
* 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/