Announcement

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

  • Error with user written program grc1leg. It produces 3 legends instead of 1 legend for combined 2 graphs!

    Hi at all.

    I try to use grc1leg with margins plot.


    I have the strange error, that I get 3 in stead of 1 legend.

    I tried to create an example, that closely follows my data, but I cannot manage with the auto dataset. But the idea is:

    Code:
    gen displ = 0 if displacement < = 100
    
    replace displ = 1 if displacement > = 100
    
    replace displ = 2 if displacement > = 200
    
    label define displ 0 "Moederat" 1 "Medium" 2"Really high"
    
    label values displ displ
    
    gen expensive = 0 if price > 10000
    
    replace expensive = 1 if price >= 10000
    
    
    quietly: logit foreign c.headroom##c.weight##(1.expensive ib0.displ), ///
    
           noomitted noempty
    
      graph drop _all
    
    quietly: margins, at(headroom=(2(0.5)4) weight=(2500) displ=(0 1 2)) over(expensive) 
    
    marginsplot, by(expensive) scheme(s1color) name(m1) nodraw title("weight = 2.5") subtitle(, fcolor(white)) ///
    
     legend(cols(1) size(vsmall))  recast(line)
    
    quietly: margins,  at(headroom =(2(0.5)4) weight=(3500)  displ=(0 1 2)) over(expensive) 
    
    marginsplot, by(expensive) scheme(s1color) name(m2) nodraw title("weight = 3.5")subtitle(, fcolor(white)) recast(line)
    
    
    
    grc1leg m1 m2, name(m3, replace) span legendfrom(m1)    ycommon      
    
    graph display gme
    The resulting error is in the attached picture.
    Click image for larger version

Name:	image.png
Views:	1
Size:	192.7 KB
ID:	1365111


    Any suggestions how to overcome the problem are highly appreciated. Thanks!

  • #2
    Its the by dimension causing the problem. I would just plot them separately in a loop and combine if `grc1leg' is needed. Try this:

    Code:
    gr drop _all
    loc k=1
    foreach j of numlist 2500 3500 {
    
    forval i=0/1 {
        loc t : lab (expensive) `i'
        margins if expensive==`i',  at(headroom =(2(0.5)4) weight=(`j')  displ=(0 1 2))
        marginsplot,scheme(s1color) legend(size(small) col(1)) ///
         nodraw title("`t': weight = `j'") subtitle(, fcolor(white)) ///
         recast(line)
    gr copy m`k', replace
    loc ++k
    }
    }
    grc1leg m1 m2 m3 m4, scheme(s1color)
    Roman

    Comment


    • #3
      Thanks for the answer. That works reasonably well for me, thanks! Great!

      Comment

      Working...
      X