Announcement

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

  • Uneven length of x axis in graph combine

    Hi,

    I am trying to combine 3 coefplots using graph combine in Stata 16. I have coefficient labels on one plot but not on the others. When I combine, the x axis is shorter on the first graph with the coefficient labels so the other two graphs look wider. I'm wondering if there is a way to force the x axes to span the same physical width?

    My code is:

    Code:
    qui svy: mean diff_wt2 diff_ht2 diff_bmi2 if smpl2==1
    local mean_1 = e(b)[1,1]
    local mean_2 = e(b)[1,2]
    local mean_3 = e(b)[1,3]
    local yscale "on"
    forval x =1/3 {
        if `x'==1 local y="Weight"
        if `x'==2 local y="Height"
        if `x'==3 local y="BMI"
        local z1=`x'*3-2
        local z2=`x'*3-1
        local z3=`x'*3
        if `x'==1 local fxsize=100
        if inlist(`x',2,3) local fxsize=80
        if `x'==1 local ysize=5
        if inlist(`x',2,3) local ysize=4
        di "`z1' `z2' `z3'"
        coefplot (matrix(health_plots[,`z1']), ci((health_plots[,`z2'] health_plots[,`z3']))) , title("`y' SR-M") ///
            ylabel(,labsize(small)) ysize(`ysize') xsize(3) xlabel(-10(5)20, labsize(small)) ///
            graphregion(color(white) fcolor(white) lcolor(white) ilcolor(white) ifcolor(white)) ///
            xscale(range(-10(2)10)) msize(small) /*fxsize(`fxsize')*/  ///
            text(1 10 "Long term alcohol", size(small) just(left) place(east))  ///
            text(7 10 "Short term alcohol", size(small) just(left) place(east))  ///
            text(13 10 "RDI fruit/veg", size(small) just(left) place(east))  ///
            text(17 10 "Exercise", size(small) just(left) place(east))  ///
            text(20 10 "Physical activity", size(small) just(left) place(east))  ///
            text(23 10 "Smoker", size(small) just(left) place(east))  ///
            text(28 10 "SEIFA", size(small) just(left) place(east))  ///
            text(37 10 "K10", size(small) just(left) place(east))  ///
            xline(`mean_`x'') yscale(`yscale') ///
            ytitle("Health variable") /*nodraw*/ name("health_`x'", replace)
        local yscale "off"
    }
    
    graph combine health_1 health_2 health_3, altshrink ///
        graphregion(color(white) fcolor(white) lcolor(white) ilcolor(white) ifcolor(white)) title("Health variables") ///
        rows(1) xcommon ycommon name("health_vars_all", replace)
    Thank you.









  • #2
    Click image for larger version

Name:	health_vars_all.png
Views:	1
Size:	86.0 KB
ID:	1654182 My graph is attached.
    Last edited by Jane Fry; 13 Mar 2022, 23:16.

    Comment


    • #3
      You probably want to combine 1 with a combination of 2 and 3, maybe adding an extra margin to 1. But in general, you want to produce the graphs using the -by()- option, see https://journals.sagepub.com/doi/pdf...36867X20976341.

      Comment


      • #4
        Thank you Andrew. I'll try that.

        Comment

        Working...
        X