Announcement

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

  • Using different markers for each line in a graph

    Dear all,

    I graph emission data for ,say 30, countries. As colors are not enough to separate countries from each other, I want to use markers. I want each country to have a different symbol. Here is a small sample of my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str24 country int year double emission float id
    "Afghanistan" 1995 920.74704 1
    "Afghanistan" 1996 939.65816 1
    "Afghanistan" 1997 1029.1133 1
    "Afghanistan" 1998 1047.1674 1
    "Afghanistan" 1999 880.55764 1
    "Afghanistan" 2000 478.10435 1
    "Afghanistan" 2001  418.2312 1
    "Afghanistan" 2002 525.85404 1
    "Afghanistan" 2003 588.07605 1
    "Antigua"     1995 12024.509 2
    "Antigua"     1996 12438.551 2
    "Antigua"     1997 12949.813 2
    "Antigua"     1998 13666.697 2
    "Antigua"     1999 14056.152 2
    "Antigua"     2000  14064.74 2
    "Antigua"     2001 14316.295 2
    "Antigua"     2002 15270.916 2
    "Antigua"     2003 15820.542 2
    "Argentina"   1995 10573.171 3
    "Argentina"   1996 10910.546 3
    "Argentina"   1997  11604.96 3
    "Argentina"   1998 11932.882 3
    "Argentina"   1999 11586.602 3
    "Argentina"   2000 11331.958 3
    "Argentina"   2001 10690.723 3
    "Argentina"   2002 9561.1764 3
    "Argentina"   2003 10172.063 3
    "Australia"   1995 22648.291 4
    "Australia"   1996 23271.226 4
    "Australia"   1997 24010.643 4
    "Australia"   1998 24950.277 4
    "Australia"   1999 25658.207 4
    "Australia"   2000  25834.54 4
    "Australia"   2001 26528.388 4
    "Australia"   2002 27119.407 4
    "Australia"   2003 27871.535 4
    "Bahamas"     1995 17111.225 5
    "Bahamas"     1996 16741.521 5
    "Bahamas"     1997 16624.036 5
    "Bahamas"     1998 16705.854 5
    "Bahamas"     1999 18425.053 5
    "Bahamas"     2000 19088.042 5
    "Bahamas"     2001 18533.119 5
    "Bahamas"     2002 18377.338 5
    "Bahamas"     2003 18381.131 5
    "Bahrain"     1995 16906.196 6
    "Bahrain"     1996 16865.345 6
    "Bahrain"     1997 16889.001 6
    "Bahrain"     1998 17048.288 6
    "Bahrain"     1999 18054.555 6
    "Bahrain"     2000 18652.151 6
    "Bahrain"     2001 19093.738 6
    "Bahrain"     2002  18882.95 6
    "Bahrain"     2003   19560.6 6
    "Barbados"    1995 14020.479 7
    "Barbados"    1996 14237.518 7
    "Barbados"    1997 14539.566 7
    "Barbados"    1998 15050.467 7
    "Barbados"    1999 15537.087 7
    "Barbados"    2000     16086 7
    "Barbados"    2001 15497.756 7
    "Barbados"    2002 15450.672 7
    "Barbados"    2003 15707.709 7
    "Belgium"     1995 21936.724 8
    "Belgium"     1996 22093.781 8
    "Belgium"     1997  22786.21 8
    "Belgium"     1998 23163.219 8
    "Belgium"     1999 23793.334 8
    "Belgium"     2000 24661.914 8
    "Belgium"     2001 24821.924 8
    "Belgium"     2002 25105.985 8
    "Belgium"     2003 25262.252 8
    end
    Here is what I come up with:
    Code:
    xtset id year
    xtline emission, overlay recast (connected)  plot1opts(ms(Oh)) plot2opts(ms(Th)) plot3opts(ms(T)) plot4opts(ms(+)) plot5opts(ms(-))
    and the result:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	77.4 KB
