Announcement

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

  • twoway line with more than 15 lines?

    Dear All,
    I have a panel data set where I use the following command to print a graph of interest:

    Code:
    twoway line mean_country_cum day_date if code == "U:ACE" || line mean_country_cum day_date if code == "D:MUV2" || ...
    Unfortunately Stata will only print the first 15 lines and then drop the others. They do not appear in the graph, nor in the legend (where however Stata realizes that 3 countries are not getting a value) If I change the order of countries, the problem is persistent in the sense that always the last three are missing (so it is not a dataissue with NO FI and AT, but a stata problem)

    Does anyone know how to force it to accept more lines?

    Thanks in advance,
    Harvey


    Click image for larger version

Name:	max15.png
Views:	1
Size:	8.4 KB
ID:	1332912

  • #2
    The limit is not on the number of lines, but on the number of graphs. But do you really think this design would work well any way? It's a recipe for spaghetti.

    Consider

    Code:
     twoway line mean_country_cum day_date, by(code)
    or subsetplot (SSC). On the last, see http://www.statalist.org/forums/foru...series-problem and in turn its references
    and http://stats.stackexchange.com/quest...es-in-one-plot
    Last edited by Nick Cox; 28 Mar 2016, 06:20.

    Comment


    • #3
      Dear Nick Cox, I understand what you mean. Probably:
      Code:
      twoway line mean_country_cum day_date, by(code)
      is the best solution. For some reason though the dates are not displayed for some countries and also for some there is a linear line connecting the first and the last observation. Do you know how to change this? It is weird because the variable day_date is declared to be time:
      Code:
      xtset id day_stat
      Click image for larger version

Name:	graphs.png
Views:	1
Size:	6.0 KB
ID:	1332923

      Comment


      • #4
        Have a close look at your data. The connecting line probably means that id variable and the time variable are "misaligned".

        Comment


        • #5
          Eric de Souza : can you elaborate on this? I dont understand what you men =/

          Comment


          • #6
            Harvey: Post an example we can check and you will get good advice. At present, you give nothing that we can check. Please (re-)read FAQ Advice #12, as advised to all posters. We don't need to see all your data; a subset with which you can reproduce your problem is sufficient.

            However, note that your xtset specifies a time variable day_stat and your graph is in terms of day_date. We can't say whether that is biting. As Eric points out you need to check your data more carefully.

            Comment


            • #7
              Nick Cox: I apologize for not getting back, the following reproduces the problem:

              Code:
              clear
              
              webuse grunfeld, clear
              g ret=invest/1500
              bys company (year): g cumul=ret if _n==1
              replace cumul=ret + l.cumul if missing(cumul)
              gen country = "empty"
              keep if company <8
              replace country = "FR" if company ==1
              replace country = "DE" if company ==2
              replace country = "DE" if company ==3
              replace country = "US" if company ==4
              replace country = "US" if company ==5
              replace country = "DE" if company ==6    
              replace country = "FR" if company ==7
                  
              egen meancumul = mean(cumul), by(year country)
              
              
              collapse (mean) invest meancumul, by(country year)
              
              twoway line meancumul year if country == "US"

              See how for for two of the three countries, a line connects the begining and the end. I played a bit with assigning different countries to different companies, but I cannot seem to find a pattern. Any advice how to surpress this?

              Thanks in advance!
              Last edited by Jannic Cutura; 12 Apr 2016, 08:18.

              Comment


              • #8
                I'd edit out the line

                Code:
                  
                 cd "C:\Users\jannic\Desktop\sandbox"
                not least because it casts doubt on whether you are really "Harvey Spector". As one of my old teachers used to say, be sure that your sins will find you out.

                More interestingly, but no less seriously, the code you show only draws a graph for one country, so the perceived problem cannot be reproduced. Please fix the example.

                Comment


                • #9
                  Nick Cox :
                  haha I am sorry, Harvey Spector is a fictional character of a law show, I didn't mean to fool anyone

                  and yes, of course I should have deleted the last if statement:
                  Code:
                  clear
                  
                  webuse grunfeld, clear
                  g ret=invest/1500
                  bys company (year): g cumul=ret if _n==1
                  replace cumul=ret + l.cumul if missing(cumul)
                  gen country = "empty"
                  keep if company <8
                  replace country = "FR" if company ==1
                  replace country = "DE" if company ==2
                  replace country = "DE" if company ==3
                  replace country = "US" if company ==4
                  replace country = "US" if company ==5
                  replace country = "DE" if company ==6    
                  replace country = "FR" if company ==7
                      
                  egen meancumul = mean(cumul), by(year country)
                  
                  
                  collapse (mean) invest meancumul, by(country year)
                  
                  twoway line meancumul year
                  Last edited by Jannic Cutura; 12 Apr 2016, 08:23.

                  Comment


                  • #10
                    I don't find that quite as amusing as you do. The code of practice here is clearly explained as preferring full real names. http://www.statalist.org/forums/help#realnames

                    But now that you've accidentally outed yourself as not what you say, please contact the administrators with a full real name.

                    We can now reproduce your problem. For panel data, starting where you left off, consider

                    Code:
                    encode country, gen(nation) 
                    xtset nation year
                    xtline meancumul 
                    xtline meancumul, overlay

                    Comment


                    • #11
                      Nick Cox : I apologize, I wasn't aware of this rule/convention. It seems that in general people recommend not to reveal your identity online, I didn't notice that Statalist handles this differently. I will contact the administrators immediately.

                      Thank you for the code, it works just fine in the minimum example. let me see if I can work this in my larger code.

                      Comment


                      • #12
                        Thanks for that. For the record, the home page www.statalist.org says

                        "
                        We ask that you use your real name."

                        while there and in the New topic prompt text, all posters are asked to read the FAQ Advice first, which spells out our policy that people use full real names.

                        We find that using full real names helps establish who people are, so that you get to know who wrote what programs or papers, whose advice is good, whose questions are interesting to you, and so forth. As no-one is obliged or expected to publish email addresses, this usually works well for most purposes.


                        Comment


                        • #13
                          Harvey Spector while I completely agree with Nick Cox's warning about over plotting, if for some reason you really just had to have > 15 distinct lines, the ggplot2 palette in brewscheme has upto 24 colors that you can use. Again, there would be no redeeming qualities for such a graph, but if you are forced to do so (e.g., employer tells you that you must create such a hideous monstrosity) then that should help. You may still want to send the information to StataCorp since the default behavior of the s2color scheme is to begin recycling colors once there are more than 15 colors required.

                          Comment


                          • #14
                            "Harvey", to respond to the problem you described in post #1, you can overcome the limit of 15 colors by using combinations of line color and pattern. Here is an example, building on your code in post #9:
                            Code:
                            #delimit ;
                            twoway (line meancumul year if country == "US", lcolor(navy) lpattern(solid))
                              (line meancumul year if country == "FR", lcolor(maroon) lpattern(dash))
                              (line meancumul year if country == "DE", lcolor(forest_green) lpattern(dash_dot)),
                              legend(lab(1 "US") lab(2 "FR") lab(3 "DE"))
                            ;
                            #delimit cr
                            For more information, see
                            Code:
                            help connect_options

                            Comment


                            • #15
                              wbuchanan and Friedrich Huebler : Thanks for your suggestions! The original solution by Nick Cox worked just fine for my needs, but I will keep this in mind, in case I might ever need it. Thanks again everyone!!



                              CLOSED

                              Comment

                              Working...
                              X