Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:57:41+00:00 2026-05-30T09:57:41+00:00

I am using the mlogit package with R. After importing my data using: t

  • 0

I am using the mlogit package with R.

After importing my data using:

t <-read.csv('junk.csv',header=TRUE, sep=",", dec=".")

and call:

x <- mlogit.data(t,choice="D",shape="long",id.var="key",alt.var="altkey")

I am getting the following error:

Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.1", "1.2", "1.3",  : 
  duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘1.1’, ‘1.2’, ‘1.3’, ‘1.4’, ‘1.5’, ‘1.6’

Any ideas how to fix it?

My data exist in the following format in a csv file:

[junk.csv]

key,altkey,A,B,C,D
201005131,1,2.6,118.17,117,0
201005131,2,1.4,117.11,115,0
201005131,3,1.1,117.38,122,1
201005131,4,24.6,,122,0
201005131,5,48.6,91.90,122,0
201005131,6,59.8,,122,0
201005132,1,20.2,118.23,113,0
201005132,2,2.5,123.67,120,1
201005132,3,7.4,116.30,120,0
201005132,4,2.8,118.86,120,0
201005132,5,6.9,124.72,120,0
201005132,6,2.5,123.81,120,0
201005132,7,8.5,119.23,115,
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:57:42+00:00Added an answer on May 30, 2026 at 9:57 am

    My experience of mlogit is that it isn’t very forgiving about data that isn’t exactly the way it should be.

    In your case, I notice that the first respondent has 6 alternatives, while the second respondent has 7 alternatives. If you format your data to have an equal number of alternatives for each respondent the mlogit.data function works:

    dat <- read.table(sep=",",text="
    key,altkey,A,B,C,D
    201005131,1, 2.6,118.17,117,0
    201005131,2,1.4,117.11,115,0
    201005131,3,1.1,117.38,122,1
    201005131,4,24.6,,122,0
    201005131,5,48.6,91.90,122,0
    201005131,6,59.8,,122,0
    201005132,1,20.2,118.23,113,0
    201005132,2,2.5,123.67,120,1
    201005132,3,7.4,116.30,120,0
    201005132,4,2.8,118.86,120,0
    201005132,5,6.9,124.72,120,0
    201005132,6,2.5,123.81,120,0
    201005132,7,8.5,119.23,115,0
    ", header=TRUE)
    

    Running mlogit on all of the data reproduces the error:

    > mlogit.data(dat, choice="D", shape="long", id.var="key", alt.var="altkey")
    Error in `row.names<-.data.frame`(`*tmp*`, value = c("1.1", "1.2", "1.3",  : 
      duplicate 'row.names' are not allowed
    In addition: Warning message:
    non-unique values when setting 'row.names': '1.1', '1.2', '1.3', '1.4', '1.5', '1.6' 
    

    However, removing line number 13, i.e. the 7th alternative, works:

    > mlogit.data(dat[-13, ], choice="D", shape="long", id.var="key", alt.var="altkey")
              key altkey    A      B   C     D
    1.1 201005131      1  2.6 118.17 117 FALSE
    1.2 201005131      2  1.4 117.11 115 FALSE
    1.3 201005131      3  1.1 117.38 122  TRUE
    1.4 201005131      4 24.6     NA 122 FALSE
    1.5 201005131      5 48.6  91.90 122 FALSE
    1.6 201005131      6 59.8     NA 122 FALSE
    2.1 201005132      1 20.2 118.23 113 FALSE
    2.2 201005132      2  2.5 123.67 120  TRUE
    2.3 201005132      3  7.4 116.30 120 FALSE
    2.4 201005132      4  2.8 118.86 120 FALSE
    2.5 201005132      5  6.9 124.72 120 FALSE
    2.6 201005132      6  2.5 123.81 120 FALSE
    

    Of course, this isn’t very satisfactory, since it destroys some of the data. A better solution is to construct the data in a format that mlogit() expects, and then call mlogit() directly:

    dat$key <- factor(as.numeric(as.factor(dat$key)))
    dat$altkey <- as.factor(dat$altkey)
    dat$D <- as.logical(dat$D)
    row.names(dat) <- paste(dat$key, dat$altkey, sep = ".")
    

    Now the data looks like this:

        key altkey    A      B   C     D
    1.1   1      1  2.6 118.17 117 FALSE
    1.2   1      2  1.4 117.11 115 FALSE
    1.3   1      3  1.1 117.38 122  TRUE
    1.4   1      4 24.6     NA 122 FALSE
    1.5   1      5 48.6  91.90 122 FALSE
    1.6   1      6 59.8     NA 122 FALSE
    2.1   2      1 20.2 118.23 113 FALSE
    2.2   2      2  2.5 123.67 120  TRUE
    2.3   2      3  7.4 116.30 120 FALSE
    2.4   2      4  2.8 118.86 120 FALSE
    2.5   2      5  6.9 124.72 120 FALSE
    2.6   2      6  2.5 123.81 120 FALSE
    2.7   2      7  8.5 119.23 115 FALSE
    

    And you can call mlogit() directly:

    mlogit(D ~ A + B + C, dat, 
           chid.var = "key", 
           alt.var = "altkey", 
           choice = "D", 
           shape = "long")
    

    Result:

    Call:
    mlogit(formula = D ~ A + B + C, data = dat, chid.var = "key",     alt.var = "altkey", choice = "D", shape = "long", method = "nr",     print.level = 0)
    
    Coefficients:
    2:(intercept)  3:(intercept)  4:(intercept)  5:(intercept)  6:(intercept)  
          10.7774         4.8129         5.2257       -17.2522        -7.7364  
    7:(intercept)              A              B              C  
          10.0389         1.6010         2.7156         2.9888  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the mlogit package in R to estimate a mixed logit model with
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using Android TelephonyManager an application can obtain the state of data activity over the
Using Core Data, I have a fetch request to fetch the minimum of a
using VB.Net2010 I need to call a C# DLL The problem I have is
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.