ID:	1759188


    2 questions, please. First, I want to let Stata know the countries by using id but when I plot the graph I want to see country names instead of ids. A side way to do this is to encode the country as country1 and then "xtset country1 year" and then plot the graph, which works fine. But is there a way to show country names in the legend, even in the case of using the "xtset id year" command?

    Secondly and more importantly, when I have 20 countries, do I have to type starting from plot1opts(ms(Oh)) to all the way to plot20opts(ms(-)) one by one to differentiate the markers? Is there not a short command to let these markers vary regardless of the number of countries?

    I really appreciate any insights. Thanks much.

  • #2
    First, I want to let Stata know the countries by using id but when I plot the graph I want to see country names instead of ids. A side way to do this is to encode the country as country1 and then "xtset country1 year" and then plot the graph, which works fine. But is there a way to show country names in the legend, even in the case of using the "xtset id year" command?
    Encode country and use that for your xtset

    Code:
    encode country, gen(cid)
    xtset cid year
    xtline emission, overlay
    As for your second question, I’m not sure how to get around hardcoding all the markers. It might be hard to differentiate 30 countries on a single chart. See this thread for some suggestions

    https://www.statalist.org/forums/for...using-linkplot

    One approach is to use fabplot (Stata Journal). Two rows works with your data example, but probably not the full set.

    Code:
    gen ln_ = ln(emission)
    fabplot line ln_ year, by(country, compact rows(2)) xlab(`=year[1]' `=year[_N-1]') xtitle("") front(connected) ytitle(ln(Emissions))

    Comment


    • #3
      It's a little hard to follow what is being asked here. For 30 -- or is it 20 -- countries or so, different colours, different markers and use of a legend are all more or less doomed to failure. I can't see that different markers or a better legend will not create as many problems as they solve.

      20 different colours can easily be defined but the real question is can they be defined in a way that can be decoded by readers (including the researcher) easily and effectively? It is no real help -- although goodness knows it seems to be often done -- to produce a graph that in principle shows different groups (here different countries) in different ways but is such a tangled mess that the typical reader just thinks "Well, I could come back to the graph and try to puzzle it out, but right now I don't have the time and inclination".

      20 different markers -- which I suppose may include filled or open and markers in different colours -- same story.

      A legend (key if you prefer) is at best a necessary evil. A legend with say 2, 3 or 4 items is not too much pain and doesn't take up too much space but neither is true for 20 or 30 items.

      Justin Niakamal gives some excellent pointers (including to my own work!).

      Here I pick up Justin's suggestion of a front-and-back plot as implemented through fabplot from the Stata Journal.

      The data example in #1 gives the flavour of the data here but with just 8 countries the eample is not large enough to see easily what would work well with 20 or 30 countries.

      For something similar I downloaded data from https://ourworldindata.org/co2-emissions and chose 20 countries from Latin America for greenhouse gas emissions. It's a little long by Statalist standards but I will give a complete data example in the next post.

      My main tips are

      * Using many colours and/or many different markers or line patterns is often just confusing. By giving everything separate emphasis you can even make it harder to see interesting or important details, not easier.

      * For most outcome variables, log scale is your friend. Even if log scale isn't applicable or helpful, some other transformed scale may help. But show axis labels in units that make most sense.

      * DIrect labelling is positive, which means informative text as near as possible to the data elements. Lose the legend! (kill the key!) (if you can).

      * Juxtaposition (series side by side) and superimposition (series in the same space) have opposite advantages and disadvantages. So try both, which is what a front-and-back plot does.

      * Using alphabetical order is dopey outside compilation of dictionaries and directories. Sort on some criterion you care about (means, medians, latest values, you choose).

      * Using numeric identifiers is almost always pointless. (Just possibly, flagging that patient 42 is puzzling is helpful to the clinician who can ethically break the code and check what is going on.)

      * If somebody needs to be told that 1990 2000 2010 2020 mean years, they are in the wrong place.

      Various efforts ended up on the cutting room floor, but here is my best stab from one session.

      Code:
      use lam_ghg_sandbox.dta, clear
      
      myaxis country2 = country, sort(mean ghg) descending subset(year == 2020)
      
      fabplot line ghg year, by(country2, compact) xtitle("") xla(, labsize(medlarge)) frontopts(lw(thick)) ysc(log) yla(30 10 3 1) xsc(r(1988, 2022))


      The .dta file is as given in the next post.

      myaxis is for sorting groups into a congenial if not compelling order. Here I used the latest values (the mean of one value, for 2020, is precisely that value).


      Code:
      .
      
      SJ-21-3 st0654  . . Speaking Stata: Ordering or ranking groups of observations
              (help myaxis if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
              Q3/21   SJ 21(3):818--837
              discusses procedures for datasets based on aggregate
              frequencies and for datasets based on individuals and
              introduce a new convenience command, myaxis, that handles
              many cases directly
      fabplot is for front-and-back plots. The name is mine, but the idea is much older than my publications on it.

      Code:
      SJ-21-2 gr0087  . . Front-and-back plots to ease spaghetti and paella problems
              (help fabplot if installed) . . . . . . . . . . . . . . . .  N. J. Cox
              Q2/21   SJ 21(2):539--554
              explores front-and-back plots, in which each subset of data
              is shown separately with the other subsets as backdrop
      30 might work, just about. A minute detail is that 20 permits a tidy 5 x 4 or 4 x 5 layout.
      Click image for larger version

Name:	ghg.png
Views:	1
Size:	600.8 KB
ID:	1759218

      Comment


      • #4
        This is the dataset used in #3. The units of the outcome are tonnes per head in each year.

        Code:
         
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str40 country int year str3 iso_code double ghg_per_capita
        "Argentina"          1990 "ARG"  9.094
        "Argentina"          1991 "ARG"  9.101
        "Argentina"          1992 "ARG"  9.122
        "Argentina"          1993 "ARG"  9.024
        "Argentina"          1994 "ARG"  9.012
        "Argentina"          1995 "ARG"  8.974
        "Argentina"          1996 "ARG"  9.192
        "Argentina"          1997 "ARG"  9.239
        "Argentina"          1998 "ARG"  9.279
        "Argentina"          1999 "ARG"  9.378
        "Argentina"          2000 "ARG"  9.254
        "Argentina"          2001 "ARG" 10.284
        "Argentina"          2002 "ARG" 10.079
        "Argentina"          2003 "ARG" 10.556
        "Argentina"          2004 "ARG" 10.864
        "Argentina"          2005 "ARG" 10.842
        "Argentina"          2006 "ARG" 11.099
        "Argentina"          2007 "ARG" 11.295
        "Argentina"          2008 "ARG" 11.298
        "Argentina"          2009 "ARG" 10.679
        "Argentina"          2010 "ARG" 10.706
        "Argentina"          2011 "ARG" 10.139
        "Argentina"          2012 "ARG" 10.156
        "Argentina"          2013 "ARG" 10.285
        "Argentina"          2014 "ARG" 10.124
        "Argentina"          2015 "ARG" 10.183
        "Argentina"          2016 "ARG"   9.34
        "Argentina"          2017 "ARG"  9.357
        "Argentina"          2018 "ARG"  9.239
        "Argentina"          2019 "ARG"  9.088
        "Argentina"          2020 "ARG"  8.765
        "Bolivia"            1990 "BOL" 16.048
        "Bolivia"            1991 "BOL" 15.873
        "Bolivia"            1992 "BOL" 15.662
        "Bolivia"            1993 "BOL" 15.183
        "Bolivia"            1994 "BOL" 14.781
        "Bolivia"            1995 "BOL"  14.32
        "Bolivia"            1996 "BOL" 13.999
        "Bolivia"            1997 "BOL" 14.045
        "Bolivia"            1998 "BOL" 13.787
        "Bolivia"            1999 "BOL" 14.217
        "Bolivia"            2000 "BOL" 12.848
        "Bolivia"            2001 "BOL" 10.301
        "Bolivia"            2002 "BOL" 10.894
        "Bolivia"            2003 "BOL" 10.303
        "Bolivia"            2004 "BOL" 11.779
        "Bolivia"            2005 "BOL" 10.937
        "Bolivia"            2006 "BOL"  10.95
        "Bolivia"            2007 "BOL" 11.401
        "Bolivia"            2008 "BOL" 10.536
        "Bolivia"            2009 "BOL" 10.162
        "Bolivia"            2010 "BOL" 12.532
        "Bolivia"            2011 "BOL" 10.871
        "Bolivia"            2012 "BOL" 10.739
        "Bolivia"            2013 "BOL" 10.547
        "Bolivia"            2014 "BOL" 10.401
        "Bolivia"            2015 "BOL" 10.563
        "Bolivia"            2016 "BOL" 11.381
        "Bolivia"            2017 "BOL" 11.041
        "Bolivia"            2018 "BOL" 10.914
        "Bolivia"            2019 "BOL" 11.818
        "Bolivia"            2020 "BOL" 11.011
        "Brazil"             1990 "BRA" 10.903
        "Brazil"             1991 "BRA" 10.853
        "Brazil"             1992 "BRA" 10.739
        "Brazil"             1993 "BRA" 10.639
        "Brazil"             1994 "BRA" 10.576
        "Brazil"             1995 "BRA" 10.576
        "Brazil"             1996 "BRA" 10.436
        "Brazil"             1997 "BRA" 10.469
        "Brazil"             1998 "BRA" 10.525
        "Brazil"             1999 "BRA" 10.442
        "Brazil"             2000 "BRA" 10.314
        "Brazil"             2001 "BRA" 10.684
        "Brazil"             2002 "BRA" 10.758
        "Brazil"             2003 "BRA" 10.707
        "Brazil"             2004 "BRA"  10.84
        "Brazil"             2005 "BRA" 10.797
        "Brazil"             2006 "BRA" 10.629
        "Brazil"             2007 "BRA" 10.717
        "Brazil"             2008 "BRA" 10.615
        "Brazil"             2009 "BRA" 10.373
        "Brazil"             2010 "BRA" 10.812
        "Brazil"             2011 "BRA"   6.49
        "Brazil"             2012 "BRA"  6.653
        "Brazil"             2013 "BRA"  6.713
        "Brazil"             2014 "BRA"  6.861
        "Brazil"             2015 "BRA"  6.725
        "Brazil"             2016 "BRA"  7.079
        "Brazil"             2017 "BRA"  7.127
        "Brazil"             2018 "BRA"  6.867
        "Brazil"             2019 "BRA"  6.929
        "Brazil"             2020 "BRA"  6.893
        "Chile"              1990 "CHL"  2.161
        "Chile"              1991 "CHL"  2.043
        "Chile"              1992 "CHL"  2.126
        "Chile"              1993 "CHL"  2.285
        "Chile"              1994 "CHL"  2.537
        "Chile"              1995 "CHL"  2.757
        "Chile"              1996 "CHL"  3.163
        "Chile"              1997 "CHL"  3.607
        "Chile"              1998 "CHL"  3.631
        "Chile"              1999 "CHL"   3.78
        "Chile"              2000 "CHL"  3.477
        "Chile"              2001 "CHL"   2.09
        "Chile"              2002 "CHL"  2.113
        "Chile"              2003 "CHL"  2.135
        "Chile"              2004 "CHL"  2.449
        "Chile"              2005 "CHL"  2.465
        "Chile"              2006 "CHL"  2.519
        "Chile"              2007 "CHL"  2.964
        "Chile"              2008 "CHL"  3.228
        "Chile"              2009 "CHL"  3.047
        "Chile"              2010 "CHL"  3.317
        "Chile"              2011 "CHL"  1.028
        "Chile"              2012 "CHL"  1.157
        "Chile"              2013 "CHL"  1.326
        "Chile"              2014 "CHL"   .898
        "Chile"              2015 "CHL"  1.232
        "Chile"              2016 "CHL"  2.735
        "Chile"              2017 "CHL"  2.796
        "Chile"              2018 "CHL"  2.682
        "Chile"              2019 "CHL"  2.961
        "Chile"              2020 "CHL"  2.575
        "Colombia"           1990 "COL"   6.67
        "Colombia"           1991 "COL"  6.577
        "Colombia"           1992 "COL"  6.541
        "Colombia"           1993 "COL"  6.557
        "Colombia"           1994 "COL"  6.501
        "Colombia"           1995 "COL"  6.495
        "Colombia"           1996 "COL"  6.379
        "Colombia"           1997 "COL"   6.43
        "Colombia"           1998 "COL"  6.374
        "Colombia"           1999 "COL"   5.97
        "Colombia"           2000 "COL"   5.98
        "Colombia"           2001 "COL"  5.618
        "Colombia"           2002 "COL"  5.484
        "Colombia"           2003 "COL"  5.447
        "Colombia"           2004 "COL"  5.416
        "Colombia"           2005 "COL"  5.356
        "Colombia"           2006 "COL"  5.306
        "Colombia"           2007 "COL"  5.367
        "Colombia"           2008 "COL"  5.334
        "Colombia"           2009 "COL"  5.354
        "Colombia"           2010 "COL"  5.411
        "Colombia"           2011 "COL"  4.911
        "Colombia"           2012 "COL"  4.818
        "Colombia"           2013 "COL"   4.95
        "Colombia"           2014 "COL"  4.982
        "Colombia"           2015 "COL"  4.919
        "Colombia"           2016 "COL"  5.504
        "Colombia"           2017 "COL"  5.326
        "Colombia"           2018 "COL"  5.413
        "Colombia"           2019 "COL"  5.371
        "Colombia"           2020 "COL"  5.307
        "Costa Rica"         1990 "CRI"  3.458
        "Costa Rica"         1991 "CRI"  3.464
        "Costa Rica"         1992 "CRI"  3.721
        "Costa Rica"         1993 "CRI"  3.653
        "Costa Rica"         1994 "CRI"  3.686
        "Costa Rica"         1995 "CRI"  3.485
        "Costa Rica"         1996 "CRI"  3.397
        "Costa Rica"         1997 "CRI"  3.335
        "Costa Rica"         1998 "CRI"  3.452
        "Costa Rica"         1999 "CRI"   3.33
        "Costa Rica"         2000 "CRI"  3.227
        "Costa Rica"         2001 "CRI"  2.526
        "Costa Rica"         2002 "CRI"  2.486
        "Costa Rica"         2003 "CRI"  2.535
        "Costa Rica"         2004 "CRI"    2.5
        "Costa Rica"         2005 "CRI"  2.586
        "Costa Rica"         2006 "CRI"  2.624
        "Costa Rica"         2007 "CRI"  2.905
        "Costa Rica"         2008 "CRI"  2.897
        "Costa Rica"         2009 "CRI"  2.763
        "Costa Rica"         2010 "CRI"  2.756
        "Costa Rica"         2011 "CRI"  1.412
        "Costa Rica"         2012 "CRI"  1.393
        "Costa Rica"         2013 "CRI"  1.484
        "Costa Rica"         2014 "CRI"  1.468
        "Costa Rica"         2015 "CRI"  1.436
        "Costa Rica"         2016 "CRI"  1.583
        "Costa Rica"         2017 "CRI"  1.626
        "Costa Rica"         2018 "CRI"  1.672
        "Costa Rica"         2019 "CRI"  1.652
        "Costa Rica"         2020 "CRI"  1.382
        "Cuba"               1990 "CUB"  4.134
        "Cuba"               1991 "CUB"  3.244
        "Cuba"               1992 "CUB"  2.649
        "Cuba"               1993 "CUB"  2.316
        "Cuba"               1994 "CUB"  2.438
        "Cuba"               1995 "CUB"  2.532
        "Cuba"               1996 "CUB"  2.767
        "Cuba"               1997 "CUB"  2.962
        "Cuba"               1998 "CUB"  2.909
        "Cuba"               1999 "CUB"  2.938
        "Cuba"               2000 "CUB"  2.958
        "Cuba"               2001 "CUB"  2.911
        "Cuba"               2002 "CUB"  2.794
        "Cuba"               2003 "CUB"  2.706
        "Cuba"               2004 "CUB"  2.649
        "Cuba"               2005 "CUB"  2.653
        "Cuba"               2006 "CUB"  2.735
        "Cuba"               2007 "CUB"  2.815
        "Cuba"               2008 "CUB"  2.753
        "Cuba"               2009 "CUB"   2.83
        "Cuba"               2010 "CUB"  2.929
        "Cuba"               2011 "CUB"  2.705
        "Cuba"               2012 "CUB"  2.796
        "Cuba"               2013 "CUB"  2.825
        "Cuba"               2014 "CUB"  2.634
        "Cuba"               2015 "CUB"   2.81
        "Cuba"               2016 "CUB"  3.486
        "Cuba"               2017 "CUB"  3.374
        "Cuba"               2018 "CUB"  3.415
        "Cuba"               2019 "CUB"  3.209
        "Cuba"               2020 "CUB"  3.152
        "Dominican Republic" 1990 "DOM"  1.192
        "Dominican Republic" 1991 "DOM"  1.322
        "Dominican Republic" 1992 "DOM"  1.493
        "Dominican Republic" 1993 "DOM"   1.53
        "Dominican Republic" 1994 "DOM"  1.757
        "Dominican Republic" 1995 "DOM"  1.788
        "Dominican Republic" 1996 "DOM"  1.871
        "Dominican Republic" 1997 "DOM"  2.045
        "Dominican Republic" 1998 "DOM"  2.247
        "Dominican Republic" 1999 "DOM"  2.284
        "Dominican Republic" 2000 "DOM"  2.331
        "Dominican Republic" 2001 "DOM"  3.001
        "Dominican Republic" 2002 "DOM"  3.235
        "Dominican Republic" 2003 "DOM"  2.928
        "Dominican Republic" 2004 "DOM"   2.81
        "Dominican Republic" 2005 "DOM"  2.917
        "Dominican Republic" 2006 "DOM"  3.086
        "Dominican Republic" 2007 "DOM"  3.175
        "Dominican Republic" 2008 "DOM"   3.15
        "Dominican Republic" 2009 "DOM"  3.057
        "Dominican Republic" 2010 "DOM"  3.156
        "Dominican Republic" 2011 "DOM"   3.23
        "Dominican Republic" 2012 "DOM"   3.27
        "Dominican Republic" 2013 "DOM"  3.207
        "Dominican Republic" 2014 "DOM"  3.202
        "Dominican Republic" 2015 "DOM"  3.397
        "Dominican Republic" 2016 "DOM"  3.439
        "Dominican Republic" 2017 "DOM"   3.33
        "Dominican Republic" 2018 "DOM"  3.502
        "Dominican Republic" 2019 "DOM"   3.51
        "Dominican Republic" 2020 "DOM"  3.227
        "Ecuador"            1990 "ECU"  7.091
        "Ecuador"            1991 "ECU"  7.002
        "Ecuador"            1992 "ECU"  7.088
        "Ecuador"            1993 "ECU"  7.098
        "Ecuador"            1994 "ECU"  7.251
        "Ecuador"            1995 "ECU"   7.33
        "Ecuador"            1996 "ECU"  7.547
        "Ecuador"            1997 "ECU"  7.571
        "Ecuador"            1998 "ECU"  7.299
        "Ecuador"            1999 "ECU"  6.945
        "Ecuador"            2000 "ECU"  6.777
        "Ecuador"            2001 "ECU"  6.441
        "Ecuador"            2002 "ECU"  6.298
        "Ecuador"            2003 "ECU"  6.281
        "Ecuador"            2004 "ECU"  6.494
        "Ecuador"            2005 "ECU"  6.508
        "Ecuador"            2006 "ECU"  6.576
        "Ecuador"            2007 "ECU"  6.434
        "Ecuador"            2008 "ECU"  6.445
        "Ecuador"            2009 "ECU"  6.569
        "Ecuador"            2010 "ECU"    6.7
        "Ecuador"            2011 "ECU"   5.85
        "Ecuador"            2012 "ECU"  5.749
        "Ecuador"            2013 "ECU"  5.858
        "Ecuador"            2014 "ECU"  5.879
        "Ecuador"            2015 "ECU"   5.69
        "Ecuador"            2016 "ECU"  6.097
        "Ecuador"            2017 "ECU"  5.921
        "Ecuador"            2018 "ECU"  5.883
        "Ecuador"            2019 "ECU"  5.781
        "Ecuador"            2020 "ECU"  5.355
        "El Salvador"        1990 "SLV"  1.479
        "El Salvador"        1991 "SLV"  1.599
        "El Salvador"        1992 "SLV"  1.641
        "El Salvador"        1993 "SLV"  1.701
        "El Salvador"        1994 "SLV"  1.792
        "El Salvador"        1995 "SLV"   1.82
        "El Salvador"        1996 "SLV"  1.796
        "El Salvador"        1997 "SLV"  1.929
        "El Salvador"        1998 "SLV"  1.935
        "El Salvador"        1999 "SLV"  1.958
        "El Salvador"        2000 "SLV"   1.88
        "El Salvador"        2001 "SLV"  1.979
        "El Salvador"        2002 "SLV"   2.01
        "El Salvador"        2003 "SLV"  2.099
        "El Salvador"        2004 "SLV"  2.156
        "El Salvador"        2005 "SLV"  2.219
        "El Salvador"        2006 "SLV"    2.3
        "El Salvador"        2007 "SLV"  2.391
        "El Salvador"        2008 "SLV"  2.289
        "El Salvador"        2009 "SLV"   2.22
        "El Salvador"        2010 "SLV"   2.17
        "El Salvador"        2011 "SLV"  2.148
        "El Salvador"        2012 "SLV"  2.165
        "El Salvador"        2013 "SLV"  2.035
        "El Salvador"        2014 "SLV"  2.071
        "El Salvador"        2015 "SLV"  2.139
        "El Salvador"        2016 "SLV"   2.12
        "El Salvador"        2017 "SLV"  1.977
        "El Salvador"        2018 "SLV"  2.028
        "El Salvador"        2019 "SLV"  2.164
        "El Salvador"        2020 "SLV"  1.931
        "Guatemala"          1990 "GTM"  3.071
        "Guatemala"          1991 "GTM"   3.03
        "Guatemala"          1992 "GTM"  3.077
        "Guatemala"          1993 "GTM"  3.064
        "Guatemala"          1994 "GTM"  3.003
        "Guatemala"          1995 "GTM"  3.025
        "Guatemala"          1996 "GTM"  2.973
        "Guatemala"          1997 "GTM"  2.922
        "Guatemala"          1998 "GTM"  3.178
        "Guatemala"          1999 "GTM"  2.983
        "Guatemala"          2000 "GTM"  3.108
        "Guatemala"          2001 "GTM"  2.757
        "Guatemala"          2002 "GTM"  2.799
        "Guatemala"          2003 "GTM"  2.899
        "Guatemala"          2004 "GTM"  2.722
        "Guatemala"          2005 "GTM"  2.843
        "Guatemala"          2006 "GTM"  2.718
        "Guatemala"          2007 "GTM"  2.786
        "Guatemala"          2008 "GTM"   2.63
        "Guatemala"          2009 "GTM"  2.698
        "Guatemala"          2010 "GTM"  2.627
        "Guatemala"          2011 "GTM"  2.209
        "Guatemala"          2012 "GTM"  2.211
        "Guatemala"          2013 "GTM"  2.251
        "Guatemala"          2014 "GTM"  2.273
        "Guatemala"          2015 "GTM"  2.424
        "Guatemala"          2016 "GTM"  2.199
        "Guatemala"          2017 "GTM"  2.124
        "Guatemala"          2018 "GTM"  2.184
        "Guatemala"          2019 "GTM"  2.233
        "Guatemala"          2020 "GTM"  2.118
        "Haiti"              1990 "HTI"    .78
        "Haiti"              1991 "HTI"   .794
        "Haiti"              1992 "HTI"   .835
        "Haiti"              1993 "HTI"   .769
        "Haiti"              1994 "HTI"   .687
        "Haiti"              1995 "HTI"   .776
        "Haiti"              1996 "HTI"     .8
        "Haiti"              1997 "HTI"   .836
        "Haiti"              1998 "HTI"    .84
        "Haiti"              1999 "HTI"   .842
        "Haiti"              2000 "HTI"   .884
        "Haiti"              2001 "HTI"   .889
        "Haiti"              2002 "HTI"   .909
        "Haiti"              2003 "HTI"   .898
        "Haiti"              2004 "HTI"   .869
        "Haiti"              2005 "HTI"   .866
        "Haiti"              2006 "HTI"   .858
        "Haiti"              2007 "HTI"   .888
        "Haiti"              2008 "HTI"   .877
        "Haiti"              2009 "HTI"   .868
        "Haiti"              2010 "HTI"   .915
        "Haiti"              2011 "HTI"   .996
        "Haiti"              2012 "HTI"   .957
        "Haiti"              2013 "HTI"   .971
        "Haiti"              2014 "HTI"   .997
        "Haiti"              2015 "HTI"  1.017
        "Haiti"              2016 "HTI"  1.024
        "Haiti"              2017 "HTI"  1.008
        "Haiti"              2018 "HTI"   .983
        "Haiti"              2019 "HTI"   .982
        "Haiti"              2020 "HTI"   .964
        "Honduras"           1990 "HND"  3.422
        "Honduras"           1991 "HND"  3.348
        "Honduras"           1992 "HND"  3.314
        "Honduras"           1993 "HND"  3.187
        "Honduras"           1994 "HND"   3.22
        "Honduras"           1995 "HND"  3.263
        "Honduras"           1996 "HND"   3.09
        "Honduras"           1997 "HND"  3.073
        "Honduras"           1998 "HND"   3.08
        "Honduras"           1999 "HND"  2.822
        "Honduras"           2000 "HND"  2.821
        "Honduras"           2001 "HND"  2.751
        "Honduras"           2002 "HND"  2.744
        "Honduras"           2003 "HND"  3.092
        "Honduras"           2004 "HND"   2.92
        "Honduras"           2005 "HND"  2.973
        "Honduras"           2006 "HND"  2.941
        "Honduras"           2007 "HND"  2.969
        "Honduras"           2008 "HND"  2.933
        "Honduras"           2009 "HND"  2.872
        "Honduras"           2010 "HND"  2.804
        "Honduras"           2011 "HND"  3.085
        "Honduras"           2012 "HND"  3.023
        "Honduras"           2013 "HND"  3.002
        "Honduras"           2014 "HND"  3.005
        "Honduras"           2015 "HND"  3.015
        "Honduras"           2016 "HND"  2.957
        "Honduras"           2017 "HND"  2.764
        "Honduras"           2018 "HND"   2.74
        "Honduras"           2019 "HND"  2.801
        "Honduras"           2020 "HND"  2.734
        "Mexico"             1990 "MEX"  5.316
        "Mexico"             1991 "MEX"  5.443
        "Mexico"             1992 "MEX"  5.373
        "Mexico"             1993 "MEX"  5.472
        "Mexico"             1994 "MEX"  5.671
        "Mexico"             1995 "MEX"  5.336
        "Mexico"             1996 "MEX"  5.451
        "Mexico"             1997 "MEX"  5.615
        "Mexico"             1998 "MEX"  5.873
        "Mexico"             1999 "MEX"  5.609
        "Mexico"             2000 "MEX"  5.797
        "Mexico"             2001 "MEX"  4.777
        "Mexico"             2002 "MEX"  4.808
        "Mexico"             2003 "MEX"  4.999
        "Mexico"             2004 "MEX"  4.997
        "Mexico"             2005 "MEX"  5.153
        "Mexico"             2006 "MEX"  5.268
        "Mexico"             2007 "MEX"  5.304
        "Mexico"             2008 "MEX"  5.271
        "Mexico"             2009 "MEX"  5.111
        "Mexico"             2010 "MEX"  5.193
        "Mexico"             2011 "MEX"  6.028
        "Mexico"             2012 "MEX"   5.99
        "Mexico"             2013 "MEX"  5.799
        "Mexico"             2014 "MEX"  5.668
        "Mexico"             2015 "MEX"  5.737
        "Mexico"             2016 "MEX"  5.749
        "Mexico"             2017 "MEX"  5.668
        "Mexico"             2018 "MEX"  5.374
        "Mexico"             2019 "MEX"  5.411
        "Mexico"             2020 "MEX"  4.834
        "Nicaragua"          1990 "NIC"   6.89
        "Nicaragua"          1991 "NIC"  6.415
        "Nicaragua"          1992 "NIC"  6.476
        "Nicaragua"          1993 "NIC"  6.479
        "Nicaragua"          1994 "NIC"  6.408
        "Nicaragua"          1995 "NIC"  6.148
        "Nicaragua"          1996 "NIC"  6.032
        "Nicaragua"          1997 "NIC"  6.101
        "Nicaragua"          1998 "NIC"  6.196
        "Nicaragua"          1999 "NIC"  6.214
        "Nicaragua"          2000 "NIC"  6.236
        "Nicaragua"          2001 "NIC"  6.942
        "Nicaragua"          2002 "NIC"   6.94
        "Nicaragua"          2003 "NIC"  7.084
        "Nicaragua"          2004 "NIC"  6.895
        "Nicaragua"          2005 "NIC"  6.902
        "Nicaragua"          2006 "NIC"  6.834
        "Nicaragua"          2007 "NIC"  6.768
        "Nicaragua"          2008 "NIC"  6.653
        "Nicaragua"          2009 "NIC"  6.566
        "Nicaragua"          2010 "NIC"  6.537
        "Nicaragua"          2011 "NIC"  4.503
        "Nicaragua"          2012 "NIC"  4.497
        "Nicaragua"          2013 "NIC"  4.478
        "Nicaragua"          2014 "NIC"  4.568
        "Nicaragua"          2015 "NIC"  4.647
        "Nicaragua"          2016 "NIC"  5.976
        "Nicaragua"          2017 "NIC"   5.85
        "Nicaragua"          2018 "NIC"  5.761
        "Nicaragua"          2019 "NIC"  5.732
        "Nicaragua"          2020 "NIC"  5.647
        "Panama"             1990 "PAN"  5.555
        "Panama"             1991 "PAN"  5.635
        "Panama"             1992 "PAN"  5.782
        "Panama"             1993 "PAN"  5.764
        "Panama"             1994 "PAN"  5.756
        "Panama"             1995 "PAN"  5.714
        "Panama"             1996 "PAN"  5.596
        "Panama"             1997 "PAN"  5.463
        "Panama"             1998 "PAN"  5.729
        "Panama"             1999 "PAN"  5.324
        "Panama"             2000 "PAN"  5.254
        "Panama"             2001 "PAN"  5.077
        "Panama"             2002 "PAN"  4.748
        "Panama"             2003 "PAN"  4.755
        "Panama"             2004 "PAN"  4.659
        "Panama"             2005 "PAN"   5.07
        "Panama"             2006 "PAN"  5.133
        "Panama"             2007 "PAN"  5.041
        "Panama"             2008 "PAN"  4.981
        "Panama"             2009 "PAN"  5.338
        "Panama"             2010 "PAN"  5.414
        "Panama"             2011 "PAN"  5.617
        "Panama"             2012 "PAN"  5.705
        "Panama"             2013 "PAN"    5.6
        "Panama"             2014 "PAN"  5.614
        "Panama"             2015 "PAN"  5.491
        "Panama"             2016 "PAN"  5.449
        "Panama"             2017 "PAN"  5.251
        "Panama"             2018 "PAN"  5.169
        "Panama"             2019 "PAN"  5.869
        "Panama"             2020 "PAN"  4.997
        "Paraguay"           1990 "PRY" 18.546
        "Paraguay"           1991 "PRY" 17.339
        "Paraguay"           1992 "PRY" 16.731
        "Paraguay"           1993 "PRY" 16.358
        "Paraguay"           1994 "PRY" 15.952
        "Paraguay"           1995 "PRY" 16.004
        "Paraguay"           1996 "PRY"   15.6
        "Paraguay"           1997 "PRY" 15.497
        "Paraguay"           1998 "PRY" 15.193
        "Paraguay"           1999 "PRY" 15.501
        "Paraguay"           2000 "PRY"   14.3
        "Paraguay"           2001 "PRY" 17.156
        "Paraguay"           2002 "PRY" 16.985
        "Paraguay"           2003 "PRY" 17.083
        "Paraguay"           2004 "PRY" 16.472
        "Paraguay"           2005 "PRY" 16.551
        "Paraguay"           2006 "PRY" 16.393
        "Paraguay"           2007 "PRY" 16.858
        "Paraguay"           2008 "PRY" 16.304
        "Paraguay"           2009 "PRY" 16.498
        "Paraguay"           2010 "PRY" 16.742
        "Paraguay"           2011 "PRY" 18.765
        "Paraguay"           2012 "PRY" 18.719
        "Paraguay"           2013 "PRY" 18.729
        "Paraguay"           2014 "PRY" 18.765
        "Paraguay"           2015 "PRY" 18.563
        "Paraguay"           2016 "PRY" 14.927
        "Paraguay"           2017 "PRY" 15.163
        "Paraguay"           2018 "PRY" 14.669
        "Paraguay"           2019 "PRY" 14.809
        "Paraguay"           2020 "PRY" 14.699
        "Peru"               1990 "PER"  4.715
        "Peru"               1991 "PER"  4.567
        "Peru"               1992 "PER"  4.504
        "Peru"               1993 "PER"  4.461
        "Peru"               1994 "PER"  4.472
        "Peru"               1995 "PER"  4.588
        "Peru"               1996 "PER"  4.652
        "Peru"               1997 "PER"  4.605
        "Peru"               1998 "PER"  4.557
        "Peru"               1999 "PER"  4.642
        "Peru"               2000 "PER"  4.595
        "Peru"               2001 "PER"  4.649
        "Peru"               2002 "PER"  4.665
        "Peru"               2003 "PER"  4.615
        "Peru"               2004 "PER"  4.712
        "Peru"               2005 "PER"  4.729
        "Peru"               2006 "PER"  4.666
        "Peru"               2007 "PER"  4.769
        "Peru"               2008 "PER"  4.904
        "Peru"               2009 "PER"   5.01
        "Peru"               2010 "PER"  5.129
        "Peru"               2011 "PER"  6.036
        "Peru"               2012 "PER"  5.991
        "Peru"               2013 "PER"  5.996
        "Peru"               2014 "PER"  6.055
        "Peru"               2015 "PER"  6.041
        "Peru"               2016 "PER"  6.076
        "Peru"               2017 "PER"  5.911
        "Peru"               2018 "PER"  5.806
        "Peru"               2019 "PER"  5.798
        "Peru"               2020 "PER"  5.398
        "Uruguay"            1990 "URY"  4.957
        "Uruguay"            1991 "URY"  5.441
        "Uruguay"            1992 "URY"   5.92
        "Uruguay"            1993 "URY"  6.057
        "Uruguay"            1994 "URY"  5.984
        "Uruguay"            1995 "URY"  6.013
        "Uruguay"            1996 "URY"  6.391
        "Uruguay"            1997 "URY"  6.265
        "Uruguay"            1998 "URY"  6.105
        "Uruguay"            1999 "URY"  6.398
        "Uruguay"            2000 "URY"  5.805
        "Uruguay"            2001 "URY"  6.656
        "Uruguay"            2002 "URY"  6.741
        "Uruguay"            2003 "URY"      7
        "Uruguay"            2004 "URY"  7.568
        "Uruguay"            2005 "URY"  7.611
        "Uruguay"            2006 "URY"  8.241
        "Uruguay"            2007 "URY"  7.913
        "Uruguay"            2008 "URY"  8.669
        "Uruguay"            2009 "URY"  8.513
        "Uruguay"            2010 "URY"  7.779
        "Uruguay"            2011 "URY"  9.135
        "Uruguay"            2012 "URY"  9.365
        "Uruguay"            2013 "URY"  9.044
        "Uruguay"            2014 "URY"  8.869
        "Uruguay"            2015 "URY"  8.804
        "Uruguay"            2016 "URY" 10.361
        "Uruguay"            2017 "URY" 10.113
        "Uruguay"            2018 "URY" 10.073
        "Uruguay"            2019 "URY" 10.165
        "Uruguay"            2020 "URY"  9.997
        "Venezuela"          1990 "VEN" 22.104
        "Venezuela"          1991 "VEN" 22.351
        "Venezuela"          1992 "VEN" 21.942
        "Venezuela"          1993 "VEN" 21.806
        "Venezuela"          1994 "VEN" 21.557
        "Venezuela"          1995 "VEN"   22.3
        "Venezuela"          1996 "VEN" 23.079
        "Venezuela"          1997 "VEN" 23.464
        "Venezuela"          1998 "VEN" 23.051
        "Venezuela"          1999 "VEN" 21.653
        "Venezuela"          2000 "VEN" 21.921
        "Venezuela"          2001 "VEN"  19.42
        "Venezuela"          2002 "VEN" 18.394
        "Venezuela"          2003 "VEN"  17.49
        "Venezuela"          2004 "VEN" 18.088
        "Venezuela"          2005 "VEN" 18.548
        "Venezuela"          2006 "VEN" 18.185
        "Venezuela"          2007 "VEN" 17.741
        "Venezuela"          2008 "VEN" 18.056
        "Venezuela"          2009 "VEN" 17.399
        "Venezuela"          2010 "VEN" 17.302
        "Venezuela"          2011 "VEN" 17.679
        "Venezuela"          2012 "VEN" 18.654
        "Venezuela"          2013 "VEN" 18.516
        "Venezuela"          2014 "VEN"  18.14
        "Venezuela"          2015 "VEN" 17.163
        "Venezuela"          2016 "VEN" 14.016
        "Venezuela"          2017 "VEN" 12.898
        "Venezuela"          2018 "VEN" 11.835
        "Venezuela"          2019 "VEN" 10.419
        "Venezuela"          2020 "VEN"  8.341
        end

        Comment


        • #5
          Thanks much, Justin Niakamal and Nick Cox , for your very helpful comments.

          Nick Cox , I probably was not clear enough on what I need. I agree with almost all of your comments on scaling and not using legends when there are so many legends and others, as well. However, I was just trying to replicate a graph that was plotted using another software by a friend. To improve my coding skills, I try to replicate graphs plotted in other softwares.

          Here is the graph that was drawn using another software and I wanted to plot in Stata:
          Click image for larger version

Name:	Figure-5_Club Transition Curves_Club2_with_States.png
Views:	1
Size:	217.3 KB
ID:	1759241

          The graph uses different markers for each line, representing the US States . It is just one line of code that gets the job done in the other software.

          Here is a sample data to produce a similar graph:

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str24 country int year double pgdp float id
          "Afghanistan" 1989 1906.9184  1
          "Afghanistan" 1990 1750.7216  1
          "Afghanistan" 1991 1837.0431  1
          "Afghanistan" 1992 1447.2505  1
          "Afghanistan" 1993 1136.8836  1
          "Afghanistan" 1994 1022.0531  1
          "Afghanistan" 1995 920.74704  1
          "Algeria"     1989 5578.1462  2
          "Algeria"     1990 5569.9025  2
          "Algeria"     1991 5537.3233  2
          "Algeria"     1992 5616.9971  2
          "Algeria"     1993 5431.6822  2
          "Algeria"     1994 5227.7289  2
          "Algeria"     1995 5324.4755  2
          "Antigua"     1989 9984.8026  3
          "Antigua"     1990 10793.289  3
          "Antigua"     1991 10706.191  3
          "Antigua"     1992 11148.938  3
          "Antigua"     1993 11999.629  3
          "Antigua"     1994 12623.968  3
          "Antigua"     1995 12024.509  3
          "Argentina"   1989 8464.9879  4
          "Argentina"   1990 8230.9624  4
          "Argentina"   1991 9099.3323  4
          "Argentina"   1992  10053.66  4
          "Argentina"   1993 10534.851  4
          "Argentina"   1994 10967.805  4
          "Argentina"   1995 10573.171  4
          "Australia"   1989 20771.475  5
          "Australia"   1990 20424.854  5
          "Australia"   1991 20375.576  5
          "Australia"   1992 20802.631  5
          "Australia"   1993  21301.69  5
          "Australia"   1994 22007.789  5
          "Australia"   1995 22648.291  5
          "Austria"     1989 21406.837  6
          "Austria"     1990 22219.839  6
          "Austria"     1991 22763.024  6
          "Austria"     1992 23089.635  6
          "Austria"     1993 22978.429  6
          "Austria"     1994 23265.231  6
          "Austria"     1995 23590.136  6
          "Bahamas"     1989 22215.938  7
          "Bahamas"     1990  20641.32  7
          "Bahamas"     1991  19716.71  7
          "Bahamas"     1992 17947.604  7
          "Bahamas"     1993  17390.04  7
          "Bahamas"     1994 17737.486  7
          "Bahamas"     1995 17111.225  7
          "Bahrain"     1989 16659.604  8
          "Bahrain"     1990 17191.369  8
          "Bahrain"     1991 16362.655  8
          "Bahrain"     1992 17099.276  8
          "Bahrain"     1993 19595.725  8
          "Bahrain"     1994 15801.352  8
          "Bahrain"     1995 16906.196  8
          "Barbados"    1989 15170.421  9
          "Barbados"    1990 14576.119  9
          "Barbados"    1991 14334.805  9
          "Barbados"    1992 13739.969  9
          "Barbados"    1993 13273.048  9
          "Barbados"    1994 13587.517  9
          "Barbados"    1995 14020.479  9
          "Belgium"     1989 20036.538 10
          "Belgium"     1990 20644.907 10
          "Belgium"     1991 20926.877 10
          "Belgium"     1992 21179.352 10
          "Belgium"     1993 20887.794 10
          "Belgium"     1994 21493.399 10
          "Belgium"     1995 21936.724 10
          "Belize"      1989 4758.2782 11
          "Belize"      1990 5169.1894 11
          "Belize"      1991 5028.8267 11
          "Belize"      1992 5416.4035 11
          "Belize"      1993 5658.9485 11
          "Belize"      1994 5924.9863 11
          "Belize"      1995 6036.4238 11
          "Benin"       1989 1077.4303 12
          "Benin"       1990 1085.5784 12
          "Benin"       1991 1112.9446 12
          "Benin"       1992 1125.0669 12
          "Benin"       1993 1126.1144 12
          "Benin"       1994 1123.9771 12
          "Benin"       1995 1129.7024 12
          "Bermuda"     1989 32678.219 13
          "Bermuda"     1990 31620.347 13
          "Bermuda"     1991 31116.273 13
          "Bermuda"     1992 30168.626 13
          "Bermuda"     1993 30966.077 13
          "Bermuda"     1994 31266.966 13
          "Bermuda"     1995 32155.929 13
          end


          And, here is finally what I came up with:

          Code:
          xtset id year
          
          local markers "o D T S + X A a I V o d s t x v Oh Dh Th Sh oh dh th sh p i none"
          
          gen marker = ""
          
          levelsof id, local(ids)
          
          foreach i of local ids {
              local rand = floor((runiform() * 13) + 1)
              local markertype: word `rand' of `markers'
              replace marker = "`markertype'" if id == `i'
               local plotopts `plotopts' plot`i'opts(recast(connected) msymbol(`markertype'))
               }
          
          
          xtline pgdp , overlay `plotopts'
          And, the result:
          Click image for larger version

Name:	Graph_my.png
Views:	1
Size:	95.1 KB
ID:	1759242

          Comment


          • #6
            At the risk of sounding sour, I have to say that the graph you're trying to emulate is good, but not excellent, so I wouldn't try to emulate it.

            In your code a minimal change might be to xla(1989(2)1995) or xla(1989/1995)

            Your questions are a little confusing as you started out asking about technique for 20 or 30 countries and end up with 13 time series, so the focus shifts from post to post.

            Comment


            • #7
              Nick Cox The issue here is neither labeling nor scaling or anything else. The question is how to obtain different marker symbols for a set of countries when using xtline. The number of countries( or ids, or time series) does not matter at all. It might be 13, or 20, or 30. Once I have a code that produces different marker symbols, it can easily be applied to any number of countries.
              Thanks once again for your very useful and guiding feedback.

              Comment

              Working...
              X