Announcement

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

  • Creating a graph for an interaction term in Stata?

    Hi,

    I am terrible with STATA and need to create a graph for an interaction term for a paper that I am writing. My code is as follows;

    xi: svy: nbreg sdq_conduct1 i.lang2*BDCSBI gendercomp OECDcomp

    With sdq_conduct1 the outcome, lang2 being a binary variable containing 2 populations, BDCSBI as a continuous variable, gendercomp/OECDcomp are covariates controlling for gender & SES.

    My output for this is attached. The interaction was significant. Thanks for any help!
    Attached Files

  • #2
    Unless you are using a very old version of Stata, the way to do this is to back up and re-do the regression using factor variable notation and then run -margins- and -marginsplot-. If you are using a modern Stata, you should basically make strenuous efforts to forget you ever knew about -xi:-. It is obsolete, and its use, as here, actually makes your life harder by blocking your access to the -margins- command. Nearly anything you used to do with -xi- is better done with factor-variable notation now. (There are a few commands in Stata that don't allow factor-variable notation, but they are mostly archaic commands whose functionality is available in more modern commands that do allow it. There are a handful of situations where -xi- still comes in handy even with modern commands, but they are so rare that it is better to just use factor-variable notation all the time.)

    Read -help fvvarlist- and the associated manual section.

    So:

    Code:
    svy: nbreg sdq_conduct1 i.lang2##c.BDCSBI gendercomp OECDcomp
    Now, you don't say what kind of interaction plot you want. Do you want to show the predicted values of seq_conduct1 as a separate function of BDCSBI for each value of lang2? Or do you want to plot the effect of lang2 on seq_conduct1 as a function of BDCSBI? Those are two different graphs, and both could be fairly called an interaction plot. The first of these would be coded as:

    Code:
    margins lang2, at(BDCSBI = (1 2 3 4 5))
    marginsplot
    The second would be:
    Code:
    margins, dydx(lang2) at(BDCSBI = (1 2 3 4 5))
    marginsplot
    Note: I have used 1 2 3 4 5 as an placeholder for a Stata numlist that spans the interesting range of values of BDCSBI. You have the data, so you know what that range of values might be. Substitute accordingly.

    Also note that -marginsplot- accepts most options available in -graph twoway-, so you can customize the graph's appearance to your liking.


    Comment


    • #3
      You are a god amongst men. Thank you.

      Comment

      Working...
      X