Skip to content

Help with the Error Message in R "Error in 1:nchid : result would be too long a vector"

9 messages · Rahul Chakraborty, David Winsemius, Rui Barradas

#
Hello everyone,

I am using *mlogit* to analyse my choice experiment data. I have *3
alternatives* for each individual and for each individual I have *9
questions*. I have a response from *516 individuals*. So it is a panel of
9*516 observations. I have arranged the data in long format (it contains
100 columns indicating different variables and identifiers).

In mlogit I tried the following command---

*mldata<- mlogit.data(mydata, shape = "long", alt.var = "Alt_name", choice
= "Choice_binary", id.var = "IND")*

It is giving me the following error message- Error in 1:nchid : result
would be too long a vector

Could you please help me with this? I don't think it is too big a data 100
ROWS*13932 columns. I faced no issue in Excel. I am stuck due to this issue.
Thanks in advance.

-- Best Regards,
Rahul Chakraborty
Research Fellow
National Institute of Public Finance and Policy
New Delhi- 110067
#
If you had included output of summary(mydata) we might be more capable 
of giving a fact-based answer but I'm guessing that you have a lot of 
catagorical variables with multiple levels and some sort of combinatoric 
explosion is resulting in too many levels of a constructed factor.
#
Hello,

Here is the result of summary(mydata)

