Announcement

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

  • #16
    There is no -addplot()- option for twoway. You just need to add the extra plots, separating each with parentheses or double pipes.


    Code:
    twoway area Shortvolume Day if inrange(Firm, 1, 9), color(gray) || line FivesShort Day if inrange(firm, 1, 9), by(Firm) ...

    Comment


    • #17
      Dear Andrew Musau many thanks for your reply.
      Well I tried this code and it works but i need to add some featuers in the charts but I couldnt . well the code is:
      twoway (area Shortvolume Day if inrange(Firm, 1, 9), color(gs8)) (line FivesShort Day , lcolor(red)), by( Firm , yrescale xrescale) legend(off) yscale(range(0 (20) 100)) ylabel(#5) xscale(range(0 (20) 100)) xlabel(#5) ytick(10 30 50 70 90) xtick(10 30 50 70 90) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall)) by(Symbol).

      Firstly, I have another variable called "country" that specifies the location of each firm. I would like to incorporate to the above code to display the name of the country at the 7 o'clock position on each chart, corresponding to the respective firm. However, I'm unsure of how to implement this.

      Secondly, I would like to style the subtitle box in black and the subtitle text in white. Any guidance on achieving this would be greatly appreciated. Thank you for your assistance.

      Comment


      • #18
        Andrew Musau back to #17 as you know the subtitle for each chart is already the name of firm as i added by(Firm) so I would like to style the subtitle box in black and the subtitle text in white.
        Third i tried the legend (off) to remove and its not work. any alternative please. Many Thanks.

        Comment


        • #19
          For the labels, refer to https://journals.sagepub.com/doi/10....6867X211063413. For the text box and font color:

          Code:
          webuse grunfeld, clear
          lab def company 1 "A Corp." 2 "B Corp." 3 "C Corp." 4 "D Corp."
          lab values company company
          tw (line invest year if company<5, sort), by(company, note("")) subtitle(, color(white) fcolor(black)) xtitle("")
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	40.4 KB
ID:	1753490

          Comment


          • #20
            Originally posted by Bashar Fin View Post
            Andrew Musau
            Third i tried the legend (off) to remove and its not work. any alternative please. Many Thanks.
            -legend()- must be placed within -by()-

            Code:
            by(company, note("") leg(off))

            Comment


            • #21
              Thank you so much Andrew Musau. Many thanks. its work.

              Comment


              • #22
                Dear Andrew Musau

                I am stuck with an issue and I could not find a solution for it, but I am sure that Stata software can handle it. As you can see in my data example and the code that I use to export the image:

                Code:
                twoway (area Shortvolume Day ) (line FivesShort Day ), by( Firm , yrescale xrescale) yscale(range(0 (20) 100)) ylabel(#6) ylabel(0(20)100) xscale(range(0 (20) 100)) xlabel(#6) xlabel(0(20)100) ytick(10 30 50 70) xtick(10 30 50 70 90) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall))ytitle("") xtitle("") by( Symbol ,note("") leg(off)) subtitle(, color(white) fcolor(black)) plotr(m(tiny)) ylabel(,nogrid) xlabel(,nogrid)

                I saw your response to my issue in #19, but I still don’t know how to do it. I need to add two things inside each chart, exactly in the blank space to the right of the 100 label on the y-axis:

                The label of the variable country , text in blue
                The label of the variable exchange, text in black
                Please, how can I do that? Many thanks.

                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input str4 Symbol str9(Country Exchange) byte Day double Shortvolume long(Firm encodCountry encodExchange) float(day fives FivesShort)
                "ABIO" "U.S.A" "Nasdaq"  1 42.885073104386265 1 7 3   1   5  48.02466
                "ABIO" "U.S.A" "Nasdaq"  2 53.396879043117785 1 7 3   2   5  48.02466
                "ABIO" "U.S.A" "Nasdaq"  3  36.59576935181964 1 7 3   3   5  48.02466
                "ABIO" "U.S.A" "Nasdaq"  4 45.232730631437526 1 7 3   4   5  48.02466
                "ABIO" "U.S.A" "Nasdaq"  5 62.012860874807416 1 7 3   5   5  48.02466
                "ABIO" "U.S.A" "Nasdaq"  6 61.938216343162246 1 7 3   6  10   55.5404
                "ABIO" "U.S.A" "Nasdaq"  7  65.36631529139612 1 7 3   7  10   55.5404
                "ABIO" "U.S.A" "Nasdaq"  8  64.36264721143414 1 7 3   8  10   55.5404
                "ABIO" "U.S.A" "Nasdaq"  9 57.420812856476665 1 7 3   9  10   55.5404
                "ABIO" "U.S.A" "Nasdaq" 10 28.614001679361845 1 7 3  10  10   55.5404
                "ABIO" "U.S.A" "Nasdaq" 11  9.653579242926499 1 7 3  11  15  44.36757
                "ABIO" "U.S.A" "Nasdaq" 12 50.046477040342076 1 7 3  12  15  44.36757
                "ABIO" "U.S.A" "Nasdaq" 13 60.313763720392835 1 7 3  13  15  44.36757
                "ABIO" "U.S.A" "Nasdaq" 14 54.479158083085146 1 7 3  14  15  44.36757
                "ABIO" "U.S.A" "Nasdaq" 15  47.34487594912221 1 7 3  15  15  44.36757
                "ABIO" "U.S.A" "Nasdaq" 16  55.58066139139185 1 7 3  16  20  53.86923
                "ABIO" "U.S.A" "Nasdaq" 17  40.63314064554544 1 7 3  17  20  53.86923
                "ABIO" "U.S.A" "Nasdaq" 18   61.6198471319945 1 7 3  18  20  53.86923
                "ABIO" "U.S.A" "Nasdaq" 19   64.9673352643231 1 7 3  19  20  53.86923
                "ABIO" "U.S.A" "Nasdaq" 20  46.54517096749264 1 7 3  20  20  53.86923
                "ABIO" "U.S.A" "Nasdaq" 21  40.07216992584861 1 7 3  21  25  41.27278
                "ABIO" "U.S.A" "Nasdaq" 22   69.1079706916038 1 7 3  22  25  41.27278
                "ABIO" "U.S.A" "Nasdaq" 23 58.927314799314615 1 7 3  23  25  41.27278
                "ABIO" "U.S.A" "Nasdaq" 24 22.280887011615626 1 7 3  24  25  41.27278
                "ABIO" "U.S.A" "Nasdaq" 25 15.975564605701592 1 7 3  25  25  41.27278
                "ABIO" "U.S.A" "Nasdaq" 26 53.553530751708436 1 7 3  26  30  45.92026
                "ABIO" "U.S.A" "Nasdaq" 27 63.275109170305676 1 7 3  27  30  45.92026
                "ABIO" "U.S.A" "Nasdaq" 28 14.209723310378951 1 7 3  28  30  45.92026
                "ABIO" "U.S.A" "Nasdaq" 29  68.45539689851067 1 7 3  29  30  45.92026
                "ABIO" "U.S.A" "Nasdaq" 30 30.107526881720432 1 7 3  30  30  45.92026
                "ABIO" "U.S.A" "Nasdaq" 31 22.767423185833227 1 7 3  31  35 32.484447
                "ABIO" "U.S.A" "Nasdaq" 32 22.559716897670302 1 7 3  32  35 32.484447
                "ABIO" "U.S.A" "Nasdaq" 33   67.2884479092842 1 7 3  33  35 32.484447
                "ABIO" "U.S.A" "Nasdaq" 34  5.692396092702547 1 7 3  34  35 32.484447
                "ABIO" "U.S.A" "Nasdaq" 35  44.11425051967049 1 7 3  35  35 32.484447
                "ABIO" "U.S.A" "Nasdaq" 36  87.65651120739653 1 7 3  36  40   38.9609
                "ABIO" "U.S.A" "Nasdaq" 37 26.973026973026975 1 7 3  37  40   38.9609
                "ABIO" "U.S.A" "Nasdaq" 38  39.99077136045528 1 7 3  38  40   38.9609
                "ABIO" "U.S.A" "Nasdaq" 39  33.07976283700638 1 7 3  39  40   38.9609
                "ABIO" "U.S.A" "Nasdaq" 40  7.104450291728635 1 7 3  40  40   38.9609
                "ABIO" "U.S.A" "Nasdaq" 41  40.45404540454046 1 7 3  41  45  38.27912
                "ABIO" "U.S.A" "Nasdaq" 42 11.278519156263453 1 7 3  42  45  38.27912
                "ABIO" "U.S.A" "Nasdaq" 43   82.7527155298953 1 7 3  43  45  38.27912
                "ABIO" "U.S.A" "Nasdaq" 44 21.595313980532346 1 7 3  44  45  38.27912
                "ABIO" "U.S.A" "Nasdaq" 45  35.31501657981999 1 7 3  45  45  38.27912
                "ABIO" "U.S.A" "Nasdaq" 46  59.59571358986848 1 7 3  46  50  31.46121
                "ABIO" "U.S.A" "Nasdaq" 47 46.900146305779074 1 7 3  47  50  31.46121
                "ABIO" "U.S.A" "Nasdaq" 48  36.56673511293634 1 7 3  48  50  31.46121
                "ABIO" "U.S.A" "Nasdaq" 49  10.96433289299868 1 7 3  49  50  31.46121
                "ABIO" "U.S.A" "Nasdaq" 50 3.2791327913279136 1 7 3  50  50  31.46121
                "ABIO" "U.S.A" "Nasdaq" 51  66.13495524443425 1 7 3  51  55  44.67732
                "ABIO" "U.S.A" "Nasdaq" 52 23.995713311466893 1 7 3  52  55  44.67732
                "ABIO" "U.S.A" "Nasdaq" 53  40.95413689790274 1 7 3  53  55  44.67732
                "ABIO" "U.S.A" "Nasdaq" 54  28.14309510589355 1 7 3  54  55  44.67732
                "ABIO" "U.S.A" "Nasdaq" 55  64.15871233389481 1 7 3  55  55  44.67732
                "ABIO" "U.S.A" "Nasdaq" 56 37.543388198410035 1 7 3  56  60 32.178623
                "ABIO" "U.S.A" "Nasdaq" 57  31.46987951807229 1 7 3  57  60 32.178623
                "ABIO" "U.S.A" "Nasdaq" 58 22.774433200973483 1 7 3  58  60 32.178623
                "ABIO" "U.S.A" "Nasdaq" 59 20.968159461558376 1 7 3  59  60 32.178623
                "ABIO" "U.S.A" "Nasdaq" 60   48.1372636328554 1 7 3  60  60 32.178623
                "ABIO" "U.S.A" "Nasdaq" 61  48.52251407129456 1 7 3  61  65  21.61792
                "ABIO" "U.S.A" "Nasdaq" 62  25.14602062065113 1 7 3  62  65  21.61792
                "ABIO" "U.S.A" "Nasdaq" 63   7.07395498392283 1 7 3  63  65  21.61792
                "ABIO" "U.S.A" "Nasdaq" 64  7.212402636309168 1 7 3  64  65  21.61792
                "ABIO" "U.S.A" "Nasdaq" 65  20.13472055488862 1 7 3  65  65  21.61792
                "ABIO" "U.S.A" "Nasdaq" 66 60.870005741497515 1 7 3  66  70  43.28412
                "ABIO" "U.S.A" "Nasdaq" 67 22.316684378320936 1 7 3  67  70  43.28412
                "ABIO" "U.S.A" "Nasdaq" 68 20.278776978417266 1 7 3  68  70  43.28412
                "ABIO" "U.S.A" "Nasdaq" 69  43.92181294291722 1 7 3  69  70  43.28412
                "ABIO" "U.S.A" "Nasdaq" 70  69.03334132885584 1 7 3  70  70  43.28412
                "ABIO" "U.S.A" "Nasdaq" 71 13.821456538762725 1 7 3  71  75    40.971
                "ABIO" "U.S.A" "Nasdaq" 72  46.55145160440487 1 7 3  72  75    40.971
                "ABIO" "U.S.A" "Nasdaq" 73 18.207836456558773 1 7 3  73  75    40.971
                "ABIO" "U.S.A" "Nasdaq" 74  66.27314588027824 1 7 3  74  75    40.971
                "ABIO" "U.S.A" "Nasdaq" 75  60.00113327289212 1 7 3  75  75    40.971
                "ABIO" "U.S.A" "Nasdaq" 76 19.457511760584527 1 7 3  76  80 32.458393
                "ABIO" "U.S.A" "Nasdaq" 77  42.94003868471953 1 7 3  77  80 32.458393
                "ABIO" "U.S.A" "Nasdaq" 78  6.746727836999056 1 7 3  78  80 32.458393
                "ABIO" "U.S.A" "Nasdaq" 79  53.44162769710395 1 7 3  79  80 32.458393
                "ABIO" "U.S.A" "Nasdaq" 80  39.70605187319885 1 7 3  80  80 32.458393
                "ABIO" "U.S.A" "Nasdaq" 81  51.90510962571852 1 7 3  81  85   26.7737
                "ABIO" "U.S.A" "Nasdaq" 82  32.01936376210235 1 7 3  82  85   26.7737
                "ABIO" "U.S.A" "Nasdaq" 83 3.3119921201674467 1 7 3  83  85   26.7737
                "ABIO" "U.S.A" "Nasdaq" 84 21.967737963305012 1 7 3  84  85   26.7737
                "ABIO" "U.S.A" "Nasdaq" 85  24.66429260330885 1 7 3  85  85   26.7737
                "ABIO" "U.S.A" "Nasdaq" 86  26.16863644381725 1 7 3  86  90  27.22948
                "ABIO" "U.S.A" "Nasdaq" 87  19.64480024871755 1 7 3  87  90  27.22948
                "ABIO" "U.S.A" "Nasdaq" 88   28.4585475981437 1 7 3  88  90  27.22948
                "ABIO" "U.S.A" "Nasdaq" 89    37.676419765972 1 7 3  89  90  27.22948
                "ABIO" "U.S.A" "Nasdaq" 90             24.199 1 7 3  90  90  27.22948
                "ABVC" "U.S.A" "NYSE"    1  51.81062682061924 2 7 1  91  95   45.6721
                "ABVC" "U.S.A" "NYSE"    2 39.532457970303106 2 7 1  92  95   45.6721
                "ABVC" "U.S.A" "NYSE"    3 40.310403003625225 2 7 1  93  95   45.6721
                "ABVC" "U.S.A" "NYSE"    4 47.557591635713834 2 7 1  94  95   45.6721
                "ABVC" "U.S.A" "NYSE"    5 49.149436200585775 2 7 1  95  95   45.6721
                "ABVC" "U.S.A" "NYSE"    6 55.943864310453066 2 7 1  96 100     51.87
                "ABVC" "U.S.A" "NYSE"    7 53.983475637962385 2 7 1  97 100     51.87
                "ABVC" "U.S.A" "NYSE"    8  54.46493970308738 2 7 1  98 100     51.87
                "ABVC" "U.S.A" "NYSE"    9  57.04302849149043 2 7 1  99 100     51.87
                "ABVC" "U.S.A" "NYSE"   10 37.914712502952334 2 7 1 100 100     51.87
                end
                label values Firm Firm
                label def Firm 1 "ABIO", modify
                label def Firm 2 "ABVC", modify
                label values encodCountry encodCountry
                label def encodCountry 7 "U.S.A", modify
                label values encodExchange encodExchange
                label def encodExchange 1 "NYSE", modify
                label def encodExchange 3 "Nasdaq", modify
                ------------------ copy up to and including the previous line ------------------

                Listed 100 out of 2070 observations
                Use the count() option to list more

                .
                Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	63.5 KB
ID:	1753921

                Last edited by Bashar Fin; 20 May 2024, 15:56.

                Comment


                • #23
                  The coordinates are named "y1", "y2" and "x" below, which you can adjust.


                  bys Firm: gen y1=95 if _n==_N
                  bys Firm: gen y2= 91 if _n==_N
                  bys Firm: gen x= 85 if _n==_N


                  twoway (area Shortvolume Day ) (line FivesShort Day ) (scatter y1 x, msy(none) mlab(Country) mlabc(blue)) (scatter y2 x, msy(none) mlab(Exchange) mlabc(black)), by( Firm , yrescale xrescale) yscale(range(0 (20) 100)) ylabel(#6) ylabel(0(20)100) xscale(range(0 (20) 100)) xlabel(#6) xlabel(0(20)100) ytick(10 30 50 70) xtick(10 30 50 70 90) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall))ytitle("") xtitle("") by( Symbol ,note("") leg(off)) subtitle(, color(white) fcolor(black)) plotr(m(tiny)) ylabel(,nogrid) xlabel(,nogrid)
                  Click image for larger version

Name:	Graph.png
Views:	1
Size:	91.6 KB
ID:	1753927

                  Comment


                  • #24
                    Dear Andrew Musau , its works. Thank you so much. I truly appreciate your help . Thanks.

                    Comment


                    • #25
                      Dear Andrew Musau ,

                      Sorry for the multiple questions. I truly appreciate your help. I have faced an issue when exporting my graphs.

                      First, I used this code: (twoway (area Shortvolume Day , color(gs8)) (line FivesShort Day , lcolor(red)) (scatter y1 x, msy(none) mlab(Country) mlabc(blue) mlabs(vsmall)) (scatter y2 x, msy(none) mlab(Exchange) mlabc(red) mlabs(vsmall)) if inrange(Firm, 1, 9) , by( Firm , yrescale xrescale) yscale(range(0 (20) 100)) ylabel(#6) ylabel(0(20)100) xscale(range(0 (20) 100)) xlabel(#6) xlabel(0(20)100) ytick(10 30 50 70 90) xtick(10 30 50 70 90) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall))ytitle("") xtitle("") by( Firm ,note("") leg(off)) subtitle(, color(white) fcolor(black)) plotr(m(tiny)) ylabel(,nogrid) xlabel(,nogrid) ysize(4.5) xsize(7.5) aspect(0) ).

                      As you can see in the first image, the size and display of the graphs are excellent. Since I have 29 firms, I repeated the above code another three times but with different if inrange conditions (if inrange(Firm, 10, 18), if inrange(Firm, 19, 27), if inrange(Firm, 28, 29)). I used this method because only 3 columns were displayed, and the result was excellent when I merged them.

                      Then, I changed the code to this one: (twoway (area Shortvolume Day , color(gs8)) (line FivesShort Day , lcolor(red)) (scatter y1 x, msy(none) mlab(Country) mlabc(blue) mlabs(vsmall)) (scatter y2 x, msy(none) mlab(Exchange) mlabc(red) mlabs(vsmall)) , by( Firm , yrescale xrescale) yscale(range(0 (20) 100)) ylabel(#6) ylabel(0(20)100) xscale(range(0 (20) 100)) xlabel(#6) xlabel(0(20)100) ytick(10 30 50 70 90) xtick(10 30 50 70 90) ylabel(,labsize(vsmall)) xlabel(,labsize(vsmall))ytitle("") xtitle("") by( Firm ,note("") leg(off)) subtitle(, color(white) fcolor(black)) plotr(m(tiny)) ylabel(,nogrid) xlabel(,nogrid) ysize(4.5) xsize(7.5) aspect(0) ).

                      The change I made was to remove the if inrange conditions and make the graphs for the 29 firms. However, when I exported them to PNG, it displayed as shown in the second image below.

                      What I need is for the second code to give me a PNG with only 3 columns, not 6, and display the graphs in a 9x9x9x2 layout, as in the first code. I tried adjusting the width and height, but it didn't give me the desired result. Many thanks.

                      What I need exactly is the same as in the post https://www.statalist.org/forums/for...ne-many-graphs. number #3 and #4.
                      Please if its not works for me could you give me altarnatives ways. Many Thanks.
                      Click image for larger version

Name:	1.png
Views:	1
Size:	88.2 KB
ID:	1754150
                      Click image for larger version

Name:	2.png
Views:	1
Size:	276.7 KB
ID:	1754151

                      Comment


                      • #26
                        To get 3 columns, place this within -by()-

                        Code:
                        by( Firm ,note("") leg(off) col(3))

                        See the -height()- and -width()- options in


                        Code:
                        help png_options
                        You have to use these options to translate your requirements when exporting the graph. I can't help you with that.

                        Comment

                        Working...
                        X