Announcement

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

  • Italic fonts for Stata's meta forestplot

    Dear Statalisters,

    Does anyone have an idea how to make this red underlined texts 'italic' (see attached photo). It is produced using Stata's (v.16.1) 'meta forestplot' command for a meta-analysis purpose. I have tried in vain figuring out where Stata is storing this information.
    Thanks,

    Click image for larger version

Name:	test.png
Views:	1
Size:	467.3 KB
ID:	1585729
    Roman

  • #2
    I try a brute force strategy: To get italics the graph editor could be used, but to automate this one need the original strings to be changed, and those can be read from the gph file. Below, mata is used to read a gph, keep the relevant strings, and make Stata gr_edit commands adding italics, like:
    Code:
    gr_edit .plotregion1.column1.bhom_stats[1].text.Arrpush {it:Test of group differences: Q{sub:b}(2) =  1.86, p =  0.39}
    You may have to adapt this, at a minimum setting type = "bhom"

    Make a forest plot
    Code:
    ********************************************************************************
    clear all
    gr drop _all
    use https://www.stata-press.com/data/r16/bcgset
    meta forestplot, subgroup(alloc) eform
    graph save a_graph_fp, replace
    gr drop _all
    ********************************************************************************
    Display the graph to be edited with graph edit
    Code:
    ********************************************************************************
    
    gr use a_graph_fp 
    
    ********************************************************************************
    Use the full filename of the forest plot gph as argument to the mata cat() function
    Code:
    ********************************************************************************
    mata:
     
    type = "hom" /* "bhom" */
    
    pat = ".create_" + type + "stats"
    
    gph = cat("a_graph_fp.gph") /* read gph to be parsed */
    
    stats = ustrregexrf(
                    select(gph, strpos(gph, pat):> 0),
                    "^.*?\s",
                    "" )
                    
    for ( i=1; i<=length(stats); i++ ) { 
        
        hs = tokens(stats[i])[1::4]
        hs[3] = sprintf("%5.2f", strtoreal(hs[3]))  
        hs[4] = sprintf("%5.2f", strtoreal(hs[4]))  
        
        hs = hs[1] + " Q(" + hs[2] + ") = " + hs[3] + ", p = "  + hs[4]
        
        if ( type=="bhom" ) {
        
            hs = subinstr(hs, "Q", "Q{sub:b}", 1)
        }
        
        hs = "{it:" + hs + "}"
        
        ed0 = "gr_edit .plotregion1.column1." + type + "_stats[" + strofreal(i) + "].text"
        ed1 =  ed0 + "= {}" 
        ed2 =  ed0 + ".Arrpush " + hs 
        
        stata(ed1)
        stata(ed2)
    }
    
    end
    ********************************************************************************
    The following gr_edit commands are defined by mata, and run by Stata, for arguments "hom" and "bhom"
    Code:
    /*
    
    ed2:  
    
    * hom
    
      gr_edit .plotregion1.column1.hom_stats[1].text.Arrpush {it:Test of {&theta}{sub:i} = {&theta}{sub:j}: Q(1) =  5.56, p =  0.02}
      gr_edit .plotregion1.column1.hom_stats[2].text.Arrpush {it:Test of {&theta}{sub:i} = {&theta}{sub:j}: Q(6) = 110.21, p =  0.00}
      gr_edit .plotregion1.column1.hom_stats[3].text.Arrpush {it:Test of {&theta}{sub:i} = {&theta}{sub:j}: Q(3) = 16.59, p =  0.00}
      gr_edit .plotregion1.column1.hom_stats[4].text.Arrpush {it:Test of {&theta}{sub:i} = {&theta}{sub:j}: Q(12) = 152.23, p =  0.00}
    
    * bhom
    
      gr_edit .plotregion1.column1.bhom_stats[1].text.Arrpush {it:Test of group differences: Q{sub:b}(2) =  1.86, p =  0.39}
      
    */

    Comment


    • #3
      Thank you Bjarte for the solution but seriously!! I mean just to get the fonts italic it does seem to be a lot of work. I wish Stata kept these information editable like we do for others graphs without graph editor. It is a little bizarre that you can edit one side of the graph and cannot edit the other side.
      Roman

      Comment

      Working...
      X