Announcement

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

  • Graph options for connected line graph (two y-variables) only apply to one y-variable

    Hello,

    First time using datex. Hope this output is fine for you.
    Code:
     * Example generated by -dataex-. To install: ssc install dataex clear input float(bin change lower_limit bigger_limit) 2500 .12441248 .12441248         . 3000  .4294294  .4294294         . 3500  .4662447  .4662447         . 4000 .43055555 .43055555         . 4500 .51055557 .51055557         . 5000  .5265151         .         . 5500  .5465278         .  .5465278 6000  .5086806         .  .5086806 6500  .5345529         .  .5345529 7000 .58219033         . .58219033 end
    I'm trying to create a twoway connected graph with with two y variables (lower_limit and bigger_limit) and one x variable (bin). The two y variables where created by using:

    Code:
    gen lower_limit = change if bin < 4750 & bin > 2000
    gen bigger_limit =  change if bin > 5250
    The question I have now is, I want the connect points for both y variables to have the "diamond-style". But whenever I use

    Code:
    twoway connected lower_limit bigger_limit bin if bin != 5000 & bin > 2000, msymbol(D) xlabel(2500(500)7500) xtitle("") xlabel(3000 "3000" 4000 "4000" 5000 "5000" 6000 "6000" 7000 "7000") ylabel(.30(.10)0.7) ytitle("") xline(5000) color(red) title("") || lfit lower_limit bin, lcolor(red) lpattern(dash) || lfit bigger_limit bin, lcolor(brown) lpattern(dash)
    msymbol(D), it always applies the diamonds only to lower_limit connection points not for the connection points from bigger_limit. Also same problem applies to color(red). It only colors the lower_limit. I cannot figure out how to apply for both. Couldnt find anything about in the options.

    Hope someone can help.
    Last edited by Pierre Kind; 17 Jul 2020, 13:06.

  • #2
    I have also complained about this not being documented in the past, but to no avail. With such graphs, you want to repeat the options (or specify each option independently).

    Code:
    twoway connected lower_limit bigger_limit bin if bin != 5000 & bin > 2000, msymbol(DD)

    Comment


    • #3
      Hello,

      thank you for your answer. Trying msymbol(DD) gave me unfortunately this error message though:
      "(note: named style DD not found in class symbol, default attributes used)"

      Sidenote: Im using Jupyter Notebooks with Stata Kernels. I wouldnt see why this would matter, Im just giving this information in case it's necessary.
      Last edited by Pierre Kind; 17 Jul 2020, 15:18.

      Comment


      • #4
        Can you post the data in #1 again. Make sure to preview before posting so that everything is not on one line.

        Comment


        • #5
          Hope it works now for you

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float(bin change lower_limit bigger_limit)
                      0 .08722616 . .
          1.9073486e-06 .20833333 . .
          .000014781952 .08333334 . .
          .000061035156      .125 . .
                    .01 .28812057 . .
              .01999919 .08333334 . .
                    .02  .2240991 . .
                    .03 .19109195 . .
               .0390625  .6666667 . .
                    .04     .1875 . .
              .04999995      .125 . .
                    .05  .2847222 . .
                    .05  .2872807 . .
                    .06  .2847222 . .
                    .06      .125 . .
                    .07 .23214285 . .
                    .08 .20833333 . .
                    .09 .28030303 . .
                     .1  .3333333 . .
                    .11 .29166666 . .
                    .12 .24358974 . .
                    .13 .23958333 . .
                    .14  .2857143 . .
                    .15  .3090278 . .
                    .16 .24264705 . .
                    .17 .21666667 . .
                    .18 .19791667 . .
                    .19 .25462964 . .
                     .2       .25 . .
                     .2 .29166666 . .
                    .21 .21666667 . .
                    .22 .26190478 . .
                    .23 .15277778 . .
                    .24 .20833333 . .
                    .25 .28333333 . .
                    .26 .23148148 . .
              .26999998 .08333334 . .
                    .27  .3166667 . .
                    .28 .20833333 . .
                    .29 .27314815 . .
                     .3       .25 . .
                     .3 .19791667 . .
                    .31 .30555555 . .
                    .32  .3583333 . .
                    .33  .4583333 . .
                    .33 .27604166 . .
                    .34 .22222222 . .
                    .35 .29166666 . .
                    .36 .08333334 . .
                    .36 .25833333 . .
                    .37 .20833333 . .
                    .38 .22916667 . .
                    .39 .20833333 . .
                     .4       .25 . .
                     .4  .2559524 . .
                    .41  .2638889 . .
                    .42 .11111111 . .
                    .43 .22916667 . .
                    .44 .29166666 . .
                    .45 .30555555 . .
                    .45 .08333334 . .
                    .46 .20833333 . .
                    .47 .18333334 . .
                    .48 .22916667 . .
                    .49 .30555555 . .
                     .5       .25 . .
                    .51 .20833333 . .
                    .52 .22916667 . .
                    .53    .40625 . .
                    .54 .08333334 . .
                    .55 .20833333 . .
                    .56        .2 . .
                    .57 .22916667 . .
                    .58 .15833333 . .
                    .59        .2 . .
                     .6 .20833333 . .
                     .6  .3020833 . .
                    .61        .5 . .
                    .62 .15833333 . .
                    .63  .4166667 . .
                    .64  .3333333 . .
                    .65    .21875 . .
                    .66 .29166666 . .
                    .67    .15625 . .
                    .68  .2777778 . .
                    .69      .125 . .
                     .7 .29166666 . .
                    .71  .4583333 . .
                    .72 .20833333 . .
                    .72 .29166666 . .
                    .73 .08333334 . .
                    .75 .23333333 . .
                    .76 .08333334 . .
                    .77  .4166667 . .
                    .78       .25 . .
                    .79  .4583333 . .
                     .8  .3020833 . .
                    .81 .22916667 . .
                    .82  .3333333 . .
                    .83      .125 . .
          end

          Comment


          • #6
            The example is of limited use as lower_limit bigger_limit are always missing. But the issue is easy to explain.

            You can run this code in your Stata, unless you are behind a very strict firewall. Even if you can't run it, it explains.


            Code:
            * you should be read this in as a sandbox 
            . webuse grunfeld, clear
            
            * the default symbol for connect is a solid or filled circle 
            
            . twoway connect invest mvalue year if company == 1
            
            * specify D and the first named variable is plotted with a diamond; the second is plotted with the default 
            
            . twoway connect invest mvalue year if company == 1, ms(D)
            
            * specify D D and the first and second named variables are plotted with diamonds 
            
            . twoway connect invest mvalue year if company == 1, ms(D D)
            
            * Andrew forgot briefly about the need for a space 
            
            . twoway connect invest mvalue year if company == 1, ms(DD)
            (note:  named style DD not found in class symbol, default attributes used)
            
            * ms(D) does not mean "all variables should be plotted with diamonds"; there is a syntax for that 
            . twoway connect invest mvalue year if company == 1, ms(D ..)
            For once I disagree with Andrew Musau. This is documented, at

            Code:
            help stylelists

            Comment


            • #7
              It worked. Using (D D) made both variables have diamonds. Thank you Mr. Musau and Mr. Cox

              Comment


              • #8
                Thanks Nick Cox for the correction and the reference. I completely missed that entry in the documentation.

                Comment


                • #9
                  The ideal manual is one paragraph long and includes just the information you need at this particular instant.

                  Comment

                  Working...
                  X