Announcement

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

  • Plotting regression coefficients

    Hi,

    In this previous post https://www.statalist.org/forums/for...egression-loop , I asked how to create a forest plot for regression coefficients and was successful. But I'd like to know how I can present values on the outside of the graph rather than inside it. I've tried several commands from the website, but they don't work for me.


    This an example of the data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 outcome float(coef se ci_l ci_u)
    "S" -1.4595655 .14353406  -1.741194 -1.1779372
    "M" -1.4105432   .167224 -1.7386538 -1.0824327
    "A"  1.2288225 .18672407   .8624509   1.595194
    "C"  1.0382018 .18100072   .6830601  1.3933436
    "B"  1.0915558 .19679554   .7054231  1.4776887
    "D" -1.0109191 .18807442 -1.3799403   -.641898
    end
    Then I have used this code:

    Code:
    *EXTRACT RESULTS TO MATRIX
     mkmat coef ci_l ci_u, mat(res) rownames(outcome)
    
    *GRAPH USING COEFPLOT FROM SSC
    *ssc install coefplot, replace
    set scheme s1color
    mat res= res'
    coefplot mat(res), ci((2 3)) xline(0) mlab(@b) mlabpos(1)
    And the result in attachment.

    So I'm looking for a graph that includes:
    1- values in a separate column next to the names of the outcomes
    2- Sort the graph's coefficient values ascendingly.
    3- I want the values' colors to be black.

    Attached Files

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 outcome float(coef se ci_l ci_u)
    "S" -1.4595655 .14353406  -1.741194 -1.1779372
    "M" -1.4105432   .167224 -1.7386538 -1.0824327
    "A"  1.2288225 .18672407   .8624509   1.595194
    "C"  1.0382018 .18100072   .6830601  1.3933436
    "B"  1.0915558 .19679554   .7054231  1.4776887
    "D" -1.0109191 .18807442 -1.3799403   -.641898
    end
    
    *EXTRACT RESULTS TO MATRIX
     mkmat coef ci_l ci_u, mat(res) rownames(outcome)
    
    *GRAPH USING COEFPLOT FROM SSC
    *ssc install coefplot, replace
    set scheme s1color
    mat res= res'
    gen xpos = -3
    
    coefplot mat(res), ci((2 3)) xline(0) mlabpos(1)  mlabel(string(@b,"%9.3f")) mlabcolor(none) sort ///
    addplot(scatter @at xpos, ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(3) mlabsize(small)) ///
        graphr(margin(r=10)) xlab(-2/2)
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.8 KB
ID:	1703877




    Comment


    • #3
      Andrew's suggestions are always amazing.

      Noor, have you tried -metan- or -meta-? In -meta- you can present the values for the effect sizes along with their 95% CIs.

      Comment


      • #4
        Originally posted by Andrew Musau View Post
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str14 outcome float(coef se ci_l ci_u)
        "S" -1.4595655 .14353406 -1.741194 -1.1779372
        "M" -1.4105432 .167224 -1.7386538 -1.0824327
        "A" 1.2288225 .18672407 .8624509 1.595194
        "C" 1.0382018 .18100072 .6830601 1.3933436
        "B" 1.0915558 .19679554 .7054231 1.4776887
        "D" -1.0109191 .18807442 -1.3799403 -.641898
        end
        
        *EXTRACT RESULTS TO MATRIX
        mkmat coef ci_l ci_u, mat(res) rownames(outcome)
        
        *GRAPH USING COEFPLOT FROM SSC
        *ssc install coefplot, replace
        set scheme s1color
        mat res= res'
        gen xpos = -3
        
        coefplot mat(res), ci((2 3)) xline(0) mlabpos(1) mlabel(string(@b,"%9.3f")) mlabcolor(none) sort ///
        addplot(scatter @at xpos, ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(3) mlabsize(small)) ///
        graphr(margin(r=10)) xlab(-2/2)
        Res.: [ATTACH=CONFIG]n1703877[/ATTACH]



        Thank you very much, Mr. Andrew. Your efforts are much appreciated.
        I have only one comment regarding labeling. I was looking for a way to get labels outside of the graph. I used the help coefplot in Stata, but I didn't find a way to do that.

        Comment


        • #5
          Originally posted by Tiago Pereira View Post
          Andrew's suggestions are always amazing.

          Noor, have you tried -metan- or -meta-? In -meta- you can present the values for the effect sizes along with their 95% CIs.
          Thanks for your suggestion. I used help meta in Stata but I didn't get how I could use it.

          Comment


          • #6
            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str14 outcome float(coef se ci_l ci_u)
            "S" -1.4595655 .14353406  -1.741194 -1.1779372
            "M" -1.4105432   .167224 -1.7386538 -1.0824327
            "A"  1.2288225 .18672407   .8624509   1.595194
            "C"  1.0382018 .18100072   .6830601  1.3933436
            "B"  1.0915558 .19679554   .7054231  1.4776887
            "D" -1.0109191 .18807442 -1.3799403   -.641898
            end
            
            *EXTRACT RESULTS TO MATRIX
             mkmat coef ci_l ci_u, mat(res) rownames(outcome)
            
            *GRAPH USING COEFPLOT FROM SSC
            *ssc install coefplot, replace
            set scheme s1color
            mat res= res'
            gen xpos = -2
            
            coefplot mat(res), ci((2 3)) xline(0) mlabpos(1)  mlabel(string(@b,"%9.3f")) mlabcolor(none) sort ///
            addplot(scatter @at xpos, ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(-15) mlabsize(small)) ///
                graphr(margin(r=10)) xlab(-2/2) ysc(outergap(30)) ylab(,labgap(-20))
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	15.9 KB
ID:	1704052

            Comment


            • #7
              Originally posted by Andrew Musau View Post
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input str14 outcome float(coef se ci_l ci_u)
              "S" -1.4595655 .14353406 -1.741194 -1.1779372
              "M" -1.4105432 .167224 -1.7386538 -1.0824327
              "A" 1.2288225 .18672407 .8624509 1.595194
              "C" 1.0382018 .18100072 .6830601 1.3933436
              "B" 1.0915558 .19679554 .7054231 1.4776887
              "D" -1.0109191 .18807442 -1.3799403 -.641898
              end
              
              *EXTRACT RESULTS TO MATRIX
              mkmat coef ci_l ci_u, mat(res) rownames(outcome)
              
              *GRAPH USING COEFPLOT FROM SSC
              *ssc install coefplot, replace
              set scheme s1color
              mat res= res'
              gen xpos = -2
              
              coefplot mat(res), ci((2 3)) xline(0) mlabpos(1) mlabel(string(@b,"%9.3f")) mlabcolor(none) sort ///
              addplot(scatter @at xpos, ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(-15) mlabsize(small)) ///
              graphr(margin(r=10)) xlab(-2/2) ysc(outergap(30)) ylab(,labgap(-20))
              [ATTACH=CONFIG]n1704052[/ATTACH]
              Mr. Andrew, thank you so much. I greatly appreciate your assistance.

              Comment

              Working...
              X