Announcement

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

  • binary by continuous interaction plot regression

    Hi all,

    I have an interaction term in a regression model and I need to plot it. It is binary by continuous (x: binary, z: continuous). However, I do not know how I can plot model one above and below the standard deviation of the continuous variable.
    I would appreciate it if you could help me on this matter. Below is the code that I used. But I got the error: invalid num list



    regress y x z x#c.z


    return list
    global effa = round(r(mean) + r(sd),0.1)
    global eff = round(r(mean),0.1)
    global effb = round(r(mean) - r(sd),0.1)

    margins, at(x = (0 1) z = ($effa, $eff $effb))
    marginsplot

    I also tried

    margins. x , at (z = ($effa, $eff $effb))


    Thank you!
    Last edited by Roxanna Sh; 30 Jun 2023, 08:09.

  • #2
    I am really stuck. Does anyone know how I can plot +-1sd above the average of z, when the other variable is binary. I also try this
    sum x local sd = r(sd) local mean = r(mean) margins x , at(z =(`=`mean' - `sd'' `=`mean' + `sd'')) marginsplot But it gave me numlist has too few elements and this one sum x t1=r(mean)-r(sd) t2=r(mean)+r(sd) margins x , at(z =(`t1' `t2')) gabe invalid numlist error Thanks

    Comment


    • #3
      Hello Roxanna Sh. Here is an example that may help.

      Code:
      /*
      Example from this UCLA page:
      https://stats.oarc.ucla.edu/stata/faq/how-can-i-understand-a-categorical-by-continuous-interaction-stata-12/
      */
      
      use https://stats.idre.ucla.edu/stat/data/hsbdemo, clear
      
      quietly summarize socst if!missing(write, female)
      * Let low = mean - 1SD
      local low = round(r(mean) - r(sd),0.1)
      * Let med = mean
      local med = round(r(mean),0.1)
      * Let high = mean + 1SD
      local high = round(r(mean) + r(sd),0.1)
      
      regress write female##c.socst
      
      margins female, at(socst=(`low' `med' `high')) vsquish
      marginsplot, title("Write x Sex at selected values of Social Studies") ///
      xlab(`low' "Mean-SD" `med' "Mean" `high' "Mean+SD") name(fig1, replace)
      
      * Plot the F-M difference at the 3 selected values of socst
      margins, dydx(female) at(socst=(`low' `med' `high')) vsquish
      marginsplot, title("F-M difference at selected values of Social Studies") ///
      xlab(`low' "Mean-SD" `med' "Mean" `high' "Mean+SD") name(fig2, replace)
      HTH.
      --
      Bruce Weaver
      Email: [email protected]
      Version: Stata/MP 18.5 (Windows)

      Comment


      • #4
        Thanks a lot Bruce Weaver
        When I ran your example in Stata, I got "invalid numlist has too few elements error". I also get the same error when I ran my model

        Comment


        • #5
          You need to run the example all in one go, not line by line
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            It worked. Thank you!

            Comment

            Working...
            X