Announcement

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

  • clogit and Marignal effects

    hello everyone,
    I am using Stata 16, and for my research model, I am using -clogit- to run my model as:
    Code:
    clogit Dep_var Var1 Var2 Var3 i.year i.industry, group(id)
    Now I wanted to compute the marginal effects as:
    Code:
    margins  Var2
    But whenever I do this, I get the following error:
    Code:
    factor Var2 not found in list of covariates
    r(322);
    Var 2 is a binary variable made up of 1 and 0, so I thought maybe margins command has some problem with discrete variable, so I tried with Var3 which is a continuous variable in my model. But this gives me another error:
    Code:
     Var3:  factor variables may not contain noninteger values
    r(452);
    I am just not sure what is going on anymore. I tried to read other posts and thread and could not find anything that helps my case. I have been stuck on this for sometime now, and I will be really grateful for any suggestions. Is there something very simple that i am missing?

    Regards,
    Shiwani

  • #2
    Yes, Var2 may be a 0/1 variable, but you didn't tell Stata that when you gave your -clogit- command so -margins- doesn't know about it. You have to fully use factor variable notation in your regression commands whenever you want to use -margins. See -help fvvarlist- for details. So Var2 needs an i. prefix in the -clogit- command, just like year and industry have.

    As for the problem with Var3, since it is not a non-negative integer variable, you cannot ask -margins- to use it in the same way. You have to instead specify specific values of Var3 at which you would like the predictive margins calculated. For the sake of illustration, let's suppose you are interested in predictive margins for Var3 = 1, 5, 10, and 25. Then you would write
    Code:
    margins, at(Var3 = (1 5 10 25))

    Comment


    • #3
      Hi Clyde, Thank you so much for your help and pointing out what went wrong. Now, I did as you said and told Stata that my Var2 is binary by using an i.prefix, and I was able to get the code running. I got the following output, and this does not look good to me. Do you any idea/ suggestions on what could be the reason? I am very sorry, but I have never used margins or logistic regression on any of my work before, so I am getting a little more confused.

      Click image for larger version

Name:	margins.png
Views:	1
Size:	7.7 KB
ID:	1580834

      Comment


      • #4
        There is nothing wrong with how you did the -margins- command. The results are rather strange looking--it is unusual to have such a high predicted probability under all circumstances. This in turn suggests that the variable idthes is almost always non-zero in your data set. There are other possibilities as well, but that is the most likely. To diagnose the situation it would be important to see the output of -clogit- itself along with a short but representative example from your data set. (Use the -dataex- command to show example data. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.)

        Comment

        Working...
        X