summary(mydata)
      IND            Block            QES         STR             ALT
 Min.   :  1.0   Min.   :1.000   Min.   :1   Min.   :  101   Min.   :1
 1st Qu.:129.8   1st Qu.:1.000   1st Qu.:3   1st Qu.:12978   1st Qu.:1
 Median :258.5   Median :2.000   Median :5   Median :25855   Median :2
 Mean   :258.5   Mean   :2.467   Mean   :5   Mean   :25855   Mean   :2
 3rd Qu.:387.2   3rd Qu.:4.000   3rd Qu.:7   3rd Qu.:38732   3rd Qu.:3
 Max.   :516.0   Max.   :4.000   Max.   :9   Max.   :51609   Max.   :3
   ALT_name              ASC             Choice      Choice_binary
 Length:13932       Min.   :0.0000   Min.   :1.000   Min.   :0.0000
 Class :character   1st Qu.:0.0000   1st Qu.:1.000   1st Qu.:0.0000
 Mode  :character   Median :1.0000   Median :1.000   Median :0.0000
                    Mean   :0.6667   Mean   :1.626   Mean   :0.3333
                    3rd Qu.:1.0000   3rd Qu.:2.000   3rd Qu.:1.0000
                    Max.   :1.0000   Max.   :3.000   Max.   :1.0000
     Price       Refuel_availability Registration_charges  Running_cost
 Min.   : 9.00   Min.   :0.25        Min.   :0.00000      Min.   :115.0
 1st Qu.:10.00   1st Qu.:0.75        1st Qu.:0.04000      1st Qu.:192.0
 Median :10.00   Median :0.90        Median :0.06000      Median :268.0
 Mean   :10.33   Mean   :0.80        Mean   :0.05333      Mean   :268.2
 3rd Qu.:11.00   3rd Qu.:1.00        3rd Qu.:0.08000      3rd Qu.:383.0
 Max.   :12.00   Max.   :1.00        Max.   :0.08000      Max.   :383.0
  Market_share    Friends_share     Refuel_time       Emission
 Min.   :0.0500   Min.   :0.0000   Min.   : 5.00   Min.   :0.0000
 1st Qu.:0.1500   1st Qu.:0.1500   1st Qu.: 5.00   1st Qu.:0.0000
 Median :0.2500   Median :0.3000   Median : 5.00   Median :0.7500
 Mean   :0.3333   Mean   :0.3333   Mean   :13.33   Mean   :0.5833
 3rd Qu.:0.6000   3rd Qu.:0.5500   3rd Qu.:30.00   3rd Qu.:1.0000
 Max.   :0.9000   Max.   :1.0000   Max.   :30.00   Max.   :1.0000
      Sex              Age2             Age3             Age4
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :1.0000   Median :0.0000   Median :0.0000   Median :0.0000
 Mean   :0.7791   Mean   :0.4574   Mean   :0.2326   Mean   :0.1531
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:0.0000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000
     Edu_PG          Edu_Oth          Occu_Pvt        Occu_Pub
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.0000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.0000
 Median :0.0000   Median :0.0000   Median :0.000   Median :0.0000
 Mean   :0.4147   Mean   :0.1841   Mean   :0.376   Mean   :0.2733
 3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:1.000   3rd Qu.:1.0000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.0000
    Occu_SE       Location_metro   Location_majorcity      Ahm
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000     Min.   :0.00000
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000     1st Qu.:0.00000
 Median :0.0000   Median :1.0000   Median :0.0000     Median :0.00000
 Mean   :0.2655   Mean   :0.7655   Mean   :0.1453     Mean   :0.04457
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000     3rd Qu.:0.00000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000     Max.   :1.00000
      Ben               Chen              NCR              Hyd
 Min.   :0.00000   Min.   :0.00000   Min.   :0.0000   Min.   :0.00000
 1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.0000   1st Qu.:0.00000
 Median :0.00000   Median :0.00000   Median :0.0000   Median :0.00000
 Mean   :0.06977   Mean   :0.04651   Mean   :0.2558   Mean   :0.03682
 3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:1.0000   3rd Qu.:0.00000
 Max.   :1.00000   Max.   :1.00000   Max.   :1.0000   Max.   :1.00000
      Kol              Mum            MajCity          HH_size
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   : 1.000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.: 3.000
 Median :0.0000   Median :0.0000   Median :0.0000   Median : 5.000
 Mean   :0.2016   Mean   :0.1105   Mean   :0.1453   Mean   : 4.463
 3rd Qu.:0.0000   3rd Qu.:0.0000   3rd Qu.:0.0000   3rd Qu.: 6.000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :10.000
    Children           IG2              IG3              IG4
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :1.0000   Median :0.0000   Median :0.0000   Median :0.0000
 Mean   :0.8721   Mean   :0.3818   Mean   :0.4109   Mean   :0.1841
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000
 Max.   :4.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000
    HH_cars       PPC_morethan10      PPC_gr1         PPC_gr2
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.00000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.00000
 Median :0.0000   Median :0.0000   Median :0.000   Median :0.00000
 Mean   :0.4864   Mean   :0.4516   Mean   :0.405   Mean   :0.04651
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.000   3rd Qu.:0.00000
 Max.   :3.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.00000
   Body_Sedan        Body_SUV      Daily_travel_medium Daily_travel_long
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000      Min.   :0.00000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000      1st Qu.:0.00000
 Median :0.0000   Median :0.0000   Median :0.0000      Median :0.00000
 Mean   :0.3178   Mean   :0.2364   Mean   :0.3702      Mean   :0.02713
 3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:1.0000      3rd Qu.:0.00000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000      Max.   :1.00000
   Long_drive       Mode_Carpool        Mode_PB          Mode_PV
 Min.   :0.00000   Min.   :0.00000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :0.00000   Median :0.00000   Median :0.0000   Median :0.0000
 Mean   :0.03488   Mean   :0.02519   Mean   :0.2907   Mean   :0.4419
 3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:1.0000   3rd Qu.:1.0000
 Max.   :1.00000   Max.   :1.00000   Max.   :1.0000   Max.   :1.0000
    Mode_WRC           Garage_y           DL_y          Own_accom
 Min.   :0.000000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:0.000000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :0.000000   Median :1.0000   Median :1.0000   Median :1.0000
 Mean   :0.007752   Mean   :0.7267   Mean   :0.6357   Mean   :0.6647
 3rd Qu.:0.000000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000
 Max.   :1.000000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000
 Freerider_water_electricity Freerider_tot   Freerider_avg
