Announcement

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

  • Variable not found in list of covariates when trying to do margins plot

    I have tried to use dataex but I'm having some difficulty in uploading my data, so I apologise for that. I have attached a screenshot of what I'm attempting to do.

    I was trying to see if my regression indicated a non-linear relationship, between my ordinal dependent variable (envirecon) which is on a 10 point scale and I am treating as a continuous, and my categorical independent variable edu_lvl. edu_lvl has categories of education level: below gcse, gcse, a level, undergrad and post grad.

    I read on another topic that it does not make sense to do this as Dr Clyde Schechter commented: "That's because in a categorical variable, the numbers representing the levels are considered to be arbitrary". He recommended to someone to proceed their regression with a margins plot. I am attempting to do this, but stata is telling me that my dependent variable - envirecon - was not found in the list of covariates. I have attached a screenshot from stata below.

    Would someone be able to let me know where I've gone wrong?

    Thank you in advance.

    Click image for larger version

Name:	Screenshot 2021-12-23 at 18.23.23.png
Views:	1
Size:	355.7 KB
ID:	1642178

  • #2
    The varlist in the -margins- command can include only predictor variables from the regression.

    It's not clear to me what you intended by putting envirecon#i.edu_lvl there. Given the regression model you ran, all you can do is estimate the expected values of envirecon conditional on the values of edu_lvl. The command to do that does not require mentioning envirecon at all, as it is the dependent variable in the regression, which is implicitly what is being assessed. The code is just -margins edu_lvl-.

    Comment


    • #3
      Thank you Dr Schechter! I clearly got a bit confused. Thank you again for getting back to me so fast and for helping me out.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        The varlist in the -margins- command can include only predictor variables from the regression.

        It's not clear to me what you intended by putting envirecon#i.edu_lvl there. Given the regression model you ran, all you can do is estimate the expected values of envirecon conditional on the values of edu_lvl. The command to do that does not require mentioning envirecon at all, as it is the dependent variable in the regression, which is implicitly what is being assessed. The code is just -margins edu_lvl-.
        I was wondering (and I apologise if this is a silly question) but does a margins plot show the regression visually? Or if not, what would the purpose of a margins plot be?

        Comment


        • #5
          The margins plot shows the expected value of the outcome variable as a function of the variable specified, adjusted for other model variables in the way specified by any -at()- or -atmeans- options. In a simple model like the one you show in #2, it will just plot expected value of envirecon as a function of education level.

          Comment

          Working...
          X