Announcement

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

  • how to examine the moderating effect and plot the figure when iv is categorical variable and moderator is continuous variable

    After the regression, how to plot the moderating effect of w on the relationship between x and y?
    Thanks a lot.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(w x) byte y
    .9993799844782558 0 1
    .9993799844782558 0 1
    .9993799844782558 0 1
    .9993799844782558 0 1
    .9993800038136472 0 1
    .9993084682257377 0 1
    .9993098803169057 0 1
    .9993107611094899 0 1
    .9993099831400718 0 1
                    1 0 0
                    1 0 0
                    1 1 0
    .9999726114453388 0 0
    .9999726114453388 0 0
    .9999726114453388 0 0
    .9999726114453388 0 0
    .9855912386347621 1 0
    .9855912386347621 1 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
     .990649675659052 0 1
     .990649675659052 0 1
    .9915727371407879 0 1
    .9932881358941555 0 1
    .9949661026400637 0 1
    .9951749771087679 0 1
      .99638123264639 0 1
      .99638123264639 0 1
                    1 0 1
                    1 0 0
                    1 0 0
                    1 0 0
    .8917586616656455 0 0
    .8917586616656455 0 0
    .8917586616656455 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
    .9043012418332407 0 0
    .9314437976187135 0 0
    .9998485411232476 1 0
    .9998485409856721 1 1
    .9998485409856721 1 1
    .9998485409856721 1 1
    .9998485409856721 1 0
    .9998485414639602 1 1
    .9998485413310303 1 1
    .9998568055132432 1 1
    .9998568056760768 1 1
                    1 1 0
                    1 1 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 1
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 0
                    1 0 1
                    1 0 1
                    1 0 1
    .9966554453547722 1 1
    .9974360862520616 1 1
    .9978329357337956 1 1
    .9978320128844794 1 1
     .997831488995447 1 1
     .997831488995447 1 1
     .997831488995447 0 1
     .997831488995447 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 1
                    1 0 0
                    1 0 1
                    1 0 1
                    1 0 1
    end
    
    logit y i.x##c.w

  • #2
    Could anyone help me out? Thanks a lot!

    Comment


    • #3
      Originally posted by Fred Lee View Post
      After the regression, how to plot the moderating effect of w on the relationship between x and y?
      Maybe something like this?
      Code:
      version 15.1
      
      clear *
      
      input double w byte(x y)
      <dataset omitted for brevity>
      end
      
      replace w = round(w, 0.`=( strlen("99985681") - 1 ) * "0" + "1"')
      contract _all, freq(count)
      
      summarize w, meanonly
      local min = round(r(min), 0.1)
      local max = round(r(max), 0.1)
      
      logit y i.x##c.w [fweight=count], nolog
      
      quietly margins x, predict(xb) at(w = (`min' `max'))
      
      marginsplot , ///
          title("") noci ///
          plotopts(xlabel(`min' `max') ylabel( , angle(horizontal) nogrid) legend(off)) ///
          plot1opts(msymbol(circle) mcolor(black) mfcolor(white) lcolor(black)) ///
          plot2opts(msymbol(triangle) mcolor(black) mfcolor(white) lcolor(black) lpattern(dash))
      
      exit
      I omitted the confidence bars for the reason given in the regression table.

      Also, when you have log-odds coefficients and their standard errors in the tens and hundreds, you might want to step back and take a look at things again.

      Comment


      • #4
        Originally posted by Joseph Coveney View Post
        Maybe something like this?
        Code:
        version 15.1
        
        clear *
        
        input double w byte(x y)
        <dataset omitted for brevity>
        end
        
        replace w = round(w, 0.`=( strlen("99985681") - 1 ) * "0" + "1"')
        contract _all, freq(count)
        
        summarize w, meanonly
        local min = round(r(min), 0.1)
        local max = round(r(max), 0.1)
        
        logit y i.x##c.w [fweight=count], nolog
        
        quietly margins x, predict(xb) at(w = (`min' `max'))
        
        marginsplot , ///
        title("") noci ///
        plotopts(xlabel(`min' `max') ylabel( , angle(horizontal) nogrid) legend(off)) ///
        plot1opts(msymbol(circle) mcolor(black) mfcolor(white) lcolor(black)) ///
        plot2opts(msymbol(triangle) mcolor(black) mfcolor(white) lcolor(black) lpattern(dash))
        
        exit
        I omitted the confidence bars for the reason given in the regression table.

        Also, when you have log-odds coefficients and their standard errors in the tens and hundreds, you might want to step back and take a look at things again.
        Thanks for your help!
        Could you please explain more about the difference about the syntax:
        margins x, predict(xb) at(w = (`min' `max'))
        margins x, at(w = (`min' `max'))
        margins , at(x=(0 1) w = (`min' `max'))
        margins, dydx(x) at(w = (`min' `max'))
        Although the help file of margins is useful, I don't understand that thoroughly. Highly appreciate your help!

        Comment


        • #5
          can anyone explain more about the differences about such codes below?
          margins x, predict(xb) at(w = (`min' `max'))
          margins x, at(w = (`min' `max'))
          margins , at(x=(0 1) w = (`min' `max'))
          margins, dydx(x) at(w = (`min' `max'))

          Comment

          Working...
          X