Announcement

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

  • Xtlogit with weights workaround

    Hi,

    I'm trying to run a random effects logit models with weights. The syntax I was trying was

    xtologit dichotomousdv keyiv control1 contol2 control3 if selectioncriteria==1 [pweight=nweight]

    I get a message that weights are not allowed with random effects models (though I'd been using them with xtologit for other models and they worked just fine).

    These are sampling weights. The models is random effects because cases are not independent but nested.

    I was googling yesterday and found some mention of another command that could be used to run essentially the same model, but now I can't find what I was reading yesterday. Can someone please help me figure out how to do this?

    I have stata15

    Thank you.


  • #2
    -help melogit-

    Comment


    • #3
      Thank you!

      And reading that actually provided the answer to another problem I'd been having for another project, so it was super useful.

      Based on that, I think this would be essentially the same model, yes?

      melogit depvar | nestingvariable: mainiv control1 control2 control3 if selctioncriterion==1 [pweight=nweight]

      Comment


      • #4
        You have the syntax wrong. It should be:

        Code:
        melogit depvar mainiv control1 control2 control3 if selctioncriterion==1 [pweight=nweight] || nestingvariable:
        The nestingvariable: part of the model goes at the end, and you need two pipe characters to set it off, not just one.

        Comment


        • #5
          Huh...apprently not. First, if si not allowed, so I saved a copy of the data set and dropped the other cases. But then it says "weights is no allowed" too. So I put the weights in the first half before the ||, and I'm not sure that's right and it's been trying to fit the model for about 20 minutes now. Like it says "fitting full model" and hasn't moved beyond that point. It fit the random effects model first, then stuck on "Refining starting model" a while and is now stuck on fitting full model. This makes me wonder if putting the weights in the first half was wrong somehow, since that's pretty much the only thing that's in the full model and not the random effects model.

          Comment


          • #6
            Ok, I wrote my response before seeing your reply. For future readers, the apparently wrong thing I was doing was melogit dv [pweight=nweight]|| nesting variable: maindv control2 control1 control3

            Thank you so much!

            Comment


            • #7
              I am also trying to run a random effects logit models with pweights. The code in #4 works perfectly if you dont have panel data but what can one do if you have a panel structure?

              Comment


              • #8
                So far I have only found a solution with a population-averaged estimation instead of RE:
                Code:
                xtlogit y x [pweight=pweight], nolog pa
                Is there an alternative for using random effects and pweights?

                Comment


                • #9
                  Hello!!
                  Is not possible somehow to use pweight for xtmelogit? Is there any alternative? (especially, I see 4 years have passed since the last consultation). Thank you very much!!
                  Last edited by Juan Gomez; 11 Apr 2024, 06:17.

                  Comment


                  • #10
                    Well, if you are using current Stata, -xtmelogit- no longer exists--it went away at version 13. Athough the name continues to work, its current name is -meqrlogit-, and, no, it does not support pweights (nor any other kind of weights.) However, if you have a mixed-effects logistic regression model to estimate, -melogit- will do that, and does support pweights. You are only stuck in the event that -melogit- fails to converge: you will not be able to try -meqrlogit- as a plan B.

                    Comment


                    • #11
                      Thank you, Clyde. That´s right. I am stuck because melogit fails to converge. Then, there is not plan B, for instance, in an .ado, is it?

                      Comment


                      • #12
                        I'm not aware of any other Stata program that will do a multi-level logistic regression and also accepts pweights. I think you should invest some time and effort into trying to find out why your -melogit- isn't converging, as you may be able to fix that. The first thing I would do is inspect the iteration log you got from the failed attempts at -melogit-. Near the end, was the log-likelihood still increasing, or was it either unchanging or "going around in circles." If the latter, rerun the -melogit- adding an -iterate(#)- option, setting # to be a little bit lower than the number of iterations at which the log-likelihood stopped increasing. -melogit- will then run that far and halt showing you interim results. These interim results are not valid results you can report, but they may have clues as to why the estimation is failing to converge. In my experience the commonest thing you will see is that for one of the random effect levels, the variance component is very close to zero. Zero variance components are not estimable and cause non-convergence. The solution is to remove that level from the model. Another common clue is that for one or more of the fixed effects you will see absurdly large or absurdly small coefficients or standard errors. That points to problems with that (those) variables. You should carefully recheck the data on those variables to make sure that you don't have important data errors. If there are no such data errors or the non-convergence persists after you fix them, then you have to remove that (those) variables from the model.

                        If none of that helps, start over with a minimal model that includes only your outcome, and one key predictor variable in the fixed effects. Run -melogit-. Assuming it converges, now add another fixed-effect. And another, and another, continuing until you finally reach a non-convergent model. The last variable added that provokes non-convergence is now identified as problematic and should be omitted. Continue adding more variables (but excluding the problem variable already identified), to build up the largest model you can, always excluding any variable(s) that, when added, block convergence. Your model will be less than you wanted, but it will give you part of what you were seeking.

                        Comment


                        • #13

                          Thank you very much Clyde. I tried what you suggested but was unsuccessful (probably due to the complexity of my data). Then, I tried with a .ado -gllamm- that allows weight and weight, and everything is fine. However, this .ado does not allow the use of margins. So, I looked at other posts and some suggested this manual way of extracting margins. It is displayed on the page. 29: https://www3.nd.edu/~rwilliam/stats/Margins01.pdf . This interesting document shows how to apply this type of margins: margins black female, atmeans

                          However, I need to implement another type or margins such as the following:

                          margins v2, at ( v3 =(11 12 13 14 15 16 17 18 19 20))
                          Now I'm at a standstill because I can't manually apply these types of margins. I would understand that, maybe, this question may exceed the limits of this Stata Forum. In this case, do not consider it. But if it is possible to have an answer I would appreciate a lot.
                          Last edited by Juan Gomez; 24 Apr 2024, 03:29.

                          Comment


                          • #14
                            Well, the calculation of marginal effects at specific values of a variable is no different in principle from the calculations you cited in Richard Williams' document.

                            Instead of the commands
                            Code:
                            scalar female_mean = .5250121
                            scalar age_mean = 47.56584
                            where .5250121 and 47.56584 are the mean values of female and age in the data set, do
                            Code:
                            scalar v3 = 11
                            Then do it again with -scalar v3 = 12-, etc.

                            In fact, you can automate the process by looping over candidate values of v3
                            Code:
                            // RUN GLLAAM
                            matrix b = e(b)
                            clonevar v3_original = v3 // SAVE ORIGINAL VALUES OF V3
                            forvalues x = 12/20 {
                                replace v3 = `x'
                                matrix score yhat = b if e(sample) // CALCULATES xb WITHOUT WRITING OUT A LENGTHY EQUATION
                                summ yhat if e(sample), meanonly
                                scalar logodds = r(mean)
                                scalar  phat = invlogit(logodds)
                                display "Predictive margin at v3 = `x', other variables as observed = " phat
                                drop yhat
                            }
                            replace v3 v3_original // RESTORE ORIGINAL VALUES OF V3
                            What you wont' have, that you would get if you could apply -margins-, is standard errors and their associated statistics. Calculating those is much more complicated and I don't have code to do it.

                            Comment


                            • #15

                              Thank you very much Clyde. Your wise suggestions have been really helpful!!

                              Comment

                              Working...
                              X