Announcement

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

  • Plot logistic regression with moderator and two lines for one binary variable

    Hi everyone,

    I hope you can help me with that. I have the following variables:
    gender, binary
    country, binary
    success, binary

    I am trying to plot the logit regression with interaction effect:
    Code:
     logit success i.country##i.gender
    I would like to have a graph with x axis = gender, y axis success and then two lines (one for each country (binary)).
    I could not find a way to plot this. I am always getting only one line without any country aspects.

    Thanks for your help!

    Best, Manuel
    Last edited by Manuel Grimeisen; 23 Nov 2019, 04:55.

  • #2
    Originally posted by Manuel Grimeisen View Post
    I would like to have a graph with x axis = gender, y axis success and then two lines (one for each country (binary)).
    Try this.
    Code:
    version 16.0
    
    clear *
    
    set seed `=strreverse("1526058")'
    quietly set obs 200
    
    generate byte gender = mod(_n, 2)
    generate byte country = _n > _N /2
    
    generate byte success = runiform() < 0.5
    
    logit success i.country##i.gender, nolog
    
    *
    * Begin here
    *
    margins country#gender
    marginsplot , xdimension(gender)
    
    exit

    Comment


    • #3
      Hi Joseph,

      thank you very much for your replay!
      To be honest, I do not really understand what you did in the first line of codes and if I include them, the result of the graph looks wrong in regard to my findings.
      But if I start here, the graph looks realistic.:
      Code:
      logit success i.country##i.gender, nolog
      margins country#gender
      marginsplot , xdimension(gender)
      I just want to make sure I am not missing anything important in the first line of your code. So can I just proceed with the later lines of code?

      Thanks for your help!
      Best,

      Manuel

      Comment


      • #4
        What happened in the first seven lines is that Joseph made some example data at random. Normally you should provide us with example data, that way the example corresponds with your problem. You can do so with dataex for that. You failed to do so, which means Joseph had two options: either make up some random data or ask you to provide the data. The latter would slow down the process of giving your advise, but you would get an example that fits your problem, the former would speed the process, but giving you an example that does not fit your problem. Joseph chose to speed up the process. You could have read this all before posting your question in the FAQ (in the black bar at the top of the page). This is probably a good idea to do before posting the next question.

        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Hi Maarten,

          thanks for your detailed description! Will do so before my next post.
          Best, Manuel

          Comment

          Working...
          X