Satisfaction_tot
 Min.   :1.000               Min.   :2.000   Min.   :1.000   Min.   : 2.000

 1st Qu.:2.000               1st Qu.:2.000   1st Qu.:1.000   1st Qu.: 3.000

 Median :3.000               Median :2.000   Median :1.000   Median : 4.000

 Mean   :3.002               Mean   :2.244   Mean   :1.122   Mean   : 4.264

 3rd Qu.:4.000               3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.: 5.000

 Max.   :5.000               Max.   :8.000   Max.   :4.000   Max.   :10.000

 Satisfaction_avg Political_view  Meet_friends       Meet_colleagues
 Min.   :1.000    Min.   :1.000   Length:13932       Length:13932
 1st Qu.:1.500    1st Qu.:3.000   Class :character   Class :character
 Median :2.000    Median :3.000   Mode  :character   Mode  :character
 Mean   :2.132    Mean   :3.258
 3rd Qu.:2.500    3rd Qu.:4.000
 Max.   :5.000    Max.   :5.000
 Meet_relatives     Invite_colleagues  Invite_friends     Invite_relatives
 Length:13932       Length:13932       Length:13932       Length:13932
 Class :character   Class :character   Class :character   Class :character
 Mode  :character   Mode  :character   Mode  :character   Mode  :character



 Lending_relatives  Lending_friends    Lending_colleagues
 Length:13932       Length:13932       Length:13932
 Class :character   Class :character   Class :character
 Mode  :character   Mode  :character   Mode  :character



 Willingness_Purchase_Env_frnd EVuse_pollution  WTP_env_tot
 WTP_env_avg
 Min.   :1.000                 Min.   :1.000   Min.   : 2.000   Min.
:1.000
 1st Qu.:4.000                 1st Qu.:3.000   1st Qu.: 7.000   1st
Qu.:3.500
 Median :4.000                 Median :4.000   Median : 8.000   Median
:4.000
 Mean   :4.132                 Mean   :3.992   Mean   : 8.124   Mean
:4.062
 3rd Qu.:5.000                 3rd Qu.:5.000   3rd Qu.: 9.000   3rd
Qu.:4.500
 Max.   :5.000                 Max.   :5.000   Max.   :10.000   Max.
:5.000
 Social_recognition Car_social_status  Warmglow_tot    Warmglow_avg
 Min.   :1.000      Min.   :1.00      Min.   : 2.00   Min.   :1.000
 1st Qu.:3.000      1st Qu.:4.00      1st Qu.: 6.00   1st Qu.:3.000
 Median :4.000      Median :4.00      Median : 8.00   Median :4.000
 Mean   :3.541      Mean   :4.07      Mean   : 7.61   Mean   :3.805
 3rd Qu.:4.000      3rd Qu.:5.00      3rd Qu.: 9.00   3rd Qu.:4.500
 Max.   :5.000      Max.   :5.00      Max.   :10.00   Max.   :5.000
    Standout     Acceptance_new Climate_perception    Env_pref
 Tech_leader
 Min.   :1.000   Min.   :1.0    Min.   :1.000      Min.   :1.000   Min.
:1.0
 1st Qu.:2.000   1st Qu.:2.0    1st Qu.:4.000      1st Qu.:2.000   1st
Qu.:2.0
 Median :3.000   Median :3.0    Median :5.000      Median :3.000   Median
:2.0
 Mean   :2.657   Mean   :2.8    Mean   :4.483      Mean   :3.093   Mean
:2.5
 3rd Qu.:3.000   3rd Qu.:4.0    3rd Qu.:5.000      3rd Qu.:4.000   3rd
Qu.:3.0
 Max.   :5.000   Max.   :5.0    Max.   :5.000      Max.   :5.000   Max.
