My data.frame looks like this:
ID Set Choice Apple Microsoft IBM Google Intel HewlettPackard Sony Dell Yahoo Nokia
1 1 1 FALSE 1 0 0 0 0 0 0 0 0 0
2 1 1 FALSE 0 1 0 0 0 0 0 0 0 0
3 1 1 FALSE 0 0 1 0 0 0 0 0 0 0
4 1 1 TRUE 0 0 0 1 0 0 0 0 0 0
5 1 1 FALSE 0 0 0 0 0 0 0 0 0 1
6 1 2 FALSE -1 0 0 0 0 0 0 0 0 0
with it's structure as
'data.frame': 18720 obs. of 13 variables:
$ ID : int 1 1 1 1 1 1 1 1 1 1 ...
$ Set : num 1 1 1 1 1 2 2 2 2 2 ...
$ Choice : logi FALSE FALSE FALSE TRUE FALSE FALSE ...
$ Apple : num 1 0 0 0 0 -1 0 0 0 0 ...
$ Microsoft : num 0 1 0 0 0 0 -1 0 0 0 ...
$ IBM : num 0 0 1 0 0 0 0 -1 0 0 ...
$ Google : num 0 0 0 1 0 0 0 0 -1 0 ...
$ Intel : num 0 0 0 0 0 0 0 0 0 0 ...
$ HewlettPackard: num 0 0 0 0 0 0 0 0 0 0 ...
$ Sony : num 0 0 0 0 0 0 0 0 0 0 ...
$ Dell : num 0 0 0 0 0 0 0 0 0 0 ...
$ Yahoo : num 0 0 0 0 0 0 0 0 0 0 ...
$ Nokia : num 0 0 0 0 1 0 0 0 0 -1 ...
upon running mlogit with the following code:
dt = mlogit.data(longData, choice = 'Choice', shape = 'long', id.var = 'ID')
I am getting the following error
Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index, :
impossible to coerce the choice variable to a logical
But I am unable to figure out why I am getting this error, despite the fact that my Choice
column is of logical
type.
To reproduce the data.frame you can take help of this file.