1

I have conducted a discrete choice experiment using google forms and written up the results in a csv in excel. I am having problems understanding how to take the data from a standard csv format to a format that I can analyse using the gmnl package.

I am using this data below which has been dummy coded

personid    choiceid    alt payment management  assessment  crop
1   1   1   3   2   2   3
1   2   2   2   2   1   3
1   3   1   3   2   1   3
1   4   1   2   1   3   1
1   5   1   2   1   3   1
1   6   2   1   1   2   1
1   7   2   3   1   2   3
1   8   2   3   1   2   3
1   9   2   3   1   1   2
1   10  2   3   1   1   2
1   11  2   3   1   2   1
1   12  2   2   1   1   3
1   13  3   1   2   1   1
1   14  2   1   1   2   3
1   15  2   2   1   2   2
1   16  2   1   1   1   3
2   17  3   1   2   1   2
2   18  3   1   3   1   2
2   19  1   3   1   1   3

test <- as.data.frame(testchoices)

choices <- mlogit.data(test, shape = "long", idx = list(c("choiceid", "personid")), 
idnames = c("management", "crops", "assessment", "price"))
write_csv(choices, "choicesnext.csv")

It works fine up to write csv where the error is thrown saying 'Error in [.data.frame (x, start:min(NROW(x), start + len)) : undefined columns selected

I would be grateful for any assistance

dan1st
  • 12,568
  • 8
  • 34
  • 67
Miha04
  • 23
  • 5
  • You are trying to select a column that doesn't exist in your data. For example, in your data the column is called `crop`, whereas you call `crops` in the `mlogit.data` function. Furthermore, `price` is not part of the data, but you do have something called `payment`. That said, in the future, it would be helpful if you could also give a reproducible example. It makes it easier for people to help. – edsandorf Apr 16 '21 at 09:58
  • 1
    Thank you for your help! I can't mark it as solved but I appreciate it – Miha04 Apr 19 '21 at 12:16

0 Answers0