:5.0
 Social_motivation_tot Social_motivation_avg Social_motivation_median
 Min.   : 3.00         Min.   :1.000         Min.   :1.000
 1st Qu.: 9.00         1st Qu.:3.000         1st Qu.:3.000
 Median :11.00         Median :3.667         Median :3.000
 Mean   :10.62         Mean   :3.539         Mean   :3.514
 3rd Qu.:12.00         3rd Qu.:4.000         3rd Qu.:4.000
 Max.   :15.00         Max.   :5.000         Max.   :5.000
  EV_risk_tot      EV_risk_avg      EV_price     EV_awareness_tot
EV_awareness_avg
 Min.   : 2.000   Min.   :1.00   Min.   :1.000   Min.   : 3.000   Min.
:1.000
 1st Qu.: 8.000   1st Qu.:4.00   1st Qu.:1.000   1st Qu.: 4.000   1st
Qu.:1.333
 Median : 9.000   Median :4.50   Median :2.000   Median : 5.000   Median
:1.667
 Mean   : 8.661   Mean   :4.33   Mean   :2.244   Mean   : 5.419   Mean
:1.806
 3rd Qu.:10.000   3rd Qu.:5.00   3rd Qu.:3.000   3rd Qu.: 6.000   3rd
Qu.:2.000
 Max.   :10.000   Max.   :5.00   Max.   :5.000   Max.   :15.000   Max.
:5.000
 EV_awareness_median    Lost_env     Investment_trust   Lottery1
 Min.   :1.000       Min.   :1.000   Min.   :     0   Length:13932
 1st Qu.:1.000       1st Qu.:5.000   1st Qu.:     0   Class :character
 Median :2.000       Median :5.000   Median :     0   Mode  :character
 Mean   :1.806       Mean   :4.913   Mean   :  1345
 3rd Qu.:2.000       3rd Qu.:5.000   3rd Qu.:     0
 Max.   :5.000       Max.   :5.000   Max.   :100000
    Time1             Lottery2            Time2
 Length:13932       Length:13932       Length:13932
 Class :character   Class :character   Class :character
 Mode  :character   Mode  :character   Mode  :character



Yes, I have many Likert items and many dummy variables. How do I solve this
issue?

Best regards,

On Tue, Sep 22, 2020 at 1:45 AM David Winsemius <dwinsemius at comcast.net>
wrote:

  
    
#
Hello,

I tried to reduce the size of my dataframe. Now I have 57 columns of which
29 are already dummy coded. If I run   *mldata1<- mlogit.data(mydata1,
shape = "long", alt.var = "Alt_name", choice = "Choice_binary", id.var =
"IND") *it still gives me the same error message-* Error in 1:nchid :
result would be too long a vector. *

I will not use all of those variables in one regression model, but I need
those for different model specifications. The Excel file I created from my
survey looks like the attached file. The main data is a panel of 516
individuals each answering 9 questions over 3 alternatives.

Following is the output of the summary of the dataframe.

summary(mydata1)
      IND             QES         STR          ALT_name
Choice_binary
 Min.   :  1.0   Min.   :1   Min.   :  101   Length:13932       Min.
:0.0000
 1st Qu.:129.8   1st Qu.:3   1st Qu.:12978   Class :character   1st
Qu.:0.0000
 Median :258.5   Median :5   Median :25855   Mode  :character   Median
:0.0000
 Mean   :258.5   Mean   :5   Mean   :25855                      Mean
:0.3333
 3rd Qu.:387.2   3rd Qu.:7   3rd Qu.:38732                      3rd
Qu.:1.0000
 Max.   :516.0   Max.   :9   Max.   :51609                      Max.
