Announcement

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

  • Manually inputted coefficients and confidence intervals in coefplot

    Dear all,

    I am trying to manually plot the coefficients and confidence intervals for a single variable from six regressions. I want to input the coefficients and standard errors in a matrix and then plot the matrix (coefficients and calculated 95% confidence intervals) using coefplot. I managed to plot the coefficients but not the confidence intervals. When creating the matrix, is there a way to define that the first row is "b" and the second row is "se" and then somehow ask Stata to calculate the confidence intervals and plot those as well? This is what I have up to now:

    Code:
    clear all
    matrix input A = (13.1304, 3.6182, 1.3543, -1.2372, 1.7941, 1.9699 \ 4.766, 1.388, 0.936, 1.410, 0.342, 0.207)
    coefplot mat(A), vertical
    The coefficients are plotted but I get this error for the CI: "(A: could not determine CI1)"

    Thank you! Your help will be appreciated so much!

  • #2
    coefplot is from SSC (FAQ Advice #12). Thanks for the data example.

    Code:
    clear all
    matrix input A = (13.1304, 3.6182, 1.3543, -1.2372, 1.7941, 1.9699 \ 4.766, 1.388, 0.936, 1.410, 0.342, 0.207)
    set scheme s1mono
    coefplot mat(A), se(2) vertical
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	14.9 KB
ID:	1652721

    Comment


    • #3
      This has been so useful, thank you so much Andrew!

      Comment


      • #4
        Hello, I'm trying to plot similar coefplots by inputting data into a matrix. How would you assign names/labels to each coefficient so that it appears on the graph axis (instead of the default c1, c2 etc.)? Many thanks.

        Comment


        • #5
          Code:
          coefplot mat(A), se(2) vertical xlab(1 "Whatever 1" 2 "Whatever 2" ...)

          Comment


          • #6
            Thanks so much!

            Comment


            • #7
              I have one follow-up question: is there a way to produce these graphs in dark blue, as it would appear if we run regressions and use stored estimates within Stata itself?

              Comment


              • #8
                Not only the coefficients, but the confidence intervals as well. When I use the option color(blue), only the color of the coefficient dots change

                Comment


                • #9
                  I figured it out using the "lcolor" option under "ciopts". Apologies for the multiple posts.

                  Comment


                  • #10
                    Related to the above discussion, does anyone know how to use a different colour for coefficients that are statistically significant vs those that are not? I'm currently using the below code to draw a coefficient plot based on inputted data. All coefficients appear in blue. I want to change the colour to red for only coefficients that are statistically significant (the coefficient -0.063 in my example).

                    Code:
                    matrix input A = (0, 0.018, -0.063, -0.009 \ 0, 0.020, 0.038, 0.054) coefplot mat(A), se(2) vertical yline(0, lcolor(gray)) xlab(1 "Base" 2 "Pre" 3 "Post1" 4 "Post2", labsize(small)) title("Real income", size(*0.80) color(navy)) ylabel(-0.10 "-0.10" -0.05 "-0.05" 0.00 "0.00" 0.05 "0.05", labsize(vsmall)) ciopts(lcolor(navy) recast(rcap)) format(%9.2f) mlabposition(12) mlabgap(*4) mlabel(cond(@pval<.01, string(@b, "%9.3fc") + "***", cond(@pval<.05, string(@b, "%9.3fc") + "**", cond(@pval<.10, string(@b, "%9.3fc") + "*", string(@b, "%9.3fc"))))) mlabcolor(navy) color(navy) graphregion(col(white)) bgcol(white) xlab(, nogrid) ylab(, nogrid)

                    Comment


                    • #11
                      You have coefficients and standard errors in your matrix. What is significant is not globally known. It depends on the distribution of the statistic and your chosen levels of significance (alphas).

                      Comment


                      • #12
                        Thanks Andrew, so I guess I have to define what is significant and then run some code to produce different colours for different levels of significance?

                        Comment


                        • #13
                          Yes. One way is to separate the "significant" coefficients from the rest.

                          Code:
                          matrix input A = (0, 0.018, .z, -0.009 \ 0, 0.020, .z, 0.054) 
                          matrix input sigA = (.z, .z, -0.063, .z \ .z, .z, 0.038, .z) 
                          set scheme s1color
                          coefplot mat(A) mat(sigA), se(2) vertical yline(0, lcolor(gray)) ///
                          xlab(1 "Base" 2 "Pre" 3 "Post1" 4 "Post2", labsize(small)) ///
                          title("Real income", size(*0.80) color(navy)) ///
                          ylabel(-0.10 "-0.10" -0.05 "-0.05" 0.00 "0.00" 0.05 "0.05", labsize(vsmall)) ///
                          ciopts(recast(rcap)) format(%9.2f) mlabposition(12) mlabgap(*4) ///
                          mlabel(cond(@pval<.01, string(@b, "%9.3fc") + "***", cond(@pval<.05, string(@b, "%9.3fc") ///
                           + "**", cond(@pval<.10, string(@b, "%9.3fc") + "*", string(@b, "%9.3fc"))))) ///
                           graphregion(col(white)) bgcol(white) xlab(, nogrid) ylab(, nogrid)   nooffset nokey
                          Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.8 KB
ID:	1732842

                          Comment


                          • #14
                            Thank you so much, this is exactly what I needed!

                            Comment


                            • #15
                              Dear all,

                              Thanks a lot for this thread - it helped me a lot with the same issue. However, I still can't get plotted the confidence intervals.

                              I run the same code:
                              clear all
                              matrix input A = (13.1304, 3.6182, 1.3543, -1.2372, 1.7941, 1.9699 \ 4.766, 1.388, 0.936, 1.410, 0.342, 0.207)
                              set scheme s1mono
                              coefplot mat(A), se(2) vertical

                              but receive this error: A: invalid syntax in se()

                              Do you know how to fix it?

                              Thanks a lot in advance!

                              Comment

                              Working...
                              X