I have a wide discrete choice data with 3 alternatives where alternative 3 is "None" or "opt-out" i.e it doesn't have any attributes. When I use convert_wide_to_long
function from pylogit
package, the "None" alternative is transformed into a row with 0 values in all columns which doesn't seem right. Any idea what I'm doing wrong?
Input:
Columns choice is the chosen alternative with 3 being the "None" alternative.
# Create the list of observation specific variables
ind_variables = ["person", "task"]
alt_varying_variables = {"day": {1: "opt1_Day",
2: "opt2_Day"},
"time_of_day": {1: "opt1_ToD",
2: "opt2_ToD"},
"location": {1: "opt1_loc",
2: "opt2_loc"}
}
# Create the needed availability columns for the data
# where each choice is a binary decision
for i in [1, 2, 3]:
temp["availability_{}".format(i)] = 1
from collections import OrderedDict
# Specify the availability variables
availability_variables = OrderedDict()
for alt_id, var in zip([1, 2,3], ["availability_1", "availability_2", "availability_3"]):
availability_variables[alt_id] = var
df_long = pl.convert_wide_to_long(wide_data=temp,
ind_vars=ind_variables,
alt_specific_vars=alt_varying_variables,
availability_vars=availability_variables,
obs_id_col='choice_situation', #individual observations
choice_col='choice',
new_alt_id_name='alt_id')