I'm trying to fit a mixed logit model in R using the mlogit package.
This is a sample of my data:
Persona Proposito MediosUsados ModoPriPub ModoMotor TiempoViaje Sexo AdultoMayor Estudios
<dbl> <chr> <chr> <chr> <chr> <dbl> <chr> <chr> <chr>
1 17343102 Volver a Casa Bus Alimentador Publico Motorizado 70 Mujer No Media Cientifica-Human~
2 17345101 Volver a Casa A pie No motorizado No motoriza~ 20 Homb~ No Basica/Primaria
3 17345102 De compras A pie No motorizado No motoriza~ 20 Mujer No Universitaria
4 17345102 Volver a Casa A pie No motorizado No motoriza~ 25 Homb~ No Universitaria
5 17346203 Al estudio A pie No motorizado No motoriza~ 20 Mujer No Media Cientifica-Human~
6 17346203 Volver a Casa A pie No motorizado No motoriza~ 20 Homb~ No Media Cientifica-Human~
Where persona is the id of individual; MediosUsados is the mode (choice); ModoPriPub, ModoMotor and TiempoViaje are the conditional variables that depends on the mode; and Sexo, AdultoMayor & Estudios are the other variables depending on the individual.
This is how im trying to fit the model:
ibrary(readxl)
library(dfidx)
library(mlogit)
# Cargar dataset
TravelMode <- read_excel('Model_strings.xlsx')
model<-mlogit(MediosUsados~ModoMotor+ModoPriPub+TiempoViaje | Proposito+Sexo+AdultoMayor+Estudios, TravelMode, shape="long")
Nevertheless I get this error all the time:
Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index, :
the two indexes don't define unique observations
I tried removing the duplicates but it keeps throwing the same error message. Any help would be much appreciated.