Announcement

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

  • Merging three (or more) marginsplots

    Dear Statalist,
    I would like to merge three or more marginsplots in just one graph but I do not kwow how to do that. I have this example codes to merge two graphs but i do not know how to merge a possible third marginsplot, what should I add in order to obtain three graphs altogether?
    Thank you so much


    sysuse auto, clear

    egen zweight=std(weight)
    egen zlength=std(length)
    regress mpg zweight zlength
    margins, at(zweight=(-3(.25)3)) saving(margins1, replace)
    marginsplot, recast(line) noci name(g1, replace)

    margins, at(zlength=(-3(.25)3)) saving(margins2, replace)
    marginsplot, recast(line) noci name(g2, replace)

    use _at _margin using margins1, clear
    rename _margin weight
    merge 1:1 _n using margins2
    rename _margin length
    keep _at weight length

    graph twoway (line weight _at) ///
    (line length _at)
    Last edited by Luke Brown; 31 May 2018, 07:32.

  • #2
    Hi Luke,

    Try this code and see if it creates the type of plot you are looking for...

    Code:
    ssc install coefplot
    
    sysuse auto, clear
    
    egen zweight=std(weight)
    egen zlength=std(length)
    egen zturn=std(turn)
    
    regress mpg zweight zlength zturn
    margins , at(zweight=(-3(.25)3)) post
    est store g1
    
    regress mpg zweight zlength zturn
    margins , at(zlength=(-3(.25)3)) post
    est store g2
    
    regress mpg zweight zlength zturn
    margins , at(zturn=(-3(.25)3)) post
    est store g3
    
    coefplot g1 g2 g3, at noci connect(l)
    You can further customize the graph with additional arguments passed to -coefplot-
    Last edited by Matt Warkentin; 31 May 2018, 19:09.

    Comment

    Working...
    X