:1.0000
     Price       Refuel_availability Registration_charges  Running_cost
 Min.   : 9.00   Min.   :0.25        Min.   :0.00000      Min.   :115.0
 1st Qu.:10.00   1st Qu.:0.75        1st Qu.:0.04000      1st Qu.:192.0
 Median :10.00   Median :0.90        Median :0.06000      Median :268.0
 Mean   :10.33   Mean   :0.80        Mean   :0.05333      Mean   :268.2
 3rd Qu.:11.00   3rd Qu.:1.00        3rd Qu.:0.08000      3rd Qu.:383.0
 Max.   :12.00   Max.   :1.00        Max.   :0.08000      Max.   :383.0
  Market_share    Friends_share     Refuel_time       Emission
 Min.   :0.0500   Min.   :0.0000   Min.   : 5.00   Min.   :0.0000
 1st Qu.:0.1500   1st Qu.:0.1500   1st Qu.: 5.00   1st Qu.:0.0000
 Median :0.2500   Median :0.3000   Median : 5.00   Median :0.7500
 Mean   :0.3333   Mean   :0.3333   Mean   :13.33   Mean   :0.5833
 3rd Qu.:0.6000   3rd Qu.:0.5500   3rd Qu.:30.00   3rd Qu.:1.0000
 Max.   :0.9000   Max.   :1.0000   Max.   :30.00   Max.   :1.0000
      Sex              Age2             Age3             Age4
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :1.0000   Median :0.0000   Median :0.0000   Median :0.0000
 Mean   :0.7791   Mean   :0.4574   Mean   :0.2326   Mean   :0.1531
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:0.0000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000
     Edu_PG          Edu_Oth          Occu_Pvt        Occu_Pub
 Min.   :0.0000   Min.   :0.0000   Min.   :0.000   Min.   :0.0000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.000   1st Qu.:0.0000
 Median :0.0000   Median :0.0000   Median :0.000   Median :0.0000
 Mean   :0.4147   Mean   :0.1841   Mean   :0.376   Mean   :0.2733
 3rd Qu.:1.0000   3rd Qu.:0.0000   3rd Qu.:1.000   3rd Qu.:1.0000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.000   Max.   :1.0000
    Occu_SE       Location_metro   Location_majorcity      Ahm
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000     Min.   :0.00000
 1st Qu.:0.0000   1st Qu.:1.0000   1st Qu.:0.0000     1st Qu.:0.00000
 Median :0.0000   Median :1.0000   Median :0.0000     Median :0.00000
 Mean   :0.2655   Mean   :0.7655   Mean   :0.1453     Mean   :0.04457
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000     3rd Qu.:0.00000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000     Max.   :1.00000
      Ben               Chen              NCR              Hyd
 Min.   :0.00000   Min.   :0.00000   Min.   :0.0000   Min.   :0.00000
 1st Qu.:0.00000   1st Qu.:0.00000   1st Qu.:0.0000   1st Qu.:0.00000
 Median :0.00000   Median :0.00000   Median :0.0000   Median :0.00000
 Mean   :0.06977   Mean   :0.04651   Mean   :0.2558   Mean   :0.03682
 3rd Qu.:0.00000   3rd Qu.:0.00000   3rd Qu.:1.0000   3rd Qu.:0.00000
 Max.   :1.00000   Max.   :1.00000   Max.   :1.0000   Max.   :1.00000
      Kol              Mum            MajCity          HH_size
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   : 1.000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.: 3.000
 Median :0.0000   Median :0.0000   Median :0.0000   Median : 5.000
 Mean   :0.2016   Mean   :0.1105   Mean   :0.1453   Mean   : 4.463
 3rd Qu.:0.0000   3rd Qu.:0.0000   3rd Qu.:0.0000   3rd Qu.: 6.000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :10.000
    Children           IG2              IG3              IG4
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :0.0000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000
 Median :1.0000   Median :0.0000   Median :0.0000   Median :0.0000
 Mean   :0.8721   Mean   :0.3818   Mean   :0.4109   Mean   :0.1841
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:0.0000
 Max.   :4.0000   Max.   :1.0000   Max.   :1.0000   Max.   :1.0000
    HH_cars       PPC_morethan10   Daily_travel_medium Daily_travel_long
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000      Min.   :0.00000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000      1st Qu.:0.00000
 Median :0.0000   Median :0.0000   Median :0.0000      Median :0.00000
 Mean   :0.4864   Mean   :0.4516   Mean   :0.3702      Mean   :0.02713
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000      3rd Qu.:0.00000
 Max.   :3.0000   Max.   :1.0000   Max.   :1.0000      Max.   :1.00000
    Garage_y           DL_y          Own_accom      Freerider_tot
 Min.   :0.0000   Min.   :0.0000   Min.   :0.0000   Min.   :2.000
 1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:0.0000   1st Qu.:2.000
 Median :1.0000   Median :1.0000   Median :1.0000   Median :2.000
 Mean   :0.7267   Mean   :0.6357   Mean   :0.6647   Mean   :2.244
 3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:2.000
 Max.   :1.0000   Max.   :1.0000   Max.   :1.0000   Max.   :8.000
 Satisfaction_tot Political_view   WTP_env_tot      Warmglow_tot
 Standout
 Min.   : 2.000   Min.   :1.000   Min.   : 2.000   Min.   : 2.00   Min.
