Announcement

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

  • Plotting adjusted predictions for interaction effects with continuous and discrete variables for different values

    Dear Statalist,

    I am using Stata15 and have an issue about how to plot adjusted predictions for interaction effects with continuous and discrete variables.
    The application of the margins and marginsplot command is straightforward to me when interacting the main effect with a dummy variable, however, the same command only produces errors for continuous and discrete variables.

    I am analyzing the effect of the variable A und the probability of B equaling 1 in a logit model. A can take on values between 0 and 1. I interact the variable A with three other variables X,Y and Z.

    X is a dummy variable, Y is a discrete variable taking on values from 0 to 10, and Z is a continuous variable.

    In order the show the graphical effect of the interacting variables on the main effect A on Pr(B)=1, I want to plot adjusted predictions A*X, A*Y and A*Z.

    For the interaction of A*X (dummy variable) I used the following code:

    Code:
    logit B c.A##i.X
    margins i.X, at(B==(0(0.1)1)) atmeans
    marginsplot
    Here, the marginsplot command produces a graph for adjusted predictions of Pr(B) depending on the levels of A moderated by X=0 and another graph for X=1.

    I want a similar plot for the interaction with my discrete variable Y, comparing graphs for different values of Y, for example Y=0,5 and 10.
    Further, I want a plot for the interaction with the continuous variable Z for specific values of Z, for example 20, 40 and 70.


    How can I do this in Stata?

    Thank you very much for your help!
    Antonia

  • #2
    The code you show in #1 cannot be what you have run. It would produce an error message and no results. With B as the outcome variable in -logit-, it cannot appear as a variable in the-at()- specification in -margins-. I think you meant A there. But the important point is that when you are asking for help with code here, it is important to post the exact code you ran--by copy/pasting from the Results window or your log file. In this case, I'm fairly confident I've correctly guessed what you meant. But in other situations, whoever tries to help you could end up wasting their time and yours fixing code that you never ran in the first place.

    I want a similar plot for the interaction with my discrete variable Y, comparing graphs for different values of Y, for example Y=0,5 and 10.
    Code:
    margins, at(Y = (0 5 10) A = (0(0.1)1)) atmeans
    margins, xdimension(A)

    Comment


    • #3
      Thank you for replying to my post and apologies for the mistake in the code.
      The exact code I ran was the following for the interaction with the dummy variable:
      Code:
      logit Crossborder_FirmNat c.A##i.X num_localinvestors log_domexperience_t1 log_intexperience_t1 log_ageoffirm logcompanyage log_firmsize gei_score Eff_LegalSys ka_open sreligion slanguage i.LegalClass_InvNatencode i.year if obs_use5==1, robust cluster (FirmName)
      margins i.X, at(A==(0(0.1)1)) atmeans
      marginsplot
      If you try your suggested code for the interaction A*Y the first line works, however the command xdimension produces the error "option xdimension() not allowed r(198)"
      This is what I did exactly:

      Code:
      logit Crossborder_FirmNat c.A##c.Y num_localinvestors log_domexperience_t1 log_intexperience_t1 log_ageoffirm logcompanyage log_firmsize gei_score Eff_LegalSys ka_open sreligion slanguage i.LegalClass_InvNatencode i.year if obs_use5==1, robust cluster (FirmName)
      margins, at(Y = (0 5 10) A = (0(0.1)1)) atmeans
      margins, xdimension(A)
      What can I do to fix this error?

      Comment


      • #4
        Sorry, my mistake. That last command should have been
        Code:
        marginsplot, xdimension(A)

        Comment

        Working...
        X