Announcement

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

  • margins error: "could not calculate numerical derivatives..."

    Hello,

    I really hope someone can help.

    I get the following error when I try running the margins command after an HLM model:
    "could not calculate numerical derivatives -- discontinuous region with missing values
    encountered
    r(459);"

    My syntax looks something like this:
    set more off
    melogit income eduyrs female poc discrimination family_income family_edu town_discrim town_stereotypes femalediscrim female_famedu female_towndiscrim || family: || town:, or
    margins

    The last three variables in the HLM model are interactions, and the last two are cross-level interactions. I get no errors running the actual HLM. It's just the margins command that doesn't work.

    I've also tried simplifying the model, but even if I just have income and eduyrs, I still get that error for margins. I also get the error if I drop all observations that are missing on any of the variables in the model.

    So I really have no idea what to do.

    Thanks in advance for the help.

  • #2
    I am running into the exact same problem after melogit, with the exact same error code. My code is nothing more than a simple:

    melogit y x1 x2...xi || id:

    It actually works for a a few other melogit models with different dependent variables, but not for this one. The only thing different about this model is a smaller sample size, and also relatively few cases where there are multiple records per person.

    Does anyone have any ideas? Thank you for your time.

    Comment


    • #3
      Update: The problem seems to be with the random effects. Omitting the random effects, as done here, seems to solve the issue:

      margins, predict(xb) post
      margins, coeflegend
      local predprob=exp(_b[_cons])/(1+exp(_b[_cons]))

      Is there a way to use only the fixed effects in calculating the predicted probabilities using only margins?

      Thank you for your time.

      Comment

      Working...
      X