Announcement

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

  • Forest plots - making subheadings bold

    Hi all,

    I'm just having some issues with some minor formatting things with a forest plot. I am trying to make the subheadings along the top aswell as, importantly, the subgroups ("Patella, trochlea" etc) bold. Initially I used the following code:


    clear
    . input str12(study year biomech time region stat) float(e n p)
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.089 30 0.636
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.549 30 0.002
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.052 30 0.783
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.493 30 0.006
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.1 30 0.598
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.485 30 0.007
    "Liao" "2023" "PFJ contact force" "6 months" "Trochlea" "r" -0.47 49 0.025
    "Liao" "2023" "PFJ contact force" "6 months" "Patella" "r" -0.49 49 0.021
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.5368 32 0.0015
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.165 32 0.367
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.4408 32 0.0116
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.063 30 0.752
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.47 30 0.009
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.061 30 0.747
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.461 30 0.1
    "Williams" "2023" "KFM" "3 months" "Patella" "r" 0.032 30 0.866
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.382 30 0.037
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.043 26 0.385
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.031 26 0.881
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.24 70 0.051
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.18 70 0.054
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.13 70 0.494
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.48 70 0.38
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.05 70 0.731
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.18 70 0.785
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.272 26 0.221
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.107 26 0.636
    end

    label variable study "Author"
    label variable year "Year"
    label variable biomech "Biomech"
    label variable time "Time"
    label variable region "Region"
    label variable stat "Stat"
    label variable n "Sample size"
    label variable p "p-value"
    format p %05.3f
    format study time biomech %-12s

    gen SE = sqrt((1 - e^2) / (n - 2))
    metan e SE, effect("Correlation") labtitle("Author") lcols(study year biomech time region stat) rcols(n p) nooverall nowt astext(60) keepall by(region) ///
    xlabel(-0.4 "Deterioration" 0 "No Change" 0.4 "Improvement")
    To produce the following plot:


    But then I came across two really useful threads:
    https://www.statalist.org/forums/for...de-using-metan
    https://www.statalist.org/forums/for...n-forest-plots


    So I have been trying to do this using admetan instead, but I am finding the code I have so far doesn't work. Giving me the error "too few quotes" and then "file myforest.dta already exists". See below the code I have so far:
    clear
    . input str12(study year biomech time region stat) float(e n p)
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.089 30 0.636
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.549 30 0.002
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.052 30 0.783
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.493 30 0.006
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.1 30 0.598
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.485 30 0.007
    "Liao" "2023" "PFJ contact force" "6 months" "Trochlea" "r" -0.47 49 0.025
    "Liao" "2023" "PFJ contact force" "6 months" "Patella" "r" -0.49 49 0.021
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.5368 32 0.0015
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.165 32 0.367
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.4408 32 0.0116
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.063 30 0.752
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.47 30 0.009
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.061 30 0.747
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.461 30 0.1
    "Williams" "2023" "KFM" "3 months" "Patella" "r" 0.032 30 0.866
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.382 30 0.037
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.043 26 0.385
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.031 26 0.881
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.24 70 0.051
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.18 70 0.054
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.13 70 0.494
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.48 70 0.38
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.05 70 0.731
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.18 70 0.785
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.272 26 0.221
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.107 26 0.636
    end

    label variable study "Author"
    label variable year "Year"
    label variable biomech "Biomech"
    label variable time "Time"
    label variable region "Region"
    label variable stat "Stat"
    label variable n "Sample size"
    label variable p "p-value"
    format p %05.3f
    format study time biomech %-12s

    // 1. adapt your data
    gen loge = ln((1 + e) / (1 - e))
    gen SE = sqrt((1 - e^2) / (n - 2))
    // 2. run the meta-analysis with "admetan"
    admetan loge SE, effect("Correlation") lcols(study year biomech time region stat) rcols(n p) nooverall nowt saving(myforest) by(region) nograph
    // 3. Load and edit the data
    use myforest, clear
    // 4. Edit labels using SCML
    label var _LABELS `"`"{bf:Author}"' `"{bf:Year}"' `"{bf:Biomech}"' `"{bf:Time}"' `"{bf:Region}"' `"{bf:Stat}"'"
    replace _LABELS = `"{bf:"' + _LABELS + `"}"' if _USE==0

    label var n `"`"{bf:Sample size}"'"
    label var p `"`"{bf:p-value}"'"
    label var _EFFECT `"{bf:Correlation}"' // Assuming you want to label the effect as correlation
    // 5. generate the forest plot
    forestplot, useopts nostats nowt rcols(_EFFECT _WT)

    Apologies as this is a lot of information, but thanks so much for reading all of this! Any help is most most welcome. Thank you!

    Best wishes,
    Matt


  • #2
    Dear Matt,
    Unfortunately, I cannot see your embedded image of the forest plot. Nevertheless, does the code below give you what you want?
    Note that admetan is superseded by metan, and it is no longer supported.
    Best wishes,
    David.


    Code:
    clear
    . input str12(study year biomech time region stat) float(e n p)
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.089 30 0.636
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.549 30 0.002
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.052 30 0.783
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.493 30 0.006
    "Williams" "2023" "PFJ contact force" "3 months" "Patella" "r" -0.1 30 0.598
    "Williams" "2023" "PFJ contact force" "3 months" "Trochlea" "r" -0.485 30 0.007
    "Liao" "2023" "PFJ contact force" "6 months" "Trochlea" "r" -0.47 49 0.025
    "Liao" "2023" "PFJ contact force" "6 months" "Patella" "r" -0.49 49 0.021
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.5368 32 0.0015
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.165 32 0.367
    "Schache" "2023" "PFJ contact force" "1 year" "Neither" "r" -0.4408 32 0.0116
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.063 30 0.752
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.47 30 0.009
    "Williams" "2023" "KFM" "3 months" "Patella" "r" -0.061 30 0.747
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.461 30 0.1
    "Williams" "2023" "KFM" "3 months" "Patella" "r" 0.032 30 0.866
    "Williams" "2023" "KFM" "3 months" "Trochlea" "r" -0.382 30 0.037
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.043 26 0.385
    "Capin" "2019" "KFM" "3 months" "Trochlea" "r" -0.031 26 0.881
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.24 70 0.051
    "Hall" "2015" "KFM" "3 months" "Patella" "Regression coefficient" -0.18 70 0.054
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.13 70 0.494
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.48 70 0.38
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.05 70 0.731
    "Hall" "2015" "KAM" "3 months" "Patella" "Regression coefficient" 0.18 70 0.785
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.272 26 0.221
    "Capin" "2019" "Quadriceps muscle forces" "3 months" "Trochlea" "r" -0.107 26 0.636
    end
    
    label variable year "{bf:Year}"
    label variable biomech "{bf:Biomech}"
    label variable time "{bf:Time}"
    label variable region "{bf:Region}"
    label variable stat "{bf:Stat}"
    label variable n "{bf:Sample} {bf:size}"
    label variable p "{bf:p-value}"
    format p %05.3f
    format study time biomech %-12s
    
    gen SE = sqrt((1 - e^2) / (n - 2))
    metan e SE, labtitle("{bf:Author}") lcols(study year biomech time region stat) rcols(n p) nooverall nowt keepall by(region) nograph clear
    
    replace _LABELS = `"{bf:"' + _LABELS + `"}"' if _USE==0
    label variable _EFFECT `"{bf:Correlation} {bf:(95% CI)}"'
    forestplot, useopts nostats nowt rcols(_EFFECT n p) astext(60) xlabel(-0.4 "Deterioration" 0 "No Change" 0.4 "Improvement")

    Comment

    Working...
    X