Announcement

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

  • Multi-nominal regression interactions with margins and margin plots

    Hi everyone,

    Does anyone know how to do the margin command for multinominal regression for a certain outcome?

    I'm trying to get margins to plot school year's use of energy drinks over time using repeated cross-sectional data.

    The mlogit command is (I want sugar2=0 to be the reference category):
    Code:
    mlogit sugar2 i.schlyear##c.year gender ethnic2 ses, base(0)
    Code:
    margins, at(year=(1998 2000 2002 2004 2006 2009 2013 2014 2015 2017) schlyear=(1 2 3 4 5 6 7))
    Code:
     marginsplot
    But this gives me the margins for outcomes 0, 1 and 2. I just would like outcome 1 and 2 to be separate graphs as it is too much in one graph.

    I have tried various ways of plotting margins but stata has returned errors.

    e.g.

    1)
    Code:
    margins, at(year=(1998 2000 2002 2004 2006 2009 2013 2014 2015 2017) schlyear=(1 2 3 4 5 6 7)), predict(outcome(#1))
    invalid 'predict' 
    2)
    Code:
    . margins schlyear##year, predict(outcome(#1))
    factor 'year' not found in list of covariates
    3)
    Code:
    margins i.schlyear##c.year, predict(outcome(#1))
    only factor variables and their interactions are allowed
    4)
    Code:
     . margins schlyear year, predict(outcome(#1))
    factor 'year' not found in list of covariates


    P.S.
    Details of variables:
    sugar2 = sugary drinks (never, weekly, daily) 0=base/reference category
    schlyear = school year (1-7)
    year = wave of data (1998 - 2017)
    gender = boy (1) girl (2)
    ethnic2 = white (1) BAME (2)
    ses = high (0) low (1)

    Any help would be greatly appreciated! Thanks in advance.

  • #2
    Code:
    margins schlyear, at(year = (1998 2000 2002 2004 2006 2009 2013 2014 2015 2017)) predict(outcome(2))  
    marginsplot

    will give you the graph for outcome sugar2 = 1 (because with base category 0, 1 is the second outcome). Then do the same with -predict(outcome(3))-

    Comment


    • #3
      This might help.

      https://www3.nd.edu/~rwilliam/stats3/Margins05.pdf

      Also check out the user-written combomarginsplot. Even if you wind up not using it, the help shows how you can do things like combine satisfied and very satisfied into a single line.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Hi Clyde, Richard,

        Clyde, thank you very much for providing me with this. I will try that code this morning.

        Richard - that you for providing that, I use a lot of your materials and I must have not come across this one. Your materials are very helpful so thank you for providing these further.

        Best wishes,

        Em

        Comment

        Working...
        X