Announcement

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

  • margins: factor variables may not contain noninteger values

    I am trying to estimate the marginal effects of my xtlogit model, which looks like this:
    xtlogit onset c.l.log_welfarespending##c.l.ethnic_groups l.gdplog, re vce(robust)
    The model itself runs smoothly and there are no complications at all. When I try to estimate the marginal effects:
    margins log_welfarespending, at(l.ethnic_groups(= (0, 6))
    I receive log_welfarespending: factor variables may not contain noninteger values. From what I have read so far sometimes Stata needs a specification on whether the variables are categorical or continuous. When I change the code to:
    c.margins log_welfarespending, at(l.ethnic_groups(= (0, 6))
    The error changes to only factor variables and their interactions are allowed. Any suggestions how to solve the problem?


  • #2
    In you regression you have clearly specified log_welfarespending as a continuous variable, not a discrete one. So it simply cannot be used in -margins- the way you are trying. To get margins for specific values of that variable, you have to use the -at()- option instead.

    Comment


    • #3
      Clyde Schechter thanks a lot for the answer. Would it be possible to use the at() option twice? To display the margins
      from log_welfarespending at the values 3, 4 and 5 when l.ethnic_groups are 0 and 6 ?

      Comment


      • #4
        Yes, you could do that. But there is no need to use the -at()- option for the ethnic groups: that is a discrete variable with non-negative integer values, right? You only need the -at()- option for the continuous variables. So I would do this as:

        Code:
        margins ethnic_groups, at(log_welfarespending = (3 4 5))
        Now, that will give you the margins for all combinations of log_welfarespending = (3 4 5) and each ethnic group 0 through 6. If you only care about ethnic groups 0 and 6, the simplest thing is to just disregard the results you get for ethnic groups 1 through 5. But if that is not convenient, or if the -margins- command takes a long time to run, then you can pare it back using the double-at approach:

        Code:
        margins ethnic_groups, at(log_welfarespending = (3 4 5) ethnic_groups = (0 6))
        Last edited by Clyde Schechter; 15 Apr 2022, 12:18.

        Comment


        • #5
          Clyde Schechter thank you again! My problem is the grapgh is kind of messy with all 6 levels of ethnic groups. I can edit the grapgh in a way that these levels are hidden, but due to the high standard errors of one level of ethnic groups (which I terefore want exclude from the graph) it only pictures the graph from "far away", so the 95% Cls can be shown. When tryin

          margins ethnic_groups, at(log_welfarespending = (3 4 5) ethnic_groups = (0 6))

          I get the error variable 'ethnic_groups' not found in list of covariates

          Comment


          • #6
            Sorry, for a couple of errors. I see that your variable is l.ethnic_groups, not ethnic_groups. Also, it shouldn't be mentioned in both places. So the command should be:
            Code:
            margins, at(log_welfarespending = (3 4 5) l.ethnic_groups = (0 6))

            Comment


            • #7
              The problem remains: error variable 'ethnic_groups' not found in list of covariates

              Comment


              • #8
                Post back with the exact output of your regression and the exact regression and margins commands you are using so I can see what is going on.

                N.B. Important: do that by copying and pasting from your Results window or log file. Do not type it in manually, and do not edit the output in any way.
                Last edited by Clyde Schechter; 15 Apr 2022, 16:01.

                Comment

                Working...
                X