Announcement

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

  • Sorting coefficients in -coefplot-

    Hello all:

    I was trying to do a forest plot of HR and 95%CI and trying to sort by HR in the plot. But I am struggling. Was wondering if it had to do with me assigning those spaced column names. Tried xsvmat and mkmat etc but I am not getting ahead. Would appreciate any input. have attached a sample of my code with the stan3 dataset.

    Code:
    webuse stan3, clear
    gen byte age40 = age>40
    stset stime, failure(died)
    
    *Direct forest plot of univariable Cox models without resorting to R for the final work.
    local list age40 transplant wait surgery
    local n: word count `list'
    local names ""Age>40 yrs" "Transplant" "Wait Time" "Surgery""
    matrix drop _all
            matrix C = J(3,`n',.)
            matrix rownames C = HR ll95 ul95
            matrix colnames C = `names'
            local i 0
            foreach v of var `list' {
                local ++ i
                stcox `v' 
                matrix C[1,`i'] = r(table)[1,1] \ r(table)[5,1] \ r(table)[6,1]
            }
            matrix list C
    
            coefplot ///
            (matrix(C), ci((2 3)) msymbol(S) ciopts(recast(rcap))), ///
                xline(1, lwidth(small) lcolor(gray) lpattern(dash)) ///
                xlabel(,notick) ///
                ylabel(,notick) ///
                title("HR of uni-variable models as a forest plot", ///
                span size(*.9) linegap(1.5) margin(medium)) ///
                graphregion(margin(0 10 0 0)) ///
                caption(" " "testing it out to see if I can do HR, 95% CI here", justification(right) position(3))

  • #2
    Just figured it. Found the right option in help to add in the plot options without fiddling with the matrix structure.

    Code:
    sort(,descending)

    Comment

    Working...
    X