:1.000
 1st Qu.: 3.000   1st Qu.:3.000   1st Qu.: 7.000   1st Qu.: 6.00   1st
Qu.:2.000
 Median : 4.000   Median :3.000   Median : 8.000   Median : 8.00   Median
:3.000
 Mean   : 4.264   Mean   :3.258   Mean   : 8.124   Mean   : 7.61   Mean
:2.657
 3rd Qu.: 5.000   3rd Qu.:4.000   3rd Qu.: 9.000   3rd Qu.: 9.00   3rd
Qu.:3.000
 Max.   :10.000   Max.   :5.000   Max.   :10.000   Max.   :10.00   Max.
:5.000
 Acceptance_new Climate_perception    Env_pref      Tech_leader
 Min.   :1.0    Min.   :1.000      Min.   :1.000   Min.   :1.0
 1st Qu.:2.0    1st Qu.:4.000      1st Qu.:2.000   1st Qu.:2.0
 Median :3.0    Median :5.000      Median :3.000   Median :2.0
 Mean   :2.8    Mean   :4.483      Mean   :3.093   Mean   :2.5
 3rd Qu.:4.0    3rd Qu.:5.000      3rd Qu.:4.000   3rd Qu.:3.0
 Max.   :5.0    Max.   :5.000      Max.   :5.000   Max.   :5.0
 Social_motivation_tot  EV_risk_tot     EV_awareness_tot
 Min.   : 3.00         Min.   : 2.000   Min.   : 3.000
 1st Qu.: 9.00         1st Qu.: 8.000   1st Qu.: 4.000
 Median :11.00         Median : 9.000   Median : 5.000
 Mean   :10.62         Mean   : 8.661   Mean   : 5.419
 3rd Qu.:12.00         3rd Qu.:10.000   3rd Qu.: 6.000
 Max.   :15.00         Max.   :10.000   Max.   :15.000

On Tue, Sep 22, 2020 at 2:07 AM Rahul Chakraborty <chakrarahul at gmail.com>
wrote:

  
    
#
@Rahul;


You need to learn to post in plain text and attachments may not be xls 
or xlsx. They need to be text files. And even if they are comma 
separated files and text, they still need to be named with a txt extension.


I'm the only one who got the xlsx file. I got the error regardless of 
how many column I omitted, so my gues was possibly incorrect. But I did 
RTFM. See ?mlogit.datadfi The mlogit.data function is deprecated and you 
are told to use the dfidx function. Trying that you now get an error 
saying: " the two indexes don't define unique observations".


 > sum(duplicated( dfrm[,1:2]))
[1] 12
 > length(dfrm[,1])
[1] 18

So of your 18 lines in the example file, most of them appear to be 
duplicated in their first two rows and apparently that is not allowed by 
dfidx.


