Hello,
I'm trying to make something like a forest plot, with markers weighted by number of observations. I also want my categories in different colours. I can't seem to combine the two: either I can specify different plots with twoway and give them different colours, but each plot is apparently weighted individually so the marker sizes are the same; or I can specify them as one plot, which allows me to use weights, but not different colours.
Here are the two things I'd like to combine:

My dataset has one observation per BMI category, with an estimate and a confidence interval for mean change per year.
This is my code at the moment, with the weighted/uncoloured version commented out:
I explored adding my three data points as different variables into the same scatter plot, but as you can only specify the x variable once, I could only orient my plot vertically. I looked for a way to transpose the x and y axis, but there doesn't seem to be one.
Any advice?
I'm trying to make something like a forest plot, with markers weighted by number of observations. I also want my categories in different colours. I can't seem to combine the two: either I can specify different plots with twoway and give them different colours, but each plot is apparently weighted individually so the marker sizes are the same; or I can specify them as one plot, which allows me to use weights, but not different colours.
Here are the two things I'd like to combine:
My dataset has one observation per BMI category, with an estimate and a confidence interval for mean change per year.
This is my code at the moment, with the weighted/uncoloured version commented out:
Code:
#delimit ;
twoway /// CIs
(rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 1
, horizontal color($c1 ))
(rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 2
, horizontal color($c2 ))
(rspike ann_lci_`rfvar' ann_uci_`rfvar' bmicat if bmicat == 3
, horizontal color($c3 ))
/// markers (colour)
(scatter bmicat ann_est_`rfvar' if bmicat == 1 [aweight=respbmi]
, color($c1 ) msymbol(square) msize(medlarge))
(scatter bmicat ann_est_`rfvar' if bmicat == 2 [aweight=respbmi]
, color($c2 ) msymbol(square) msize(medlarge))
(scatter bmicat ann_est_`rfvar' if bmicat == 3 [aweight=respbmi]
, color($c3 ) msymbol(square) msize(medlarge))
/* /// markers (weights)
(scatter bmicat ann_est_`rfvar' [fweight = resp]
, msymbol(square) msize(medlarge) mcolor(gs2))
*/
/// options
, xtitle("Annual change") xline(0) xmtick(none)
ytitle("") yscale(range(-1 5) lcolor(none) reverse) ymtick(none)
ylabel(1 "< 25" 2 "25-29" 3 "30+"
, angle(horizontal) notick nogrid)
title("Annual change in `rfname' by BMI category")
legend(off) scheme(s1mono) plotregion(lcolor(none))
name(`rfvar'_annual_c2, replace)
;
#delimit cr
I explored adding my three data points as different variables into the same scatter plot, but as you can only specify the x variable once, I could only orient my plot vertically. I looked for a way to transpose the x and y axis, but there doesn't seem to be one.
Any advice?

Comment