# ModeChoice is a long data.frame
data("TravelMode",package="AER")
TM <- mlogit.data(TravelMode,choice="choice",shape="long",
alt.levels=c("air","train","bus","car"))
# Same but the alt variable called mode is provided
TM <- mlogit.data(TravelMode,choice="choice",shape="long",
alt.var="mode")
# Same but the chid variable called individual is provided
TM <- mlogit.data(TravelMode,choice="choice",shape="long",
id.var="individual",alt.levels=c("air","train","bus","car"))
# Same but with two own provided variables
TM <- mlogit.data(TravelMode,choice="choice",shape="long",
id.var="individual",alt.var="mode")
# Train is a wide data.frame with columns 'choiceid' is the choice
# index, the alternatives are named "ch1" and "ch2", the opposite
# of the variables is returned
data("Train",package="Ecdat")
Train <- mlogit.data(Train,choice="choice",shape="wide",
varying=4:11,alt.levels=c("ch1","ch2"),
opposite=c("price","time","change","comfort"), sep="")
# Car is a wide data.frame, indexes names are provided
data("Car",package="Ecdat")
Car <-
mlogit.data(Car,varying=5:70,shape="wide",sep="",choice="choice",
id.var="Mr",alt.var="Car",alt.levels=1:6)
Run the code above in your browser using DataLab