Caveat: I'm not a user of the mlogit package so I'm just reading the 
manual and possibly coming up with informed speculation.

Please read the Posting Guide. You have been warned. Repeated violations 
of the policies laid down in that hallowed document will possibly result 
in postings being ignored.
#
Hello David and everyone,

I am really sorry for not abiding by the specific guidelines in my
prior communications. I tried to convert the present email in plain
text format (at least it is showing me so in my gmail client). I have
also converted the xlsx file into a csv format with .txt extension.

So, my problem is I need to run panel mixed logit regression for a
choice model. There are 3 alternatives, 9 questions for each
individual and 516 individuals in data. I have created a csv file in
long format from the survey questionnaire. Apart from the alternative
specific variables I have many individual specific variables and most
of these are dummies (dummy coded). I will use subsets of these in my
alternative model specifications. So, in my data I have 100 columns
with 13932 rows (3*9*516). After reading the csv file and creating a
dataframe 'mydata' I used the following command for mlogit.

mldata1<- mlogit.data(mydata, shape = "long", alt.var = "Alt_name",
choice = "Choice_binary", id.var = "IND")

It gives me the same error message- Error in 1:nchid : result would be
too long a vector.

The attached file (csv file with .txt extension) is an example of 2
individuals each with 3 questions. I have also reduced the number of
columns to 57. Now, there are 18 rows. But still if I use the same
command on my new data I get the same error message. Can anyone please
help me out with this? Because of this error I am stuck at the
dataframe level.


Thanks in advance.


Regards,
Rahul Chakraborty
On Tue, Sep 22, 2020 at 4:50 AM David Winsemius <dwinsemius at comcast.net> wrote:
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: example2.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20200922/52cb1a83/attachment.txt>
#
You were told two things about your code:


1) mlogit.data is deprecated by the package authors, so use dfidx.

2) dfidx does not allow duplicate ids in the first two columns.


Which one of those are you asserting is not accurate?
#
Hello,

I apologize if the rest of quotes prior to David's email are missing, 
for some reason today my mail client is not including them.

As for the question, there are two other problems:

1) Alt_name is misspelled, it should be ALT_name;

2) the data is in wide, not long, format.

A 3rd, problem is that in ?dfidx it says

alt.var	
the name of the variable that contains the alternative index (for a long 
data.frame only) or the name under which the alternative index will be 
stored (the default name is alt)


So if shape = "wide", alt.var is not needed.
But I am not a user of package mlogit, I'm just guessing.

The following seems to fix it (it doesn't throw errors).


mldata1 <- dfidx(mydata, shape = "wide",
                  #alt.var = "ALT_name",
                  choice = "Choice_binary",
                  id.var = "IND")


Hope this helps,

Rui Barradas


?s 16:15 de 22/09/20, David Winsemius escreveu:
#
David,

My apologies with the first one. I was checking different tutorials on
mlogit where they were using mlogit.data, so I ended up using it.

I am not getting what you are saying by the "duplicates in first two
columns". See, my first column is IND which identifies my individuals,
second column is QES which identifies the question number each
individual faces, 3rd column is a stratification code that can be
ignored. Columns 6-13 are alternative specific variables and rest are
individual specific. So 1st 3 rows indicate 1st question faced by 1st
individual containing 3 alternatives, and so on. So, I have already
arranged the data in long format. Here, I could not get what the
"duplicate in first two columns" mean.


And I am really sorry that there was an error in my code as Rui has
pointed out. The correct code is
mldata1 <- dfidx(mydata, shape = "long",
                  alt.var = "ALT_name",
                  choice = "Choice_binary",
                  id.var = "IND")

It still shows the error-  "the two indexes don't define unique observations"
It would be really helpful if you kindly help.

Regards,
On Tue, Sep 22, 2020 at 8:46 PM David Winsemius <dwinsemius at comcast.net> wrote: