Announcement

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

  • Stata treating variable row as a data row, that stops me from drawing a tsset yearly variable graph showing oil production for 24 regions

    Hi Stata community;

    Here's the data I have:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 var1 long(var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 var12 var13 var14 var15 var16)
    ""               2008     2009     2010     2011      2012      2013      2014      2015      2016      2017      2018      2019      2020      2021      2022
    "ariana"     28480510 25609453 30063331 26950413  30268434  31133456  35098861  34316590  36639892  35744822  34699696  35334365  32383595  26411406  22023369
    "manouba"    20360283 19616901 19535610 18858296  17885194  16544553  16056025  14073380  14539672  13027754  10661456  10560877  13046636   8405661   8867913
    "ben-arous"   5732611  7696598  9346580  9201327   9236748   8511390   9168940   9660066  10323892  10885281   8991364  10966136  12558769  14127478  14551871
    "nabeul"     17253710 17592875 24953470 25737814  26765652  24794239  27497245  30367234  31980683  32235462  28922146  38491612  46919541  38196495  42431376
    "zaghouan"    1351334  3915348  1235170   916610    620465    639156    943978   1132415   1040821    783377    786217    678951   1162415   1971768   2094948
    "bizerte"    67973187 70778401 78922979 80061076  85326287  88733331  82671544 103728124 118324680 133038097 138644845 140114541 138434175 128745941 133868795
    "beja"       55895758 53664787 60099943 61778051  64564446  66848312  72921642  74210557  58826864  61088535  64688041  72687060  78113758  70744009  64684891
    "jandouba"   53509218 57922966 62560152 61359859  67777174  74459334  83992077  95257570 100370494 111734763 111082839 118220312 116549315 119292552 114510237
    "lekef"       6021926  5658817  5390225  5630049   6338341   7821260   9012978  14033767  11083908  10237561   8288184   3073104    244302         0   1939884
    "siliana"     1169557  2324372  2056305  3946378   8750788  11015950   1303789   4301856   4330573   3274987  10832423  16166825  18674022  20612777  19800954
    "kairouan"    6890758  8006319 10383672 12274951  11780080  11554816  13072564  15283044  18497132  24231472  23719419  23351471  28403229  29091910  26679429
    "sousse"     11933042 11884597 11475967 11051745  10248746  10201650  11821218  12688422  12393424  13286310  12498203  14077215  17038172  18917351  13568014
    "monastir"   38148512 34164132 35142456 38054845  40740750  41743253  43192395  44637344  45595355  43235250  36848966  30918928  29322912  32224088  29911564
    "mahdia"     99256314 88794373 83106240 87288122  91303534  96345650 106795740 115484615 124214955 121716048 115166490 113325652 119392118 126106622 120070724
    "sfax"       77161422 71672798 70542110 67143725  63916115  65196477  63417980  64570510  63306256  61518651  51266106  51236810  57180662  54715870  45231343
    "sidibouzid" 68549730 76742415 95064067 99191341 109993089 117109947 127058910 134360630 132989973 129907597 115041368 107231095 104698490  98243311  84980878
    "gafsa"      14492111 17236490 22924866 24518046  30631403  39890206  43484237  44058954  44599504  51255503  45785720  40727768  39100814  37880401  34641139
    "kasserine"   6913099  9745044  8386420 10925714  14883198  17615400  18667492  19367890  23222346  22572904  18219246  16746512  17702617  20223982  19555906
    "tozeur"            0        0        0        0         0         0         0         0         0         0         0         0         0         0         0
    "gabes"      18340501 19028184 18642876 19440084  18231796  17538634  16736405  16319867  12960491  12197624   9298911   8394073   9609698   9880168   8069875
    "medenine"     109887   175056   102472        0         0         0         0         0         0         0         0         0         0         0         0
    "kebilli"      315963   321005   361935    86635         0         0         0         0         0         0         0         0         0         0         0
    end
    For some reason, when importing the data from an excen format to a Stata one, I get the first row treated as data, or I do want it to be treated like a variable row (even more so, that option doesn't show so I could choose how to treat the forst row)

    I do wanna draw a tsset year graph that shows the evolution of the oil production for the 24 regions (each region line presented by a color) through the years. I know 24 lines on a same graph seem too much and that the grph could be crowded, but I kinda need that for comparative analysis, I might just keep the 6 or 8 most interesting regions on the graph after all.

    Any Help Please? Thank You!

  • #2
    The entries in your first observation ("row") cannot be variable names, because in Stata all variable names must begin with a letter or underscore character.

    Moreover, to get the kind of graph you want, you need to reorganize the data into a long layout--you can't do it with the years "side by side."

    So, like this:
    Code:
    rename var1 something
    foreach v of varlist var* {
        rename `v' oil_production`=`v'[1]'
    }
    drop in 1
    
    encode something, gen(panel_var)
    drop something
    reshape long oil_production, i(panel_var) j(year)
    xtset panel_var year
    xtline oil_production, overlay ylabel(, angle(0))
    Note: You should replace "panel_var" in the above code by a variable name that describes whatever ariana, manouba, etc. are. (i.e. a name like region, or city, or refinery, or firm, or whatever they actually are.)

    Comment


    • #3
      Clyde Schechter Thanks for the Help So, I guess since the Year variable didn't have any alphabetics in it, so it was automatically treated as part of the data Anyway, the shared code works well, even thos I still have a slight problem: The quantites of oil production are expressed in the exponential format (some call it the scientific format) in the graph, and I kinda don't want that, I want them to be expressed in the normal format.
      Any help with that please? Is it an option in the code or something else?

      Thanks

      Comment


      • #4
        You should please show a data example -- as that in #1 is unfit for purpose -- and also a graph.

        The problem of very large numbers can be attacked in different ways, here just changing the unstated units to million units.

        You have more problems than that, including the legend being unworkable, alphabetical order being unhelpful, and so on.

        Here is a stab at another design. I use myaxis from the Stata Journal.

        Log scale is also a possibility so long as you ignore the zeros. EDIT: No, it doesn't help much in practice.

        I guess this is vegetable (olive?) oil not petroleum!

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input long panel_var int year long oil_production
         1 2008  28480510
         1 2009  25609453
         1 2010  30063331
         1 2011  26950413
         1 2012  30268434
         1 2013  31133456
         1 2014  35098861
         1 2015  34316590
         1 2016  36639892
         1 2017  35744822
         1 2018  34699696
         1 2019  35334365
         1 2020  32383595
         1 2021  26411406
         1 2022  22023369
         2 2008  55895758
         2 2009  53664787
         2 2010  60099943
         2 2011  61778051
         2 2012  64564446
         2 2013  66848312
         2 2014  72921642
         2 2015  74210557
         2 2016  58826864
         2 2017  61088535
         2 2018  64688041
         2 2019  72687060
         2 2020  78113758
         2 2021  70744009
         2 2022  64684891
         3 2008   5732611
         3 2009   7696598
         3 2010   9346580
         3 2011   9201327
         3 2012   9236748
         3 2013   8511390
         3 2014   9168940
         3 2015   9660066
         3 2016  10323892
         3 2017  10885281
         3 2018   8991364
         3 2019  10966136
         3 2020  12558769
         3 2021  14127478
         3 2022  14551871
         4 2008  67973187
         4 2009  70778401
         4 2010  78922979
         4 2011  80061076
         4 2012  85326287
         4 2013  88733331
         4 2014  82671544
         4 2015 103728124
         4 2016 118324680
         4 2017 133038097
         4 2018 138644845
         4 2019 140114541
         4 2020 138434175
         4 2021 128745941
         4 2022 133868795
         5 2008  18340501
         5 2009  19028184
         5 2010  18642876
         5 2011  19440084
         5 2012  18231796
         5 2013  17538634
         5 2014  16736405
         5 2015  16319867
         5 2016  12960491
         5 2017  12197624
         5 2018   9298911
         5 2019   8394073
         5 2020   9609698
         5 2021   9880168
         5 2022   8069875
         6 2008  14492111
         6 2009  17236490
         6 2010  22924866
         6 2011  24518046
         6 2012  30631403
         6 2013  39890206
         6 2014  43484237
         6 2015  44058954
         6 2016  44599504
         6 2017  51255503
         6 2018  45785720
         6 2019  40727768
         6 2020  39100814
         6 2021  37880401
         6 2022  34641139
         7 2008  53509218
         7 2009  57922966
         7 2010  62560152
         7 2011  61359859
         7 2012  67777174
         7 2013  74459334
         7 2014  83992077
         7 2015  95257570
         7 2016 100370494
         7 2017 111734763
         7 2018 111082839
         7 2019 118220312
         7 2020 116549315
         7 2021 119292552
         7 2022 114510237
         8 2008   6890758
         8 2009   8006319
         8 2010  10383672
         8 2011  12274951
         8 2012  11780080
         8 2013  11554816
         8 2014  13072564
         8 2015  15283044
         8 2016  18497132
         8 2017  24231472
         8 2018  23719419
         8 2019  23351471
         8 2020  28403229
         8 2021  29091910
         8 2022  26679429
         9 2008   6913099
         9 2009   9745044
         9 2010   8386420
         9 2011  10925714
         9 2012  14883198
         9 2013  17615400
         9 2014  18667492
         9 2015  19367890
         9 2016  23222346
         9 2017  22572904
         9 2018  18219246
         9 2019  16746512
         9 2020  17702617
         9 2021  20223982
         9 2022  19555906
        10 2008    315963
        10 2009    321005
        10 2010    361935
        10 2011     86635
        10 2012         0
        10 2013         0
        10 2014         0
        10 2015         0
        10 2016         0
        10 2017         0
        10 2018         0
        10 2019         0
        10 2020         0
        10 2021         0
        10 2022         0
        11 2008   6021926
        11 2009   5658817
        11 2010   5390225
        11 2011   5630049
        11 2012   6338341
        11 2013   7821260
        11 2014   9012978
        11 2015  14033767
        11 2016  11083908
        11 2017  10237561
        11 2018   8288184
        11 2019   3073104
        11 2020    244302
        11 2021         0
        11 2022   1939884
        12 2008  99256314
        12 2009  88794373
        12 2010  83106240
        12 2011  87288122
        12 2012  91303534
        12 2013  96345650
        12 2014 106795740
        12 2015 115484615
        12 2016 124214955
        12 2017 121716048
        12 2018 115166490
        12 2019 113325652
        12 2020 119392118
        12 2021 126106622
        12 2022 120070724
        13 2008  20360283
        13 2009  19616901
        13 2010  19535610
        13 2011  18858296
        13 2012  17885194
        13 2013  16544553
        13 2014  16056025
        13 2015  14073380
        13 2016  14539672
        13 2017  13027754
        13 2018  10661456
        13 2019  10560877
        13 2020  13046636
        13 2021   8405661
        13 2022   8867913
        14 2008    109887
        14 2009    175056
        14 2010    102472
        14 2011         0
        14 2012         0
        14 2013         0
        14 2014         0
        14 2015         0
        14 2016         0
        14 2017         0
        14 2018         0
        14 2019         0
        14 2020         0
        14 2021         0
        14 2022         0
        15 2008  38148512
        15 2009  34164132
        15 2010  35142456
        15 2011  38054845
        15 2012  40740750
        15 2013  41743253
        15 2014  43192395
        15 2015  44637344
        15 2016  45595355
        15 2017  43235250
        15 2018  36848966
        15 2019  30918928
        15 2020  29322912
        15 2021  32224088
        15 2022  29911564
        16 2008  17253710
        16 2009  17592875
        16 2010  24953470
        16 2011  25737814
        16 2012  26765652
        16 2013  24794239
        16 2014  27497245
        16 2015  30367234
        16 2016  31980683
        16 2017  32235462
        16 2018  28922146
        16 2019  38491612
        16 2020  46919541
        16 2021  38196495
        16 2022  42431376
        17 2008  77161422
        17 2009  71672798
        17 2010  70542110
        17 2011  67143725
        17 2012  63916115
        17 2013  65196477
        17 2014  63417980
        17 2015  64570510
        17 2016  63306256
        17 2017  61518651
        17 2018  51266106
        17 2019  51236810
        17 2020  57180662
        17 2021  54715870
        17 2022  45231343
        18 2008  68549730
        18 2009  76742415
        18 2010  95064067
        18 2011  99191341
        18 2012 109993089
        18 2013 117109947
        18 2014 127058910
        18 2015 134360630
        18 2016 132989973
        18 2017 129907597
        18 2018 115041368
        18 2019 107231095
        18 2020 104698490
        18 2021  98243311
        18 2022  84980878
        19 2008   1169557
        19 2009   2324372
        19 2010   2056305
        19 2011   3946378
        19 2012   8750788
        19 2013  11015950
        19 2014   1303789
        19 2015   4301856
        19 2016   4330573
        19 2017   3274987
        19 2018  10832423
        19 2019  16166825
        19 2020  18674022
        19 2021  20612777
        19 2022  19800954
        20 2008  11933042
        20 2009  11884597
        20 2010  11475967
        20 2011  11051745
        20 2012  10248746
        20 2013  10201650
        20 2014  11821218
        20 2015  12688422
        20 2016  12393424
        20 2017  13286310
        20 2018  12498203
        20 2019  14077215
        20 2020  17038172
        20 2021  18917351
        20 2022  13568014
        21 2008         0
        21 2009         0
        21 2010         0
        21 2011         0
        21 2012         0
        21 2013         0
        21 2014         0
        21 2015         0
        21 2016         0
        21 2017         0
        21 2018         0
        21 2019         0
        21 2020         0
        21 2021         0
        21 2022         0
        22 2008   1351334
        22 2009   3915348
        22 2010   1235170
        22 2011    916610
        22 2012    620465
        22 2013    639156
        22 2014    943978
        22 2015   1132415
        22 2016   1040821
        22 2017    783377
        22 2018    786217
        22 2019    678951
        22 2020   1162415
        22 2021   1971768
        22 2022   2094948
        end
        label values panel_var panel_var
        label def panel_var 1 "ariana", modify
        label def panel_var 2 "beja", modify
        label def panel_var 3 "ben-arous", modify
        label def panel_var 4 "bizerte", modify
        label def panel_var 5 "gabes", modify
        label def panel_var 6 "gafsa", modify
        label def panel_var 7 "jandouba", modify
        label def panel_var 8 "kairouan", modify
        label def panel_var 9 "kasserine", modify
        label def panel_var 10 "kebilli", modify
        label def panel_var 11 "lekef", modify
        label def panel_var 12 "mahdia", modify
        label def panel_var 13 "manouba", modify
        label def panel_var 14 "medenine", modify
        label def panel_var 15 "monastir", modify
        label def panel_var 16 "nabeul", modify
        label def panel_var 17 "sfax", modify
        label def panel_var 18 "sidibouzid", modify
        label def panel_var 19 "siliana", modify
        label def panel_var 20 "sousse", modify
        label def panel_var 21 "tozeur", modify
        label def panel_var 22 "zaghouan", modify
        
        
        myaxis newid=panel_var, sort(mean oil_production) descending
        
        gen oil_production2 = oil_production/1e6
        line oil_production2 year, by(newid, compact note("")) yla(, ang(h)) ytitle(Oil production (million ???units here)) xtitle("") xla(2008(2)2022, format(%tyYY))
        Click image for larger version

Name:	oilTunisia.png
Views:	1
Size:	42.2 KB
ID:	1706028

        Last edited by Nick Cox; 17 Mar 2023, 04:35.

        Comment


        • #5
          Challenges like this arise all the time -- plotting multiple series but allowing attention to detail and fine structure -- so I kept playing, regardless of an apparent lack of interest in suggestions. 22 panels (substantive and graphical) are quite a lot so is there a compromise based on grouping panels?

          An idea mentioned in Section 6 of https://journals.sagepub.com/doi/pdf...36867X19893641 (but presumably used in many places before) leads to a thought that -- given a ranking of series by typical magnitude 1 2 3 ... 21 22 we could plot series

          1 4 7 ...

          together and

          2 5 8 ...

          together and

          3 6 9 ...

          together, as a way of not plotting series of similar magnitude in a way that would produce too much tangle.

          In using Aziz's data as a sandbox I made some simplifying choices

          * not plotting some areas with low amounts

          * guessing that 3 letter abbreviations would be helpful enough for people interested in the geographical detail of which areas are high, changing, etc.

          Mapping ranks 1 2 3 4 5 6 ... 20 21 22 to 1 2 3 1 2 3 ... 2 3 1 is almost done by mod(rank, 3) (but is there a more direct solution than my code below?).

          Here is the complete code. Repeating the data is a gesture to anyone wanting to play themselves and apologies to anyone irritated by the length of the post.

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input long panel_var int year long oil_production
           1 2008  28480510
           1 2009  25609453
           1 2010  30063331
           1 2011  26950413
           1 2012  30268434
           1 2013  31133456
           1 2014  35098861
           1 2015  34316590
           1 2016  36639892
           1 2017  35744822
           1 2018  34699696
           1 2019  35334365
           1 2020  32383595
           1 2021  26411406
           1 2022  22023369
           2 2008  55895758
           2 2009  53664787
           2 2010  60099943
           2 2011  61778051
           2 2012  64564446
           2 2013  66848312
           2 2014  72921642
           2 2015  74210557
           2 2016  58826864
           2 2017  61088535
           2 2018  64688041
           2 2019  72687060
           2 2020  78113758
           2 2021  70744009
           2 2022  64684891
           3 2008   5732611
           3 2009   7696598
           3 2010   9346580
           3 2011   9201327
           3 2012   9236748
           3 2013   8511390
           3 2014   9168940
           3 2015   9660066
           3 2016  10323892
           3 2017  10885281
           3 2018   8991364
           3 2019  10966136
           3 2020  12558769
           3 2021  14127478
           3 2022  14551871
           4 2008  67973187
           4 2009  70778401
           4 2010  78922979
           4 2011  80061076
           4 2012  85326287
           4 2013  88733331
           4 2014  82671544
           4 2015 103728124
           4 2016 118324680
           4 2017 133038097
           4 2018 138644845
           4 2019 140114541
           4 2020 138434175
           4 2021 128745941
           4 2022 133868795
           5 2008  18340501
           5 2009  19028184
           5 2010  18642876
           5 2011  19440084
           5 2012  18231796
           5 2013  17538634
           5 2014  16736405
           5 2015  16319867
           5 2016  12960491
           5 2017  12197624
           5 2018   9298911
           5 2019   8394073
           5 2020   9609698
           5 2021   9880168
           5 2022   8069875
           6 2008  14492111
           6 2009  17236490
           6 2010  22924866
           6 2011  24518046
           6 2012  30631403
           6 2013  39890206
           6 2014  43484237
           6 2015  44058954
           6 2016  44599504
           6 2017  51255503
           6 2018  45785720
           6 2019  40727768
           6 2020  39100814
           6 2021  37880401
           6 2022  34641139
           7 2008  53509218
           7 2009  57922966
           7 2010  62560152
           7 2011  61359859
           7 2012  67777174
           7 2013  74459334
           7 2014  83992077
           7 2015  95257570
           7 2016 100370494
           7 2017 111734763
           7 2018 111082839
           7 2019 118220312
           7 2020 116549315
           7 2021 119292552
           7 2022 114510237
           8 2008   6890758
           8 2009   8006319
           8 2010  10383672
           8 2011  12274951
           8 2012  11780080
           8 2013  11554816
           8 2014  13072564
           8 2015  15283044
           8 2016  18497132
           8 2017  24231472
           8 2018  23719419
           8 2019  23351471
           8 2020  28403229
           8 2021  29091910
           8 2022  26679429
           9 2008   6913099
           9 2009   9745044
           9 2010   8386420
           9 2011  10925714
           9 2012  14883198
           9 2013  17615400
           9 2014  18667492
           9 2015  19367890
           9 2016  23222346
           9 2017  22572904
           9 2018  18219246
           9 2019  16746512
           9 2020  17702617
           9 2021  20223982
           9 2022  19555906
          10 2008    315963
          10 2009    321005
          10 2010    361935
          10 2011     86635
          10 2012         0
          10 2013         0
          10 2014         0
          10 2015         0
          10 2016         0
          10 2017         0
          10 2018         0
          10 2019         0
          10 2020         0
          10 2021         0
          10 2022         0
          11 2008   6021926
          11 2009   5658817
          11 2010   5390225
          11 2011   5630049
          11 2012   6338341
          11 2013   7821260
          11 2014   9012978
          11 2015  14033767
          11 2016  11083908
          11 2017  10237561
          11 2018   8288184
          11 2019   3073104
          11 2020    244302
          11 2021         0
          11 2022   1939884
          12 2008  99256314
          12 2009  88794373
          12 2010  83106240
          12 2011  87288122
          12 2012  91303534
          12 2013  96345650
          12 2014 106795740
          12 2015 115484615
          12 2016 124214955
          12 2017 121716048
          12 2018 115166490
          12 2019 113325652
          12 2020 119392118
          12 2021 126106622
          12 2022 120070724
          13 2008  20360283
          13 2009  19616901
          13 2010  19535610
          13 2011  18858296
          13 2012  17885194
          13 2013  16544553
          13 2014  16056025
          13 2015  14073380
          13 2016  14539672
          13 2017  13027754
          13 2018  10661456
          13 2019  10560877
          13 2020  13046636
          13 2021   8405661
          13 2022   8867913
          14 2008    109887
          14 2009    175056
          14 2010    102472
          14 2011         0
          14 2012         0
          14 2013         0
          14 2014         0
          14 2015         0
          14 2016         0
          14 2017         0
          14 2018         0
          14 2019         0
          14 2020         0
          14 2021         0
          14 2022         0
          15 2008  38148512
          15 2009  34164132
          15 2010  35142456
          15 2011  38054845
          15 2012  40740750
          15 2013  41743253
          15 2014  43192395
          15 2015  44637344
          15 2016  45595355
          15 2017  43235250
          15 2018  36848966
          15 2019  30918928
          15 2020  29322912
          15 2021  32224088
          15 2022  29911564
          16 2008  17253710
          16 2009  17592875
          16 2010  24953470
          16 2011  25737814
          16 2012  26765652
          16 2013  24794239
          16 2014  27497245
          16 2015  30367234
          16 2016  31980683
          16 2017  32235462
          16 2018  28922146
          16 2019  38491612
          16 2020  46919541
          16 2021  38196495
          16 2022  42431376
          17 2008  77161422
          17 2009  71672798
          17 2010  70542110
          17 2011  67143725
          17 2012  63916115
          17 2013  65196477
          17 2014  63417980
          17 2015  64570510
          17 2016  63306256
          17 2017  61518651
          17 2018  51266106
          17 2019  51236810
          17 2020  57180662
          17 2021  54715870
          17 2022  45231343
          18 2008  68549730
          18 2009  76742415
          18 2010  95064067
          18 2011  99191341
          18 2012 109993089
          18 2013 117109947
          18 2014 127058910
          18 2015 134360630
          18 2016 132989973
          18 2017 129907597
          18 2018 115041368
          18 2019 107231095
          18 2020 104698490
          18 2021  98243311
          18 2022  84980878
          19 2008   1169557
          19 2009   2324372
          19 2010   2056305
          19 2011   3946378
          19 2012   8750788
          19 2013  11015950
          19 2014   1303789
          19 2015   4301856
          19 2016   4330573
          19 2017   3274987
          19 2018  10832423
          19 2019  16166825
          19 2020  18674022
          19 2021  20612777
          19 2022  19800954
          20 2008  11933042
          20 2009  11884597
          20 2010  11475967
          20 2011  11051745
          20 2012  10248746
          20 2013  10201650
          20 2014  11821218
          20 2015  12688422
          20 2016  12393424
          20 2017  13286310
          20 2018  12498203
          20 2019  14077215
          20 2020  17038172
          20 2021  18917351
          20 2022  13568014
          21 2008         0
          21 2009         0
          21 2010         0
          21 2011         0
          21 2012         0
          21 2013         0
          21 2014         0
          21 2015         0
          21 2016         0
          21 2017         0
          21 2018         0
          21 2019         0
          21 2020         0
          21 2021         0
          21 2022         0
          22 2008   1351334
          22 2009   3915348
          22 2010   1235170
          22 2011    916610
          22 2012    620465
          22 2013    639156
          22 2014    943978
          22 2015   1132415
          22 2016   1040821
          22 2017    783377
          22 2018    786217
          22 2019    678951
          22 2020   1162415
          22 2021   1971768
          22 2022   2094948
          end
          label values panel_var panel_var
          label def panel_var 1 "ariana", modify
          label def panel_var 2 "beja", modify
          label def panel_var 3 "ben-arous", modify
          label def panel_var 4 "bizerte", modify
          label def panel_var 5 "gabes", modify
          label def panel_var 6 "gafsa", modify
          label def panel_var 7 "jandouba", modify
          label def panel_var 8 "kairouan", modify
          label def panel_var 9 "kasserine", modify
          label def panel_var 10 "kebilli", modify
          label def panel_var 11 "lekef", modify
          label def panel_var 12 "mahdia", modify
          label def panel_var 13 "manouba", modify
          label def panel_var 14 "medenine", modify
          label def panel_var 15 "monastir", modify
          label def panel_var 16 "nabeul", modify
          label def panel_var 17 "sfax", modify
          label def panel_var 18 "sidibouzid", modify
          label def panel_var 19 "siliana", modify
          label def panel_var 20 "sousse", modify
          label def panel_var 21 "tozeur", modify
          label def panel_var 22 "zaghouan", modify
          
          * download from Stata Journal 
          myaxis newid=panel_var, sort(mean oil_production) descending
          
          gen oil_production2 = oil_production/1e6 
          
          * new stuff below 
          gen group3 = cond(mod(newid, 3), mod(newid, 3), 3)
          decode newid, gen(name) 
          replace name = substr(proper(name), 1, 3) 
          
          set scheme s1color 
          
          line oil_production2 year if newid <= 15, by(group3, row(1) legend(off) note("")) c(L) yla(, ang(h)) ytitle(Oil production (million ???units here)) xtitle("") xla(2008 "2008  " 2010(2)2020 2022 "   2022", grid format(%tyYY)) || scatter oil_production2 year if newid <= 15 & year==2022, ms(none) mla(name) xsc(r(. 2024)) subtitle("", nobox nobexpand fcolor(none)) name(G3, replace)
          Code:
          
          

          Click image for larger version

Name:	tunisiaG3.png
Views:	1
Size:	84.9 KB
ID:	1706106
          The trade-off between # of series in each plot and # of plots is a little delicate. If there is interest in a particular series or group of series, different colours are clearly possible.

          Comment


          • #6
            Nick Cox Thanks for the help I'm really impressed by the idea, it is a new way of viewing the problem I do think it is a new way of dealing with lots of series and giving attention to details all at once Yet, I wanna ask about the choice of the 15 regions, the data has got 22 regions in it, so is it a choice based on the most important regions in terms of production? And is it possible to have all 22 regions? Perhaps adding a fourth "sub-graph" just for the low production regions?

            Comment


            • #7
              Yes; as said, I omitted the lowest producing regions. You can plot all 22 just by omitting newid <= 15 as a qualifier but the problem is then overplotting. Log scale would run into the problem that you need to cope with zeros.

              Comment

              Working...
              X