Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Receiving conformability (503) and subscript invalid (3301) error from mixlogit command

    Hello STATA Community,

    I'm analyzing discrete choice experiment data using the mixlogit command in STATA version 12.1. Unfortunately, I'm running into some errors and not sure how to address them.

    The data includes participants' choices of one agricultural practices between 2 alternatives or continuing their current practice (i.e., Opt-out). Thus, participants decide between 3 possible choices for each hypothetical scenario. Each agricultural practice entails 5 attributes with 3 to 4 values (MaizeYieldAttrib, StrigaPrevAttrib LaborAttrib SoilFertAttrib LegYieldAttrib). The monetary attribute is MaizeYieldAttrib. In addition to these attributes, the data includes demographic information (e.g., Resp_Gend, Resp_Age).

    When I run the choice model (see M1 below), I receive sensible results.

    M1 - mixlogit Farmer_Choice MaizeYieldAttrib, rand(StrigaPrevAttrib LaborAttrib SoilFertAttrib LgYieldAttrib Opt_Out) group(Group_ID) id(HHID)

    However, when I try to run the complete model (se M2, M3), which includes demographic variables, I begin receiving errors. I can add some demographic variables, but after a certain point, I begin receiving errors (see below).

    M2 - mixlogit Farmer_Choice MaizeYieldAttrib, rand(StrigaPrevAttrib LaborAttrib SoilFertAttrib LegYieldAttrib Opt_Out) Resp_Gend Resp_Age Resp_EduLev LandHOldings GanyuPrimOccup TotalMaizeArea HH_INCOME) group(Group_ID) id(HHID)

    conformability error
    r(503);


    M3- mixlogit Farmer_Choice MaizeYieldAttrib, rand(StrigaPrevAttrib LaborAttrib SoilFertAttrib LegYieldAttrib Opt_Out) Resp_Gend Resp_Age Resp_EduLev LandHOldings GanyuPrimOccup TotalMaizeArea StrigaRankInFields2017) group(Group_ID) id(HHID

    mixl_ll(): 3301 subscript invalid
    <istmt>: - function returned error
    r(3301)


    Any and all help is much appreciated. I believe there is a problem with my data. I've tried recoding it (e.g., square values, create logarithms), but to no avail. I have attached an incomplete table showing how my data is organized. Hope this helps! Thanks again.

    Kind Regards,
    Timothy


    Click image for larger version

Name:	Screen Shot 2018-01-23 at 3.06.15 PM.png
Views:	1
Size:	36.9 KB
ID:	1427075




  • #2
    The mixlogit command is a user-written extension to Stata. At the end of the output of help mixlogit there is a name and email address to contact with comments and suggestions. I expect the author would appreciate hearing of this problem, because the uninformative error message you received suggests that the code was confronted by an unanticipated condition.

    But with that said, first run which mixlogit and be sure the you have mixlogit 1.4.0 from 29Mar2016 (or later). If not, you should
    Code:
    net install st0133_2.pkg, replace
    and the see if the problem still exists.

    Comment


    • #3

      Dear William,

      Thank you for your speedy response. As instructed I downloaded the newer mixlogit. I previously had mixlogit 1.1.1.

      Previously (in the message above), I was receiving r3301 and r503 errors. While I no longer receive these error messages, I'm afraid I'm receiving a different error when I run the command-

      mixlogit Farmer_Choice MaizeYieldAttrib, rand(StrigaPrevAttrib LaborAttrib SoilFertAttrib LegYieldAttrib Opt_Out Resp_Gend Resp_Age Resp_EduLev LandHoldings GanyuPrimOccup TotalMaizeArea BothFieldMaizeHarv HH_INCOME) group(id) id(HHID)

      Variable HH_INCOME has no within-group variance
      r(459);


      The same thing occurs if I run a command that includes an independent variable indicating whether an observation had or did not have a specific pest in their field (1=yes, 0=no). Also, if I try to add a continuous variable indicating the number of soil fertility practices (1-7) an observation implemented over a year, I receive the same message. While I understand that these household level variables repeat themselves within a group ID (whereas MaizeYieldAttrib StrigaPrevAttrib LaborAttrib SoilFertAttrib LegYieldAttrib Opt_Out do not), why am I not receiving this error messag for Resp_Gend, Resp_Age, etc.?

      I'm sure this is something that may be addressed by the author of mixlogit, but I just thought I would follow up. Thank you for your time and consideration.

      Kind Regards,
      Timothy

      Comment


      • #4
        See the advice in this post:

        https://www.stata.com/statalist/arch.../msg00709.html

        Comment


        • #5
          So are you saying that you have successfully run mixlogit with a model that included Resp_Gend or Resp_Age? Or are you asking why the error message from mixlogit only lists a single variable, when you know there are others with a similar issue?

          In the latter case, I'm thinking it just stops at the first problematic variable it encounters, and if you take that variable out, another variable will cause the error message to be thrown, until you clear the non-varying variables.

          In the former case, I'm past the boundaries of my knowledge, although another member here may have some ideas.

          Comment


          • #6
            Dear William and Arne,

            Thank you both for your responses.

            Arne, reading that post was very helpful.

            William, please excuse the confusion. I successfully ran a model that included Resp_Gend AND Resp_Age. I tried adding the covariates one by one to see which one may have been problematic. What's strange is that I receive an error for HH_INCOME stating the variable is non-varying. This doesn't make sense considering that Resp_Age, doesn't vary for 18 observations. There are 18 observations per HHID. So a household's choices vary as well as choice attributes, but their household characteristics do not. So I'm wondering why I would get an error message indicating that HH_INCOME doesn't vary but not for Resp_Gend and Resp_Age (which don't vary). Based on Arne's response, it appears I have to interact these covariates with "alternative-specific constants".

            Thanks again,
            Timothy

            Comment


            • #7
              Hi Arne and William,

              Once again, thank you for addressing my previous hiccups. I still have one more question but would like to first share some information for 1st time users employing mixlogit to analyze their choice experiment data-

              After you write mixlogit and list your dependent variable, you list your the case specific variables (i.e., characteristics of the individual). Afterwards, in rand brackets, list the alternative-specific variables (i.e, attributes). For instance, if you're using data from a choice experiment that analyzed car consumer decisions, your case-specific variables might be age, gender and/or income. Your alternative-specific variables might be price, color and/or miles per gallon of fuel (depending on the attributes identified). The group ID refers to the choice set. So if car consumers had 3 alternatives (i.e., cars) to choose from, the first choice set would have three corresponding 1's in the ChoiceSet_ID column and the second choice set would have three corresponding 2's. In this example, you would write the code-

              mixlogit Consumer_Choice Consumer_Age Consumer_Gender Consumer_Income, rand(Price_Attribute Color_Attribute MPG_Attribute), group(Choice_Set_ID) id(Consumer_ID)

              You may refer to my first post if you have questions about how the data was organized. Arne and William, please correct me if I'm wrong. I'm sure there are some instructions I could not find which are pretty straight forward, but I thought this information might be helpful.

              The other question I have is how to address the conformability errors (r503) I'm receiving for my mixlogit. At first, I thought the problem was arising because of missing observations. So I summarized the explanatory variables to make sure they all had the same number of observations (3240). I even summarized the Group ID and individual ID to make sure there were 3240. All amount to this total, but when I run the mixlogit below, one observation is missing (i.e,. n = 3239) in the regression table.

              mixlogit Farmer_Choice RespGen RespAge RespEdu HhTotalLandOwn HhLabor HhIncome FarmMaizeArea FarmMaizeYield FarmStrigaHist, rand(MaizeYieldAttrib StrigaEmergAttrib LaborReqAttrib SoilFertAttrib LegYieldAttrib) group(id) id(HHID)

              If I try to add one more critical case-specific variable such as household income, I receive a conformatibility error. The three case-specific variables I would like to add all have 3240 observations. There are 18 observations per participant because they participated in 6 choice scenarios with 3 alternatives to choose from. Hence, my n should be divisible by 18. I think this may be a clue to why I'm receiving errors. Any suggestions on how to troubleshoot this issue? Thank you for your time and consideration.

              Kind Regards,
              Timothy

              Comment


              • #8
                This is another uninformative error message, like the one you initially reported in your first post, and (since you now have the latest version of mixlogit) as someone who does not use mixlogit, I cannot improve on the advice I offered in the first paragraph of post #2.

                Comment


                • #9
                  Timothy

                  The advice you have provided is incorrect and it directly contradicts the mixlogit help file which explains that:

                  rand(varlist) is required and specifies the independent variables whose coefficients are random. … The variables immediately following the dependent variable in the syntax are specified to have fixed coefficients.

                  As explained in the Statalist post linked to in #4 above individual-specific variables need to be interacted with alternative-specific constants to be included in the model. This is the case regardless of whether the variables are specified to have fixed or random coefficients. See the second (pupils’ behaviour) example in http://www.stata-journal.com/sjpdf.h...iclenum=st0133 for an example – I recommend that all new users of mixlogit read this paper and the help file before using the command to prevent any misunderstandings.

                  I will not be able to help you more with this as I have too many other demands on my time at the moment, but I did not want this misleading advice to stand uncorrected.

                  Arne

                  Comment


                  • #10
                    Dear Arne,

                    I apologize for posting incorrect information. Thank you for correcting this misleading advice.

                    I will interact the individual-specific variables with alternative-specific constants. Thank you for sending the link of the pupils' behaviour example.

                    Take Care,
                    Timothy

                    Comment


                    • #11
                      Timothy

                      No problem. Good luck with your analysis.

                      Arne

                      Comment


                      • #12
                        Hello,

                        As I understand, the coefficient and standard error of a price variable in a willingness to pay space are generally not reported in peer-reviewed articles. I receive them, however, when I run the following command-

                        mixlogitwtp Farmer_Choice Opt_Out_Constant, rand(soil_high_c soil_low_c labhc lablc str_hc str_lc leg_hc) price(maize) group(Group_ID) id(HHID)

                        Please see the results below, where the price variable is reported.
                        Mixed logit model in WTP space Number of obs = 3,870
                        Wald chi2(9) = 3223.51
                        Log likelihood = -1224.3234 Prob > chi2 = 0.0000
                        Coef. Std. Err. z P>z [95% Conf. Interval]
                        Mean
                        Opt_Out -1.175352 14.05364 -0.08 0.933 -28.71998 26.36928
                        soil_high_c 15.00154 4.433559 3.38 0.001 6.311928 23.69116
                        soil_low_c -12.97617 5.111912 -2.54 0.011 -22.99533 -2.957004
                        labhc -14.11424 5.324205 -2.65 0.008 -24.54949 -3.678993
                        lablc 10.83061 5.406536 2 0.045 0.2339967 21.42723
                        str_hc -20.69909 5.10284 -4.06 0 -30.70047 -10.69771
                        str_lc 12.29053 5.171295 2.38 0.017 2.154977 22.42608
                        leg_hc 33.96455 6.416826 5.29 0 21.38781 46.5413
                        maize -4.515235 0.1440789 -31.34 0 -4.797624 -4.232845
                        SD
                        soil_high_c -1.016615 7.598444 -0.13 0.894 -15.90929 13.87606
                        soil_low_c -2.689085 9.291119 -0.29 0.772 -20.89934 15.52117
                        labhc -0.7380442 11.48615 -0.06 0.949 -23.25049 21.7744
                        lablc -3.150765 9.986153 -0.32 0.752 -22.72326 16.42174
                        str_hc -1.29142 6.696918 -0.19 0.847 -14.41714 11.8343
                        str_lc -9.031636 8.357229 -1.08 0.28 -25.4115 7.348232
                        leg_hc -35.57084 7.92673 -4.49 0 -51.10694 -20.03473
                        maize -0.5611764 0.0893419 -6.28 0 -0.7362833 -0.386069
                        The price variable, maize, assumes either 50, 75, 100 or 125 which correspond to a 50% reduction in current yield, a 25% reduction in current yield, no reduction or a 25% increase in current yield, respectively.

                        I have three questions based on these results.
                        1. Being that maize is the price variable, why is it reported in STATA from a mixlogitwtp command? Or rather, why aren’t the coefficient and standard error omitted?
                        2. Should I modify my command?
                        3. How do I interpret the results of maize in the following table?
                        Thank you for all of your help.

                        Note-

                        The data includes participants' choices of one agricultural practice out of 2 alternatives or an opt-out option. Thus, participants decide between 3 choices for each hypothetical scenario. Each scenario entails an agricultural practice that includes 5 attributes with 3 levels (excluding the monetary attribute). The choice attributes you see in the table are in effects form and are defined as-

                        Attribute 1 - soil_high_c/soil_low_c indicate high or low soil fertility received from practice
                        Attribute 2 - labhc/lablc indicate high or low labor requirements demanded by practice
                        Attribute 3 - str_hc/str_lc indicate high or low Striga prevalence (a weed that parasitizes maize) received from practice
                        Attribute 4 - leg_hc/leg_lc indicate high or low legume yield received from practice
                        Attribute 5 - The monetary attribute is maize.

                        Status-quo is omitted from each attribute. So soil_med_c, labmc, str_mc and leg_mc are not foud in the mixlogitwtp command.




                        Comment

                        Working...
                        X