Announcement

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

  • Custom subgroup means in meta forest

    Hello all, I am trying to include custom diamonds for each subgroup in my meta analysis that uses the option subgroup(). I know of the customoverall() option but cannot find one for each group.
    Any ideas on how I could achieve this using the meta suite?

    Thank you

  • #2
    Hi Jean-Michel,

    This can certainly be achieved (as can most things! ) with user-written metan. I'm not sure whether you want custom values, or a custom presentation style, so in the example below I use both.

    I will use Example 12 of the meta forestplot documentation PDF ("Adding custom columns and overall effect sizes"), in which repeated calls to customoverall() are used to show "custom" diamonds representing predicted (marginal) effects from a meta-regression. The same dataset (a meta-analysis of BCG vaccine efficacy for TB) was used in the 2008 Stata Journal article on metan (although note that metan itself has evolved significantly since then -- I really need to submit an updated article to Stata Journal when I have time!). To run this code you will need the latest version of metan (version 4.08.1 12jul2024) available from the SSC archive.

    I hope this is useful!
    BW,
    David.


    Code:
    use "https://www.stata-press.com/data/r18/bcgset", clear
    
    * Form study subgroups based on latitude
    recode latitude (min/23.5 = 1 "Tropical, < 23.5 latitude") (23.5/40 = 2 "23.5-40 latitude") (40/max = 3 "Northern, > 40 latitude"), gen(lat_cat)
    assert !missing(latitude)
    label var latitude "Latitude"
    assert !missing(lat_cat)
    label var lat_cat "Latitude region"
    
    * Perform the meta-regression (on latitude as a continuous covariate) and save the desired marginal results in a table (see text of Example 18 for further details)
    metareg _meta_es latitude_c, wsse(_meta_se) z
    margins, at(latitude_c = (-18.5 -5.5 16.5))
    mat marginstable = r(table)
    
    * Now here is the tricky part. We run the meta-analysis, but instead of immediately displaying the forest plot
    * we instead replace the data in memory with a "forestplot results set", into which we insert our custom values
    preserve
    metan _meta_es _meta_se, lcols(studylbl latitude) by(lat_cat) re(reml) rr nograph clear
    forvalues i=1/3 {
    replace _ES = marginstable["b",`i'] if _USE==3 & _BY==`i'
    replace _LCI = marginstable["ll",`i'] if _USE==3 & _BY==`i'
    replace _UCI = marginstable["ul",`i'] if _USE==3 & _BY==`i'
    }
    replace _WT = . if _USE==3
    replace _LABELS = "Predicted effect at latitude = 15" if _USE==3 & _BY==1
    replace _LABELS = "Predicted effect at latitude = 28" if _USE==3 & _BY==2
    replace _LABELS = "Predicted effect at latitude = 50" if _USE==3 & _BY==3
    replace _LABELS = "{bf:" + _LABELS + "}" if inlist(_USE, 3, 5)
    format %-1s _LABELS
    
    * Finally, we display the forest plot. I have also demonstrated how you can change the look of the diamonds.
    forestplot, useopts xlabel(.125 .25 .5 1 2 4) astext(60) plotid(_BY) diam1opts(lcolor(red)) diam2opts(lcolor(green) fcolor(green%50)) diam3opts(lcolor(blue) fcolor(blue))
    restore
    Click image for larger version

Name:	Jean-Michel Galarneau.png
Views:	1
Size:	134.0 KB
ID:	1766160

    Comment


    • #3
      David, thank you very much for this. I had just about given up.

      That is an excellent example.

      Comment


      • #4
        Extremely useful, David! Thank you!

        Comment

        Working...
        X