1
votes

I am trying to estimate a multinomial logit model with the mlogit package. I don't know how to deal with variables that don't apply to all alternatives. For example, I have four transportation modes (walk, bike, public transport and car) and the variable "cost" applies only to the car and public transport. When I import the csv file into R and try to estimate the model I become this error message:

Error in reshapeLong(data, idvar = idvar, timevar = timevar, varying = varying,  : 
  'varying' arguments must be the same length

How can I make R understand that the cost variable describes only two of the alternatives and not all of them?

1
Fill in 0's for the the ones it doesn't apply to.Gregor Thomas
That would work I guess for the cost variable, but I also have categorical variables like comfort with two levels: 1 class (coded with 1) and 2 class (coded with 0). This variable describes only the airplane and the train but not to the car. If I fill in 0's for the car that would mean that the car has comfort of the 2. class which is not exactly correct since the car has only one level for comfort.sbb2018
Make it a 3-level factor - 1 class, 2 class, unapplicable.Gregor Thomas

1 Answers

1
votes

Use constPar=c("bike:cost", "walk:cost") to treat cost as a constant variable for bike and walk.

Check the example on page 31 on the mlogit package.