Hey folks. I have data from a survey in which I ask each respondent to complete two discrete choice experiments, and they choose between two alternatives (A and B), each with a number of attributes.I want to format my data in a way that treats each of the respondent's 2 choices as an individual observation. I've included an example dataset illustrating the raw output I can download from the survey platform. In this simplified data, there are two choice occasions per respondent, two alternatives per choice occasion (A and B), and two attributes per alternative (dist and wc):
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte id str2(choice1 choice2) byte(dista1 dista2 distb1 distb2 wca1 wca2 wcb1 wcb2)
1 "A1" "B2" 60 5 30 15 2 3 0 4
2 "B1" "B2" 40 10 2 15 3 2 3 4
end
So in the above data, respondent 1 chose alternative A (dist = 60 and wc = 2) in the first choice occasion, and chose alternative B (dist = 15 and wc = 4) in the second choice occasion, and so on. I want to treat each choice occasion as an individual observation in a conditional logit, so i'm trying to reformat my data to look like this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(id choiceoccasion) str1 alt byte(chosen dist wc)
1 1 "A" 1 60 2
1 1 "B" 0 30 0
1 2 "A" 0 5 3
1 2 "B" 1 15 4
2 3 "A" 0 40 3
2 3 "B" 1 2 3
2 4 "A" 0 10 2
2 4 "B" 1 15 4
end
I know this is probably accomplished through some combination of the -expand- and -reshape- commands, but I can't for the life of me figure out how to do it. Any help would be greatly appreciated!
0 Response to reshaping a dataset for a discrete choice model/conditional logit?
Post a Comment