Announcement

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

  • Graphing predicted probabilities for a multinomial logistic regression results with an interaction variable in Stata

    Hello

    I am trying to graph predicted probabilities for child undernutrition. I am using multinomial logistic regression. The response variable has five categories (not undernourished, stunted only, underweight and stunted, wasted and Missing). I am interested in plotting two categories (stunted only and underweight and stunted. I would like to average values for the standardised age for the graphing. My model is as follows: svy:mlogit undernutrition Stagesquared Stage Childsex i.sbi3 i.pbi5 i.Wealthstatus i.sizeatbirth ///
    Motherheight Motherweight i.Maternaleducation i.Ethnicity Agesbi

    On google I have come across some information which led me to do the following:

    margins, at(Stage = (-1.40 (0.35) 1.75)) predict (outcome(1)) vsquish
    margins, at(Stage = (-1.40 (0.35) 1.75)) predict (outcome(2)) vsquish
    margins, at(Stage = (-1.40 (0.35) 1.75)) predict (outcome(3)) vsquish
    margins, at(Stage = (-1.40 (0.35) 1.75)) predict (outcome(4)) vsquish

    predict p1 p2 p3 p4 p5
    sort Stage
    twoway (line p1 Stage if sbi3 ==1) (line p1 Stage if sbi3==2),legend(order(1 "sbi3 = 1" 2 "sbi3 = 2") ring(0) position(7) row(1))
    twoway (line p2 Stage if sbi3==1) (line p2 Stage if sbi3==2), legend(order(1 "sbi3 = 1" 2 "sbi3 = 2") ring(0) position(7) row(1))
    twoway (line p3 Stage if sbi3 ==1) (line p3 Stage if sbi3==2),legend(order(1 "sbi3 = 1" 2 "sbi3 = 2") ring(0) position(7) row(1))
    twoway (line p4 Stage if sbi3==1) (line p4 Stage if sbi3==2), legend(order(1"sbi3 = 1" 2 "sbi3 = 2") ring(0) position(7) row(1))
    twoway (line p5 Stage if sbi3 ==1) (line p5 Stage if sbi3==2),legend(order(1 "sbi3 = 1" 2 "sbi3 = 2") ring(0) position(7) row(1))

    Its not working for me. I am sure I am missing something here. Could anyone in the know please help.

    Thank you

    Lana

  • #2
    Well, you don't say in what sense it is "not working" for you, so I am left to guess what the problem might be. That said, I see a few problems here that I can point out, though I can't necessarily tell you how to solve them, since I can't be sure exactly what you were hoping to get.

    1. Your thread title refers to a model with an interaction term, but the model you show doens't have one. What it does have is a pair of variables called Stage and Stagesquared. Stata is not able to recognize that you intend this to be a quadratic, because Stata does not speak English, and has no way to know that Stagesquared is the square of Stage. So the first thing you need to do is rerun your model with the correct use of factor-variable notation. (Read -help fvvarlist- in its entirety.)
    Code:
    svy:mlogit undernutrition c.Stage##c.Stage  Childsex i.sbi3 i.pbi5 i.Wealthstatus i.sizeatbirth ///
    Motherheight Motherweight i.Maternaleducation i.Ethnicity Agesbi
    Now -margins- will recognize this as a quadratic model and make the corresponding calculations.

    2. You run -margins- (which, as already noted, will not correctly capture the quadratic model of Stage effects until you change the -mlogit- command as suggested), but then you don't use the results. You go on to just use bare -predict- for graphing. Why?

    3. Next, you have separately specified each level of the outcome variable in your multiple -margins- command. If you are using the current version of Stata (and, if memory serves, also in version 14), you would be better off with just a single margins command covering all of the outcome variables simultaneously:
    Code:
    margins, at(Stage = (-1.40 (0.35) 1.75))
    Then you can graph the results by immediately running
    Code:
    marginsplot
    You will see the parabolic curves you are probably expecting. Note that -marginsplot- accepts nearly all of the options available with -graph twoway-, so you can customize the appearance of the graph to your taste.

    Next, from your -graph- commands it appears that you also want to look at this behavior disaggregated by levels of sbi3. The easy way to do that is:

    Code:
    margins sbi3, at(Stage = (-1.40 (0.35) 1.75)) 
    marginsplot
    So, if I have correctly guessed what you want, these solutions should give you that.

    Comment


    • #3
      Thank you Clyde and apologies for my late response. I will try following your suggestions. My interest is in graphing the predicted probabilities to display the interaction effects between age and the sbi variable. Which is shown as Agesbi. This is a variable that I obtained by multiplying Stage and sbi.

      Comment


      • #4
        OK. If Agesbi is supposed to be an interaction between Stage and sbi, then you need to rewrite the regression so that it is properly specified and so that -margins- will recognize it:

        Code:
        svy:mlogit undernutrition c.Stage##c.Stage##i.sbi3 Childsex  i.pbi5 i.Wealthstatus i.sizeatbirth ///
        Motherheight Motherweight i.Maternaleducation i.Ethnicity
        
        margins sbi3, at(Stage = (-1.40 (0.35) 1.75)) 
        marginsplot
        


        It is critical that you use factor-variable notation as shown for this to come out correct. Moreover, it is an invalid model specification to have an interaction of sbi3 with Stage but not with Stage2, when Stage2 is also in the model. The code I show here incorporates these corrections.


        Comment

        Working...
        X