Hi,
I'm currently trying to enter data for a discrete choice experiment in Stata; this data was given to me in Excel, so I'm having a little trouble importing it. The data in Excel tells me which alternative a respondent chose in each choice set. The respondents are facing 10 choice sets, each with three alternatives, so a total of 30 observations per individual. My main problem is how to generate the the dependent variable "y"; this variable indicates the choice a respondent makes and takes on a value of 1 if the individual chose an alternative or 0 if the person did not choose it. I was thinking that I would create ten variables, choiceset1 through choiceset10, that take on values of 1, 2, or 3, depending on whether the 1st, 2nd, or 3rd alternative within the choice set is chosen. My question is, how can I translate that information into the variable y? In words, I'm trying to write a series of commands that does something like "for respondent i, if choicesetk=j, let the variable y take on the value 1 for the jth observation among the kth set of three observations and 0 elsewhere within that set of observations."
I know this is a complicated request, so if anyone can point me in the direction of commands that would be helpful to construct something like this, I would be grateful. I have attached an example of what I want the final data to look like, just for the first respondent in order to keep it short.
I'm currently trying to enter data for a discrete choice experiment in Stata; this data was given to me in Excel, so I'm having a little trouble importing it. The data in Excel tells me which alternative a respondent chose in each choice set. The respondents are facing 10 choice sets, each with three alternatives, so a total of 30 observations per individual. My main problem is how to generate the the dependent variable "y"; this variable indicates the choice a respondent makes and takes on a value of 1 if the individual chose an alternative or 0 if the person did not choose it. I was thinking that I would create ten variables, choiceset1 through choiceset10, that take on values of 1, 2, or 3, depending on whether the 1st, 2nd, or 3rd alternative within the choice set is chosen. My question is, how can I translate that information into the variable y? In words, I'm trying to write a series of commands that does something like "for respondent i, if choicesetk=j, let the variable y take on the value 1 for the jth observation among the kth set of three observations and 0 elsewhere within that set of observations."
I know this is a complicated request, so if anyone can point me in the direction of commands that would be helpful to construct something like this, I would be grateful. I have attached an example of what I want the final data to look like, just for the first respondent in order to keep it short.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(id cs1 cs2 cs3 cs4 cs5 cs6 cs7 cs8 cs9 cs10 y) 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 1 1 2 3 1 1 1 2 3 3 2 1 1 1 2 3 1 1 1 2 3 3 2 0 end
Comment