Announcement

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

  • Series 0 not found using grc1leg2

    Dear all, I am using Stata 14 on Windows 10. The following code is supposed to create a combined graph of several scatter plots for two variables. I used almost the same code several times for other graphs and it worked. However, this time I always get the error message "Series 0 not found" after all single graphs for the respective countries have been generated, i.e. no combined graph is created (I only get an empty combined graph). After spending several hours trying to fix that problem, I have no more idea...

    Code:
    levelsof country, local(levels)
    
    local graph ""
    
    foreach i of local levels {
        summarize net_tradevalue_m if country == "`i'", meanonly
        local y_min = `r(min)'
        local y_max = `r(max)'
        
        local y_min_r = round(`y_min')
        local y_max_r = round(`y_max')
        
        scatter net_tradevalue_m instal if country == "`i'", ///
        xtitle("Number of items installed") ///
        ytitle("Import value (US$) net of re-exports") ///
        yscale(range(`y_min' `y_max')) ylabel(`y_min_r' `y_max_r') ///
        title("`i'") name(g_`i', replace)
        local graph "`graph' g_`i'"
    }
    
    grc1leg2 `graph', xtob1title ytol1title ytsize(vsmall) labsize(vsmall)
    Code:
    * Example generated by -dataex-.
    year country net_tradevalue_m instal
    2005 "AE"   .596557    3
    2007 "AE"    .57997    2
    2008 "AE"  1.334496    2
    2012 "AE"    .82767    4
    2013 "AE"   2.23105    2
    2014 "AE"  3.857373    0
    2015 "AE"  2.996899    0
    2016 "AE"  3.456476    0
    2017 "AE" 10.282882    0
    2018 "AE"  6.563038    0
    2019 "AE"  3.967778    0
    1996 "AR"  2.930427    0
    1997 "AR"  2.566672    0
    1998 "AR"  2.713423    0
    1999 "AR"  1.757973   20
    2000 "AR"   .820514   50
    2001 "AR"  1.731663   40
    2002 "AR"   .433283   29
    2003 "AR"   .693137   33
    2004 "AR"   .537529   17
    2005 "AR"  1.334015   65
    2006 "AR"  1.607395   36
    2007 "AR"  5.205558  141
    2008 "AR" 13.348274  150
    2009 "AR"  2.953936   45
    2010 "AR"  8.285274   96
    2011 "AR" 22.273457  407
    2012 "AR" 15.632359  180
    2013 "AR" 13.275552  181
    2014 "AR" 10.507074    0
    2015 "AR" 14.350166    0
    2016 "AR" 11.726218    0
    2017 "AR" 16.001951    0
    2018 "AR"  9.526949    0
    2019 "AR" 15.542093    0
    1996 "AT"  9.284512  277
    1997 "AT" 11.324429  232
    1998 "AT"  11.18832  145
    1999 "AT" 16.971384  273
    2000 "AT"  37.53419  320
    2001 "AT" 16.574034  330
    2002 "AT" 16.691013  670
    2003 "AT"  14.51144  365
    2004 "AT" 24.916763  545
    2005 "AT"  25.72232  485
    2006 "AT" 35.112324  498
    2007 "AT"  38.49554  621
    2008 "AT"  46.18709  638
    2009 "AT"  41.32523  508
    2010 "AT"  36.71757  496
    2011 "AT"  43.99167  628
    2012 "AT"  40.30826  835
    2013 "AT"   40.7037  720
    2014 "AT"  51.64431  898
    2015 "AT"  48.09217  987
    2016 "AT"   73.0638 1686
    2017 "AT"     81.19 1641
    2018 "AT"  82.17607 1504
    2019 "AT"  74.40486 1475
    1996 "AU"  4.763878  250
    1997 "AU" 10.905708  526
    1998 "AU"  6.894873  347
    1999 "AU"  8.601764  180
    2000 "AU"  8.956798  440
    2001 "AU" 10.291573  270
    2002 "AU"  13.03586  421
    2003 "AU" 17.182116  569
    2004 "AU" 28.043364  652
    2005 "AU"  29.79912  890
    2006 "AU" 19.709654  719
    2007 "AU"  26.95258  734
    2008 "AU"  20.39395  781
    2009 "AU"  8.937055  399
    2010 "AU" 13.016978  624
    2011 "AU"  17.47799  690
    2012 "AU"   22.5622 1214
    2013 "AU"  13.40527  323
    2014 "AU" 11.591695    0
    2015 "AU" 13.899048    0
    2016 "AU"  16.18698    0
    2017 "AU" 19.643173    0
    2018 "AU"  28.74417    0
    2019 "AU" 18.894983    0
    2003 "BA"     .0334    0
    2004 "BA"   .166554    0
    2005 "BA"   .074738    0
    2006 "BA"   .260394    0
    2007 "BA"   .535262    0
    2008 "BA"   .677682    0
    2009 "BA"  1.532421    0
    2010 "BA"   .381561    2
    2011 "BA"  3.805619    2
    2012 "BA"   .817377    0
    2013 "BA"   .587407    0
    2014 "BA"  1.019831    0
    2015 "BA"   .604327    0
    2016 "BA"   .752781    0
    2017 "BA"  1.305355    0
    2018 "BA"  1.188319    0
    2019 "BA"  2.205264    0
    end

    It would be great, if someone could help me. Thanks a lot!

  • #2
    What's wrong with starting from

    Code:
     
     scatter net_tradevalue_m instal, by(country) xtitle("Number of items installed") ytitle("Import value (US$) net of re-exports")
    ?
    grc1leg2 is community-contributed, so you are asked to explain where it comes from (FAQ Advice #12).

    Comment


    • #3
      The problem is that I need individual scales for the y-axis and x-axis for every country. Your code leads to a uniform scale for every graph such that the output graph is dominated by the country with the highest values, while for all other countries no pattern is discernable.

      I heard of the command grc1leg2 in this topic on statalist: https://www.statalist.org/forums/for...one-legend-box

      I simpliy installed grc1leg2 by typing in: search grc1leg2 and then clicking on install (package grc1leg2 from http://digital.cgdev.org/doc/stata/MO/Misc).

      Comment


      • #4
        The words "starting from" were carefully chosen. The positive point that follows is that you can ask for y and/or x scales to vary through suboptions of by().

        The dataex example is #1 is very helpful, but you've edited out code that is deliberately part of the output to allow the example to run correctly. I've reinstated that.

        Also alphabetical order is sometimes helpful for look-up, but often not. I've included a demonstration of myaxis to put the countries in one of many possible better orders. The latter is from SSC and discussed
        at https://www.statalist.org/forums/for...e-or-graph-use

        Very likely you have many more countries, but the problems of that will bite regardless of how you combine the graphs.

        Code:
        * Example generated by -dataex-.
        clear 
        input year str2 country net_tradevalue_m instal
        2005 "AE"   .596557    3
        2007 "AE"    .57997    2
        2008 "AE"  1.334496    2
        2012 "AE"    .82767    4
        2013 "AE"   2.23105    2
        2014 "AE"  3.857373    0
        2015 "AE"  2.996899    0
        2016 "AE"  3.456476    0
        2017 "AE" 10.282882    0
        2018 "AE"  6.563038    0
        2019 "AE"  3.967778    0
        1996 "AR"  2.930427    0
        1997 "AR"  2.566672    0
        1998 "AR"  2.713423    0
        1999 "AR"  1.757973   20
        2000 "AR"   .820514   50
        2001 "AR"  1.731663   40
        2002 "AR"   .433283   29
        2003 "AR"   .693137   33
        2004 "AR"   .537529   17
        2005 "AR"  1.334015   65
        2006 "AR"  1.607395   36
        2007 "AR"  5.205558  141
        2008 "AR" 13.348274  150
        2009 "AR"  2.953936   45
        2010 "AR"  8.285274   96
        2011 "AR" 22.273457  407
        2012 "AR" 15.632359  180
        2013 "AR" 13.275552  181
        2014 "AR" 10.507074    0
        2015 "AR" 14.350166    0
        2016 "AR" 11.726218    0
        2017 "AR" 16.001951    0
        2018 "AR"  9.526949    0
        2019 "AR" 15.542093    0
        1996 "AT"  9.284512  277
        1997 "AT" 11.324429  232
        1998 "AT"  11.18832  145
        1999 "AT" 16.971384  273
        2000 "AT"  37.53419  320
        2001 "AT" 16.574034  330
        2002 "AT" 16.691013  670
        2003 "AT"  14.51144  365
        2004 "AT" 24.916763  545
        2005 "AT"  25.72232  485
        2006 "AT" 35.112324  498
        2007 "AT"  38.49554  621
        2008 "AT"  46.18709  638
        2009 "AT"  41.32523  508
        2010 "AT"  36.71757  496
        2011 "AT"  43.99167  628
        2012 "AT"  40.30826  835
        2013 "AT"   40.7037  720
        2014 "AT"  51.64431  898
        2015 "AT"  48.09217  987
        2016 "AT"   73.0638 1686
        2017 "AT"     81.19 1641
        2018 "AT"  82.17607 1504
        2019 "AT"  74.40486 1475
        1996 "AU"  4.763878  250
        1997 "AU" 10.905708  526
        1998 "AU"  6.894873  347
        1999 "AU"  8.601764  180
        2000 "AU"  8.956798  440
        2001 "AU" 10.291573  270
        2002 "AU"  13.03586  421
        2003 "AU" 17.182116  569
        2004 "AU" 28.043364  652
        2005 "AU"  29.79912  890
        2006 "AU" 19.709654  719
        2007 "AU"  26.95258  734
        2008 "AU"  20.39395  781
        2009 "AU"  8.937055  399
        2010 "AU" 13.016978  624
        2011 "AU"  17.47799  690
        2012 "AU"   22.5622 1214
        2013 "AU"  13.40527  323
        2014 "AU" 11.591695    0
        2015 "AU" 13.899048    0
        2016 "AU"  16.18698    0
        2017 "AU" 19.643173    0
        2018 "AU"  28.74417    0
        2019 "AU" 18.894983    0
        2003 "BA"     .0334    0
        2004 "BA"   .166554    0
        2005 "BA"   .074738    0
        2006 "BA"   .260394    0
        2007 "BA"   .535262    0
        2008 "BA"   .677682    0
        2009 "BA"  1.532421    0
        2010 "BA"   .381561    2
        2011 "BA"  3.805619    2
        2012 "BA"   .817377    0
        2013 "BA"   .587407    0
        2014 "BA"  1.019831    0
        2015 "BA"   .604327    0
        2016 "BA"   .752781    0
        2017 "BA"  1.305355    0
        2018 "BA"  1.188319    0
        2019 "BA"  2.205264    0
        end
        
        set scheme s1color 
        
        scatter net_tradevalue_m instal , by(country, yrescale)
        
        myaxis better=country, sort(median net_tradevalue_m) descending 
        
        scatter net_tradevalue_m instal , by(better, yrescale)
        Click image for larger version

Name:	myaxis.png
Views:	1
Size:	33.3 KB
ID:	1600727

        Comment


        • #5
          For your specific problem, it appears that it is triggered by including the option -labsize()-. You will want to alert Mead Over, the author of grc1leg2, to take a look.

          Code:
          * Example generated by -dataex-.
          clear 
          input year str2 country net_tradevalue_m instal
          2005 "AE"   .596557    3
          2007 "AE"    .57997    2
          2008 "AE"  1.334496    2
          2012 "AE"    .82767    4
          2013 "AE"   2.23105    2
          2014 "AE"  3.857373    0
          2015 "AE"  2.996899    0
          2016 "AE"  3.456476    0
          2017 "AE" 10.282882    0
          2018 "AE"  6.563038    0
          2019 "AE"  3.967778    0
          1996 "AR"  2.930427    0
          1997 "AR"  2.566672    0
          1998 "AR"  2.713423    0
          1999 "AR"  1.757973   20
          2000 "AR"   .820514   50
          2001 "AR"  1.731663   40
          2002 "AR"   .433283   29
          2003 "AR"   .693137   33
          2004 "AR"   .537529   17
          2005 "AR"  1.334015   65
          2006 "AR"  1.607395   36
          2007 "AR"  5.205558  141
          2008 "AR" 13.348274  150
          2009 "AR"  2.953936   45
          2010 "AR"  8.285274   96
          2011 "AR" 22.273457  407
          2012 "AR" 15.632359  180
          2013 "AR" 13.275552  181
          2014 "AR" 10.507074    0
          2015 "AR" 14.350166    0
          2016 "AR" 11.726218    0
          2017 "AR" 16.001951    0
          2018 "AR"  9.526949    0
          2019 "AR" 15.542093    0
          1996 "AT"  9.284512  277
          1997 "AT" 11.324429  232
          1998 "AT"  11.18832  145
          1999 "AT" 16.971384  273
          2000 "AT"  37.53419  320
          2001 "AT" 16.574034  330
          2002 "AT" 16.691013  670
          2003 "AT"  14.51144  365
          2004 "AT" 24.916763  545
          2005 "AT"  25.72232  485
          2006 "AT" 35.112324  498
          2007 "AT"  38.49554  621
          2008 "AT"  46.18709  638
          2009 "AT"  41.32523  508
          2010 "AT"  36.71757  496
          2011 "AT"  43.99167  628
          2012 "AT"  40.30826  835
          2013 "AT"   40.7037  720
          2014 "AT"  51.64431  898
          2015 "AT"  48.09217  987
          2016 "AT"   73.0638 1686
          2017 "AT"     81.19 1641
          2018 "AT"  82.17607 1504
          2019 "AT"  74.40486 1475
          1996 "AU"  4.763878  250
          1997 "AU" 10.905708  526
          1998 "AU"  6.894873  347
          1999 "AU"  8.601764  180
          2000 "AU"  8.956798  440
          2001 "AU" 10.291573  270
          2002 "AU"  13.03586  421
          2003 "AU" 17.182116  569
          2004 "AU" 28.043364  652
          2005 "AU"  29.79912  890
          2006 "AU" 19.709654  719
          2007 "AU"  26.95258  734
          2008 "AU"  20.39395  781
          2009 "AU"  8.937055  399
          2010 "AU" 13.016978  624
          2011 "AU"  17.47799  690
          2012 "AU"   22.5622 1214
          2013 "AU"  13.40527  323
          2014 "AU" 11.591695    0
          2015 "AU" 13.899048    0
          2016 "AU"  16.18698    0
          2017 "AU" 19.643173    0
          2018 "AU"  28.74417    0
          2019 "AU" 18.894983    0
          2003 "BA"     .0334    0
          2004 "BA"   .166554    0
          2005 "BA"   .074738    0
          2006 "BA"   .260394    0
          2007 "BA"   .535262    0
          2008 "BA"   .677682    0
          2009 "BA"  1.532421    0
          2010 "BA"   .381561    2
          2011 "BA"  3.805619    2
          2012 "BA"   .817377    0
          2013 "BA"   .587407    0
          2014 "BA"  1.019831    0
          2015 "BA"   .604327    0
          2016 "BA"   .752781    0
          2017 "BA"  1.305355    0
          2018 "BA"  1.188319    0
          2019 "BA"  2.205264    0
          end
          
          levelsof country, local(levels)
          
          local graph ""
          
          foreach i of local levels {
              summarize net_tradevalue_m if country == "`i'", meanonly
              local y_min = `r(min)'
              local y_max = `r(max)'
              
              local y_min_r = round(`y_min')
              local y_max_r = round(`y_max')
              
              scatter net_tradevalue_m instal if country == "`i'", ///
              xtitle("Number of items installed") ///
              ytitle("Import value (US$) net of re-exports") ///
              yscale(range(`y_min' `y_max')) ylabel(`y_min_r' `y_max_r') ///
              title("`i'") name(g_`i', replace)
              local graph "`graph' g_`i'"
          }
          
          grc1leg2 `graph', xtob1title ytol1title ytsize(vsmall)

          Comment


          • #6
            Dear Andrew, thanks for your response! So it worked out for you when leaving out labsize()? Mysterious... I tried it without option labsize and even without any option, but the problem does persist and I get the error message "Series 0 not found".

            Comment


            • #7
              Nick Cox: Many thanks for your hint! I was able to build a nice graph.

              However, I am still puzzled why my code seems to be non-functional only in this specific context.

              Comment


              • #8
                Originally posted by Florian Schneider View Post
                Dear Andrew, thanks for your response! So it worked out for you when leaving out labsize()? Mysterious... I tried it without option labsize and even without any option, but the problem does persist and I get the error message "Series 0 not found".
                I had an older version. Updating to the latest, I can replicate your error with the code in #5. So I would say that this occurs within the last 2 updates.

                Code:
                . which grc1leg2
                c:\ado\plus\g\grc1leg2.ado
                *! version 1.42 29Mar2021, by Mead Over
                *! based on -grc1leg- version 1.0.5  02jun2010, by Vince Wiggins

                Comment


                • #9
                  Thanks to Florian Schneider and Andrew Musau for flagging this problem. I think Nick Cox 's suggestion to Florian to use gr ..., by(..., yrescale xrescale) is a good solution. And his new program -myaxis- is cool, Meanwhile I am trying to figure out this problem with -grc1leg2-. As I emphasize in the help file for -grc1leg2-, its approach to creating a combined graph with a single legend is best used only when -gr ..., by()- won't work.

                  Comment


                  • #10
                    Andrew Musau is correct that the bug that Florian Schneider found dates back to version 1.41 which I distributed this year on March 26. In the process of fixing this bug, I've discovered that -grc1leg2- has difficulty editing certain characteristics of the keys of a legend that is too simple, i.e. that has too few keys. I don't expect this problem to arise for most users because (a) most will not attempt to edit the characteristics of legend keys and (b) a legend with only a single key is typically uninformative and should usually be suppressed. In the new version 1.5 of -grc1leg2-, I've added a rubric to the help file documenting this "Known Issue" and suggesting work-arounds. As always, please contact me if you see remaining issues with the program - or if you can suggest how to trap the serset error "series # not found".
                    Last edited by Mead Over; 04 Apr 2021, 21:21.

                    Comment


                    • #11
                      I don't know if this is helpful to Mead Over or others, and it's perhaps not surprising, but I get this error with the original -grc1leg- as well. Only it shows up as "series 2 not found" (rather than series 0, above), and seems to be an issue when there are few keys provided by the user, as previously noted. After this error is tripped, then seems to cause errors in any subsequent uses of -graph combine- or commands like -grc1leg- that wrap it. I cleared and re-ran my code after changing -grc1leg- to -graph combine- and it worked fine, but that sacrifices the -grc1leg- functionality.

                      Comment

                      Working...
                      X