Announcement

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

  • Interaction between binary categorical and continuous

    Looking at the European social survey ...

    I'm interested in how the effect of being divorced (divorced=1, not divorced=0) has on mental health conditions (mental) -- how this effect changes according to the years of education an individual has obtained (eduyrs).

    I started by doing a regression... code:
    xi: regress mental country_group gender age c.age#c.age religscale lmoutsider i.esec7 children ///
    i.divorced*eduyrs

    I've interpreted results and found the effect to be present. I have manually calculated by intercept, b1, b2, b3 and therefore the slopes etc.


    Then I want to use stata to plot this by doing predicted values (margins).
    I've tried a million codes and none of them work .. does anyone have any pointers?

    tried codes:
    margins i.divorced, at (eduyrs=(0(2)22))
    marginsplot

    margins divorced, at (eduyrs=(0(2)22))
    marginsplot

    margins at (eduyrs=(0(2)22)), over divorced
    marginsplot


  • #2
    What you probably want is something like:

    Code:
    regress mental country_group gender i.divorced##c.eduyrs c.age##c.age religscale lmoutsider i.esec7 children
    margins divorced, at(eduyrs=(0(2)22))
    marginsplot
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      Eilidth:
      welcome to this forum.
      1) your regression code does not need the -xi:- prefix, as -fvvarlist- notation is enough;
      2) I would be much more concerned about a potential endogeneity issue in your regression code (reverse causation): if, other things being equal, the divorced status may contribute to explain variations in mental health, the opposite may hold as well;
      3) in addition, another possible cause of endogeneity (latent variable) relates to education years. As your code does not take individuals'ability into account, based on the literature in your research field, you should rule out that other things being equal, smarter people have, on average, better mental health, as other things being equal, smarter people, on average, do better at school.
      4) I would go:
      Code:
      margins divorced, at (eduyrs=(0(2)22))
      marginsplot
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment

      Working...
      X