Announcement

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

  • Simple Slope Test for Negative Binomial Regression with Moderating Effect

    Dear All,

    I'm now conducting a negative binomial regression model for count dependent variable y, independent variable x1, x2, moderating variable m and control variable c1, c2. I want to make a simple slope test and draw a plot to see the moderating effect of m on the relationship between x1 and y. Is the code for the simple slope test same as the code for linear regression model? Like:

    margins, dydx(x1) at(m=(-1,1))

    And then use marginsplot to see the simple slope plot?

    However, I'm confused about the result. If "a" is the coefficient for x1, "c" in the coefficient for the interaction term x1*m, then when m = -1, the simple slope should be a+c*(-1) = a-c. But why the simple slope calculated from the above code does not equal to a-c? Instead, the result from margins, eydx(x1) at(m=(-1,1)) is the same as a-c when m = -1.

    How should I see the simple slope test and the plot?

    Thanks in advance for any advice and help!!

    Best,
    Kelly

  • #2
    you can think of nbreg as being akin to a natural log transformation of the DV during estimation, so eydx will give you the coefficient.

    Code:
    clear all
    
    sysuse auto, clear
    
    g lrep78 = ln(rep78)
    
    reg rep78 foreign turn 
    margins, dydx(turn)
    margins, eydx(turn)
    
    reg lrep78 foreign turn 
    margins, dydx(turn)
    
    nbreg rep78 foreign turn 
    margins, dydx(turn)
    margins, eydx(turn)

    Comment


    • #3
      Originally posted by George Ford View Post
      you can think of nbreg as being akin to a natural log transformation of the DV during estimation, so eydx will give you the coefficient.

      Code:
      clear all
      
      sysuse auto, clear
      
      g lrep78 = ln(rep78)
      
      reg rep78 foreign turn
      margins, dydx(turn)
      margins, eydx(turn)
      
      reg lrep78 foreign turn
      margins, dydx(turn)
      
      nbreg rep78 foreign turn
      margins, dydx(turn)
      margins, eydx(turn)
      Thank you so much for your reply.

      However, I still got one more question. If I use the following code to see the moderating effect of length on the relationship between mpg and price:

      clear
      sysuse auto,clear
      nbreg price c.length##c.mpg
      est sto regression
      foreach v of var length mpg {
      su `v' if e(sample)
      local low_`v'=r(mean)-r(sd)
      local high_`v'=r(mean)+r(sd)
      }
      est restore regression
      margins,eydx(mpg) at(length = (`low_length' `high_length'))
      margins, expression((predict(xb))) at(mpg = (`low_mpg' `high_mpg') length = (`low_length' `high_length'))
      marginsplot

      Click image for larger version

Name:	simple slop plot.png
Views:	1
Size:	103.1 KB
ID:	1748422



      Y-axis of the final plot shows the value of ln(price), which I attached it. However, I have read some papers using negative binomial regression with moderating effect, their simple slope equals a+cm, which I think they also used margins, eydx. But Y-axis of their plot of simple slope test actually shows the original value of the dependent variable, but not ln(DV). So is there any way that I can change the Y-axis from ln(DV) to DV through using marginsplot?

      Thanks for help in advance.
      Last edited by Kelly Holmes; 31 Mar 2024, 22:21.

      Comment


      • #4
        see if this gets you what you want.

        Code:
        clear
        sysuse auto,clear
        nbreg price c.length##c.mpg
        est sto regression
        foreach v of var length mpg {
        su `v' if e(sample)
        local low_`v'=r(mean)-r(sd)
        local high_`v'=r(mean)+r(sd)
        }
        est restore regression
        margins,eydx(mpg) at(length = (`low_length' `high_length'))
        margins, /*expression((predict(xb)))*/ at(mpg = (`low_mpg' `high_mpg') length = (`low_length' `high_length'))
        marginsplot

        Comment


        • #5
          Originally posted by George Ford View Post
          see if this gets you what you want.

          Code:
          clear
          sysuse auto,clear
          nbreg price c.length##c.mpg
          est sto regression
          foreach v of var length mpg {
          su `v' if e(sample)
          local low_`v'=r(mean)-r(sd)
          local high_`v'=r(mean)+r(sd)
          }
          est restore regression
          margins,eydx(mpg) at(length = (`low_length' `high_length'))
          margins, /*expression((predict(xb)))*/ at(mpg = (`low_mpg' `high_mpg') length = (`low_length' `high_length'))
          marginsplot
          Thank you for the reply. However, it returned:

          margins, /*expression((predict(xb)))*/ at(mpg = (`low_mpg' `high_mpg') length = (`low_length' `high_length'))
          option / not allowed
          r(198);

          But I guess "/*expression((predict(xb)))*/" is something like a comment? So is the above code the same as:

          margins, at(mpg = (`low_mpg' `high_mpg') length = (`low_length' `high_length'))
          marginsplot

          I run this code and then I can get the result I want.

          Thank you for your help again.

          Comment


          • #6
            Yes. /* xxx */ is a comment. but nothing can touch the /

            Comment


            • #7
              Originally posted by George Ford View Post
              Yes. /* xxx */ is a comment. but nothing can touch the /
              I understand. Thank you!

              Comment

              Working...
              X