title: Stata margins/marginsplot into R?
body: <p>I am trying to replicate a Stata marginsplot into <code>R</code>, but have not been able to do so, even after browsing StackExchange and trying to figure it out for a couple of weeks.</p>
  
  <p>Do you happen to know how can I recreate a plot created using marginsplot in <code>R</code>?</p>
  
  <p>First, I generated a reproducible dataset using the following <code>R</code> code:</p>
  
  <pre><code>set.seed(96)
  sampleData &lt;- data.frame(
      ID = 1:200,
      outcome = sample(1:7, 200, replace = T),
      scale = sample(1:7, 200, replace = T),
      dummy1 = sample(0:1, 200, replace = T),
      dummy2 = sample(0:1, 200, replace = T))
  write.dta(dataframe, "sampledata.dta")
  </code></pre>
  
  <p>Then, I read the data into <code>Stata</code> and run the following commands to get the attached graph:</p>
  
  <pre><code>   reg outcome dummy1##c.scale dummy2##c.scale
  
     margins dummy1 dummy2, at(scale=(1(1)7))
  
     marginsplot, recast(line) name(outcome, replace)
  </code></pre>
  
  <p>Essentially, when this code is run in Stata I get the graph that I am trying to replicate in R: </p>
  
  <p><a href="https://i.stack.imgur.com/t91Ok.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t91Ok.png" alt="enter image description here"></a></p>
  
  <p>Do you have any pointers that would help me replicate this graph?</p>