0

I am trying to setup my data for the mlogit-package in R, but somehow I get an error message even though the exact demand with the same data worked before.

My data-frame is called data.02.alt, and it looks like this:

Head(data.02.alt)

It can be described as the following:

str(data.02.alt).

When I rund the command

MC <- mlogit.data(data.02.alt, choice = "choice",shape = "long", id.var = "case.id", alt.var = "Mode", group.var = "Hous_Loc")

I always get the error message

Error in `row.names<-.data.frame`(`*tmp*`, value = paste(chid, alt, sep = ".")) :
    duplicate 'row.names' are not allowed
In addition:
non-unique values when setting 'row.names': ‘100344.Bike’, ‘100344.PT’, ‘100345.Car’, ‘100345.Walk’, ‘100409.Bike’, ‘100409.PT’...

Could anyone tell me what I am doing wrong here? Could be the problem that I only have on alternative specific variable (com.cost)? I have read the help-documentation of mlogit, and read similar topics here on stackowerflow but without success, since after applying the advice it still didn't work.

Thanks in advance :),

Victoria

duckmayr
  • 16,303
  • 3
  • 35
  • 53
Vicy
  • 1
  • 1
    Welcome to Stack Overflow! You may want to check out [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In particular, it's rather tough on those trying to help when you post pictures of your data. Could you instead post the output of `dput(head(data.02.alt, 10))`? – duckmayr Sep 29 '18 at 13:34
  • You may want to try the suggestion of [this answer](https://stackoverflow.com/a/22468079/8386140) to a related question. In truth, this question may be a duplicate of that one, but I can't tell for certain. – duckmayr Sep 29 '18 at 13:44
  • Thanks for your answer! I will definitely follow the How-to the next time but as I can see you edited the post to make it better readable, thank you for that. – Vicy Sep 29 '18 at 14:22
  • I also checked out the question it linked and used the tipps mentioned there but it did not help. I checked, I don't have any duplicates and after changing my variables to character it still did not work. When I used shape = "wide" instead of long it ran but the output did not make any sense. I think the reason could be that the data is set up for the shape="long". Setting it up for shape = "wide" would be very time intensive so if there's a possibility that it works with shape="long" I would try out those first. – Vicy Sep 29 '18 at 14:36

0 Answers0