Announcement

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

  • coefplot and markers

    Hi
    I've become quite fond of coefplot.
    However I would to add estimate as well as lower and upper 95%ci bounds as a marker in the plot.

    Do anyone know of smart ways of doing so?
    Thank you in advance.
    Kind regards

    nhb

  • #2
    Does one of the examples in the following documentation of the user written program from (SSC/SJ) answer to your request?
    ftp://repec.sowi.unibe.ch/files/wp1/...3-coefplot.pdf
    http://www.stata.com/meeting/germany.../de14_jann.pdf

    Comment


    • #3
      I know both of them. And I did skim them before writing this post without succes
      Kind regards

      nhb

      Comment


      • #4
        Does the following do what you want?
        Code:
        sysuse auto
        regress price ibn.foreign, nocons
        coefplot, ciopts(recast(rscatter))
        You can change the styling of the confidence bounds markers by specifying additional ciopts().
        Code:
        coefplot, ciopts(recast(rscatter) ms(s) color(maroon))
        However, the specified options will always apply to both markers. To change the markers individually, you do something like the following.
        Code:
        coefplot ///
            (., noci label(point estimate)) ///
            (., transform(* = @ll) label(lower bound) ms(s)) ///
            (., transform(* = @ul) label(upper bound) ms(Sh)), nooffset
        This is a bit clumsy, though.

        Comment


        • #5
          Hi Ben
          Thank you, but regrettably no.
          What I want is (eg marker) labels to each plotted confidence interval eg combining @b @ll and @ub in a string like "`@b' (`@ll'; `@ub' )" (here I pretend that @b, @ll and @ub are like macros).
          Can @values be used like macros?

          I want something like section 7.3 in your Stata article (see below) where estimates are marker labels.
          Click image for larger version

Name:	markerlabel.jpg
Views:	1
Size:	26.3 KB
ID:	1309178
          Or a string like "`@b' (`@ll'; `@ub' )" at one of the vertical axis.

          Thank you for a fantastic tool
          Kind regards

          nhb

          Comment


          • #6
            Howdy!

            If I gather correctly, you want to add label markers to the point estimate as well as the 95% CI values. The mlabel option provides that along with format() to specify the display for format, which is what I've been doing.

            If you want to replicate the above using Ben's syntax, I'd probably use the grexport package. Here's my hand at the syntax below, creating a tempfile with a dataset containing, the lb ub, and b.


            Code:
            /* Ben's syntax with mlabel option */
            sysuse auto, clear
            keep if rep78>=3
            qui regress mpg headroom i.rep##i.foreign
            coefplot, xline(0) mlabel format(%9.2g) mlabposition(12)mlabgap(*2)
            
            /* create tempfile after typing "ssc install grexport" */
            tempfile grexfile // name tempfile
            grexport, list saving(`grexfile') // grexport command
            use `grexfile', clear // use tempfile
            ren (__000000 __000001 __000002 __000003) (lb ub varname b) // ren tempvars
            list // list results again w/ renamed columns
            
            /* Graph results */
            Nathan E. Fosse, PhD
            [email protected]

            Comment


            • #7
              Hi Nathan
              Thank you for trying.
              The regression says:
              Code:
              -------------------------------------------------------------------------------
                        mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              --------------+----------------------------------------------------------------
                   headroom |  -1.120753   .9886418    -1.13   0.262    -3.104608    .8631023
                            |
                      rep78 |
                         4  |  -.3064994   1.973721    -0.16   0.877    -4.267059    3.654061
                         5  |   11.91038   3.856209     3.09   0.003      4.17233    19.64843
                            |
                    foreign |
                   Foreign  |   3.710693   3.149593     1.18   0.244    -2.609427    10.03081
                            |
              rep78#foreign |
                 4#Foreign  |   1.675263   3.941705     0.43   0.673    -6.234348    9.584873
                 5#Foreign  |  -8.972643   5.129298    -1.75   0.086    -19.26533    1.320046
                            |
                      _cons |   22.61131    3.33317     6.78   0.000     15.92282    29.29981
              In your example and Ben's the first (top) marker label is "-1.1" (-1.120753 with one decimal).
              I want the label to be "-1.1 (-3.1; 0.9)".

              If possible
              Kind regards

              nhb

              Comment


              • #8
                Thanks, Niels, got it! Yes, that would be nice, wouldn't it? Well, one way is to do something akin to the Figure 3 example provided in this 2007 supplement from the tables2graphs website. Their code in Stata can be modified to label the column values using macros as identified after grexport. That's my inclination, but I'm open to better ideas.

                Code:
                use mcclurg, clear
                gen lo=mean-1*sd
                gen hi=mean+1*sd
                *input x vector with the order of variables we want in the plot
                mat x=(4,3,1,2)'
                * gets x vector copied to a variable called x
                svmat x
                label def varnames 4 "Size (1260)" 3 "Political Talk (1253)" 2 "Political Knowledge(1220)" 1 "Political Agreement (1154)"
                
                label val x varnames
                label var mean "mean"
                label var sd "sd"
                label var lo "lo"
                label var hi "hi"
                
                twoway rspike lo hi x, horizontal || scatter x mean, sort  ylabel(1(1)4, valuelabel angle(0)) xtitle("") ytitle("") legend(off) xscale(range(0,5)) scheme(s1mono) scale(.5)
                
                *use this command to create a postscript file in working directory
                *graph export "mcclurg_stata.ps"
                *saves png for web
                graph export mcclurg_stata.png, replace
                Nathan E. Fosse, PhD
                [email protected]

                Comment


                • #9
                  Hi Niels,

                  creating marker labels such as "-1.1 (-3.1; 0.9)" is not possible in coefplot. However, maybe the following helps.

                  Code:
                  sysuse auto
                  regress price ibn.foreign, nocons
                  gen str lbl = ""
                  coefplot, mlabel(lbl) mlabpos(12) generate
                  replace lbl = strofreal(__b,"%9.1f")   + " (" + ///
                                strofreal(__ll1,"%9.1f") + "; "  + ///
                                strofreal(__ul1,"%9.1f") + ")"
                  `r(graph)'
                  drop lbl __* // cleanup
                  The trick is to save coefplot's input as variables and then use these variables to create the labels you want and then rerun the exact same command.

                  ben

                  Comment


                  • #10
                    Here's the corresponding graph:
                    Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.5 KB
ID:	1309949

                    Comment


                    • #11
                      Hi Ben
                      Thank you very much
                      Nice to know this workaround.
                      Kind regards

                      nhb

                      Comment


                      • #12
                        Hi
                        If others should interested in this solution then in order to clean up one needs to do the following as well
                        Code:
                        label drop __by __plot
                        just around the other drop command
                        Kind regards

                        nhb

                        Comment


                        • #13
                          I'm having some trouble figuring out how to change the color of the markers for specific coefficients. I know how to change it for all the coefficients with mcolor(), but how do you change it for specific coefficients?

                          Thanks in advance.

                          Comment

                          Working...
                          X