Announcement

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

  • Error in the mfx command after running a logit model consisting of continuous and categorical independent variables

    Respected sir/ma’am, I am new to stata and using version15. I have ran a logit regression command (logit Insured Gender Age illiterate Highersecondary Familysize Marginal Small Semimedium i.Highest_education_familymemeber) successfully consisting of covariates (continuous, Binary and as well as categorical). After this I am trying to get the marginal effect for all the covariates by usage of command mfx. But the sata is showing error as mfx default predict() is unsuitable for marginal-effect calculation r(119); . Please let me know the correct command to get marginal effects for all covariates at once.

  • #2
    The -mfx- command is outdated. You need to use -margins- instead.

    Before you do that, you may need to modify your -logit- command somewhat. I notice that you did use the i. prefix on Highest_education_familymember--so you have at least some familiarity with factor-variable notation. But some of the other variables in your model look, by their names, to be discrete as well, and they, too should have i. prefixes. I am also concerned about the variables Marginal Small and Semimedium. Again, the names suggest that these are three levels of a single categorical variable. If that is the case, then those variables should be eliminated and replaced by a single variable taking on three non-negative integer values. That single variable, with an i. prefix, should then appear in the -logit- command.

    After you have re-run the -logit- command accordingly, you can get the marginal effects you seek with
    Code:
    margins, dydx(list_all_the_variables_whose_marginal_effects_you_want_here) predict(pr)
    This will give you average marginal effects for the variables you select.

    Note: The -predict(pr)- option may or may not be necessary here. It's purpose is to be sure that Stata will calculate the average marginal effect of each variable on the probability of the outcome variable. In the current version of Stata (18) that would happen by default even without the -predict()- option being specified. But the default predictions of -margins- vary from one estimation command to another, and sometimes within the same estimation command across versions. As I no longer have access to version 15, I felt that the safest approach is to include -predict(pr)-. Even if it is unnecessary, it is harmless.

    Comment

    Working...
    X