Announcement

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

  • Graphing one product verses an average of all other products

    Hi All,

    I am having trouble thinking how I can graph an average of two products ("Coca-Cola" and "tonic water") as "Soft Drinks" within the prod variable along with an average price line of all other goods listed in the sample over time. I had tried to graph many individual lines together, but it becomes quite messy and you are unable to see exactly what is being graphed where. Instead, just have one line for "Soft Drinks" and one line for everything else. I think a "twoway" line should work, but I am not sure how to get the averages for "Soft Drinks" and for the remaining other product average lines (ideally without creating a new "total" observation which would change the results of any regressions that I run). A snippet of my data is attached below. Thanks so much for any ideas!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double abs_price str23 combined str66 prod float store_type int year str3 currency str7 country str10 city float tax
     2.99 "2014IrelandDublinEUR" "Apples (1 kg)"  0 2014 "EUR" "Ireland" "Dublin"     0
     2.24 "2014IrelandDublinEUR" "Apples (1 kg)"  1 2014 "EUR" "Ireland" "Dublin"     0
        3 "2015IrelandDublinEUR" "Apples (1 kg)"  0 2015 "EUR" "Ireland" "Dublin"     0
     2.48 "2015IrelandDublinEUR" "Apples (1 kg)"  1 2015 "EUR" "Ireland" "Dublin"     0
        3 "2016IrelandDublinEUR" "Apples (1 kg)"  0 2016 "EUR" "Ireland" "Dublin"     1
     2.34 "2016IrelandDublinEUR" "Apples (1 kg)"  1 2016 "EUR" "Ireland" "Dublin"     1
      3.2 "2017IrelandDublinEUR" "Apples (1 kg)"  0 2017 "EUR" "Ireland" "Dublin"     1
     2.15 "2017IrelandDublinEUR" "Apples (1 kg)"  1 2017 "EUR" "Ireland" "Dublin"     1
     2.99 "2018IrelandDublinEUR" "Apples (1 kg)"  0 2018 "EUR" "Ireland" "Dublin"     1
     2.19 "2018IrelandDublinEUR" "Apples (1 kg)"  1 2018 "EUR" "Ireland" "Dublin"     1
     2.54 "2019IrelandDublinEUR" "Apples (1 kg)"  0 2019 "EUR" "Ireland" "Dublin"     1
      2.4 "2019IrelandDublinEUR" "Apples (1 kg)"  1 2019 "EUR" "Ireland" "Dublin"     1
     2.61 "2020IrelandDublinEUR" "Apples (1 kg)"  0 2020 "EUR" "Ireland" "Dublin"     1
     2.25 "2020IrelandDublinEUR" "Apples (1 kg)"  1 2020 "EUR" "Ireland" "Dublin"     1
     2.52 "2014UKManchesterGBP"  "Apples (1 kg)"  0 2014 "GBP" "UK"      "Manchester" 0
     1.95 "2014UKLondonGBP"      "Apples (1 kg)"  0 2014 "GBP" "UK"      "London"     0
     1.86 "2014UKLondonGBP"      "Apples (1 kg)"  1 2014 "GBP" "UK"      "London"     0
     1.93 "2014UKManchesterGBP"  "Apples (1 kg)"  1 2014 "GBP" "UK"      "Manchester" 0
     1.85 "2015UKLondonGBP"      "Apples (1 kg)"  0 2015 "GBP" "UK"      "London"     0
      2.2 "2015UKManchesterGBP"  "Apples (1 kg)"  0 2015 "GBP" "UK"      "Manchester" 0
     1.75 "2015UKManchesterGBP"  "Apples (1 kg)"  1 2015 "GBP" "UK"      "Manchester" 0
     1.75 "2015UKLondonGBP"      "Apples (1 kg)"  1 2015 "GBP" "UK"      "London"     0
      2.1 "2016UKManchesterGBP"  "Apples (1 kg)"  0 2016 "GBP" "UK"      "Manchester" 1
        2 "2016UKLondonGBP"      "Apples (1 kg)"  0 2016 "GBP" "UK"      "London"     1
        2 "2016UKLondonGBP"      "Apples (1 kg)"  1 2016 "GBP" "UK"      "London"     1
     1.75 "2016UKManchesterGBP"  "Apples (1 kg)"  1 2016 "GBP" "UK"      "Manchester" 1
        2 "2017UKLondonGBP"      "Apples (1 kg)"  0 2017 "GBP" "UK"      "London"     1
      2.2 "2017UKManchesterGBP"  "Apples (1 kg)"  0 2017 "GBP" "UK"      "Manchester" 1
     1.75 "2017UKManchesterGBP"  "Apples (1 kg)"  1 2017 "GBP" "UK"      "Manchester" 1
     1.98 "2017UKLondonGBP"      "Apples (1 kg)"  1 2017 "GBP" "UK"      "London"     1
      2.3 "2018UKManchesterGBP"  "Apples (1 kg)"  0 2018 "GBP" "UK"      "Manchester" 1
     2.12 "2018UKLondonGBP"      "Apples (1 kg)"  0 2018 "GBP" "UK"      "London"     1
        2 "2018UKLondonGBP"      "Apples (1 kg)"  1 2018 "GBP" "UK"      "London"     1
     1.97 "2018UKManchesterGBP"  "Apples (1 kg)"  1 2018 "GBP" "UK"      "Manchester" 1
     2.04 "2019UKLondonGBP"      "Apples (1 kg)"  0 2019 "GBP" "UK"      "London"     1
     2.16 "2019UKManchesterGBP"  "Apples (1 kg)"  0 2019 "GBP" "UK"      "Manchester" 1
     1.79 "2019UKLondonGBP"      "Apples (1 kg)"  1 2019 "GBP" "UK"      "London"     1
     2.01 "2019UKManchesterGBP"  "Apples (1 kg)"  1 2019 "GBP" "UK"      "Manchester" 1
     2.14 "2020UKManchesterGBP"  "Apples (1 kg)"  0 2020 "GBP" "UK"      "Manchester" 1
      2.1 "2020UKLondonGBP"      "Apples (1 kg)"  0 2020 "GBP" "UK"      "London"     1
     1.85 "2020UKLondonGBP"      "Apples (1 kg)"  1 2020 "GBP" "UK"      "London"     1
     1.87 "2020UKManchesterGBP"  "Apples (1 kg)"  1 2020 "GBP" "UK"      "Manchester" 1
    12.45 "2014IrelandDublinEUR" "Bacon (1 kg)"   0 2014 "EUR" "Ireland" "Dublin"     0
     8.77 "2014IrelandDublinEUR" "Bacon (1 kg)"   1 2014 "EUR" "Ireland" "Dublin"     0
    10.14 "2015IrelandDublinEUR" "Bacon (1 kg)"   0 2015 "EUR" "Ireland" "Dublin"     0
     7.44 "2015IrelandDublinEUR" "Bacon (1 kg)"   1 2015 "EUR" "Ireland" "Dublin"     0
     9.99 "2016IrelandDublinEUR" "Bacon (1 kg)"   0 2016 "EUR" "Ireland" "Dublin"     1
     7.08 "2016IrelandDublinEUR" "Bacon (1 kg)"   1 2016 "EUR" "Ireland" "Dublin"     1
     8.64 "2017IrelandDublinEUR" "Bacon (1 kg)"   0 2017 "EUR" "Ireland" "Dublin"     1
        6 "2017IrelandDublinEUR" "Bacon (1 kg)"   1 2017 "EUR" "Ireland" "Dublin"     1
     6.82 "2018IrelandDublinEUR" "Bacon (1 kg)"   0 2018 "EUR" "Ireland" "Dublin"     1
     6.32 "2018IrelandDublinEUR" "Bacon (1 kg)"   1 2018 "EUR" "Ireland" "Dublin"     1
     6.54 "2019IrelandDublinEUR" "Bacon (1 kg)"   0 2019 "EUR" "Ireland" "Dublin"     1
     4.92 "2019IrelandDublinEUR" "Bacon (1 kg)"   1 2019 "EUR" "Ireland" "Dublin"     1
      5.9 "2020IrelandDublinEUR" "Bacon (1 kg)"   0 2020 "EUR" "Ireland" "Dublin"     1
     4.57 "2020IrelandDublinEUR" "Bacon (1 kg)"   1 2020 "EUR" "Ireland" "Dublin"     1
       10 "2014UKManchesterGBP"  "Bacon (1 kg)"   0 2014 "GBP" "UK"      "Manchester" 0
    13.96 "2014UKLondonGBP"      "Bacon (1 kg)"   0 2014 "GBP" "UK"      "London"     0
      9.5 "2014UKManchesterGBP"  "Bacon (1 kg)"   1 2014 "GBP" "UK"      "Manchester" 0
        5 "2014UKLondonGBP"      "Bacon (1 kg)"   1 2014 "GBP" "UK"      "London"     0
    12.36 "2015UKLondonGBP"      "Bacon (1 kg)"   0 2015 "GBP" "UK"      "London"     0
      9.5 "2015UKManchesterGBP"  "Bacon (1 kg)"   0 2015 "GBP" "UK"      "Manchester" 0
     6.67 "2015UKLondonGBP"      "Bacon (1 kg)"   1 2015 "GBP" "UK"      "London"     0
     8.32 "2015UKManchesterGBP"  "Bacon (1 kg)"   1 2015 "GBP" "UK"      "Manchester" 0
    11.96 "2016UKLondonGBP"      "Bacon (1 kg)"   0 2016 "GBP" "UK"      "London"     1
     9.33 "2016UKManchesterGBP"  "Bacon (1 kg)"   0 2016 "GBP" "UK"      "Manchester" 1
     7.67 "2016UKManchesterGBP"  "Bacon (1 kg)"   1 2016 "GBP" "UK"      "Manchester" 1
     6.67 "2016UKLondonGBP"      "Bacon (1 kg)"   1 2016 "GBP" "UK"      "London"     1
    10.84 "2017UKLondonGBP"      "Bacon (1 kg)"   0 2017 "GBP" "UK"      "London"     1
     8.14 "2017UKManchesterGBP"  "Bacon (1 kg)"   0 2017 "GBP" "UK"      "Manchester" 1
     6.18 "2017UKManchesterGBP"  "Bacon (1 kg)"   1 2017 "GBP" "UK"      "Manchester" 1
     6.67 "2017UKLondonGBP"      "Bacon (1 kg)"   1 2017 "GBP" "UK"      "London"     1
     9.09 "2018UKLondonGBP"      "Bacon (1 kg)"   0 2018 "GBP" "UK"      "London"     1
     8.04 "2018UKManchesterGBP"  "Bacon (1 kg)"   0 2018 "GBP" "UK"      "Manchester" 1
     7.48 "2018UKLondonGBP"      "Bacon (1 kg)"   1 2018 "GBP" "UK"      "London"     1
      6.4 "2018UKManchesterGBP"  "Bacon (1 kg)"   1 2018 "GBP" "UK"      "Manchester" 1
     8.33 "2019UKManchesterGBP"  "Bacon (1 kg)"   0 2019 "GBP" "UK"      "Manchester" 1
    10.93 "2019UKLondonGBP"      "Bacon (1 kg)"   0 2019 "GBP" "UK"      "London"     1
     7.33 "2019UKLondonGBP"      "Bacon (1 kg)"   1 2019 "GBP" "UK"      "London"     1
     6.67 "2019UKManchesterGBP"  "Bacon (1 kg)"   1 2019 "GBP" "UK"      "Manchester" 1
      8.5 "2020UKManchesterGBP"  "Bacon (1 kg)"   0 2020 "GBP" "UK"      "Manchester" 1
     10.9 "2020UKLondonGBP"      "Bacon (1 kg)"   0 2020 "GBP" "UK"      "London"     1
      7.8 "2020UKLondonGBP"      "Bacon (1 kg)"   1 2020 "GBP" "UK"      "London"     1
     7.09 "2020UKManchesterGBP"  "Bacon (1 kg)"   1 2020 "GBP" "UK"      "Manchester" 1
     1.25 "2014IrelandDublinEUR" "Bananas (1 kg)" 0 2014 "EUR" "Ireland" "Dublin"     0
     1.25 "2014IrelandDublinEUR" "Bananas (1 kg)" 1 2014 "EUR" "Ireland" "Dublin"     0
     1.25 "2015IrelandDublinEUR" "Bananas (1 kg)" 0 2015 "EUR" "Ireland" "Dublin"     0
     1.25 "2015IrelandDublinEUR" "Bananas (1 kg)" 1 2015 "EUR" "Ireland" "Dublin"     0
     1.39 "2016IrelandDublinEUR" "Bananas (1 kg)" 0 2016 "EUR" "Ireland" "Dublin"     1
     1.25 "2016IrelandDublinEUR" "Bananas (1 kg)" 1 2016 "EUR" "Ireland" "Dublin"     1
     1.89 "2017IrelandDublinEUR" "Bananas (1 kg)" 0 2017 "EUR" "Ireland" "Dublin"     1
     1.59 "2017IrelandDublinEUR" "Bananas (1 kg)" 1 2017 "EUR" "Ireland" "Dublin"     1
     1.59 "2018IrelandDublinEUR" "Bananas (1 kg)" 0 2018 "EUR" "Ireland" "Dublin"     1
     1.39 "2018IrelandDublinEUR" "Bananas (1 kg)" 1 2018 "EUR" "Ireland" "Dublin"     1
     1.59 "2019IrelandDublinEUR" "Bananas (1 kg)" 0 2019 "EUR" "Ireland" "Dublin"     1
     1.19 "2019IrelandDublinEUR" "Bananas (1 kg)" 1 2019 "EUR" "Ireland" "Dublin"     1
     1.46 "2020IrelandDublinEUR" "Bananas (1 kg)" 0 2020 "EUR" "Ireland" "Dublin"     1
     1.19 "2020IrelandDublinEUR" "Bananas (1 kg)" 1 2020 "EUR" "Ireland" "Dublin"     1
      .68 "2014UKLondonGBP"      "Bananas (1 kg)" 0 2014 "GBP" "UK"      "London"     0
      1.2 "2014UKManchesterGBP"  "Bananas (1 kg)" 0 2014 "GBP" "UK"      "Manchester" 0
    end

  • #2
    No beverages in your example, but the following is illustrative:

    Code:
    gen newprod= cond(inlist(prod, "Apples (1 kg)", "Bananas (1 kg)"), "Fruits", "Others ")
    encode newprod, gen(product)
    preserve
    collapse abs_price, by(product year)
    xtset product year
    xtline abs_price, overlay scheme(s1color) ytitle("Price") xtitle("")
    restore
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	19.1 KB
ID:	1592234

    Last edited by Andrew Musau; 31 Jan 2021, 14:40.

    Comment


    • #3
      Thanks for the response Andrew--that's really helpful. I wanted to know if there is a way for me to also stipulate "if" for the "xtline" command. I see in the help section I am allowed to, but it seems like the collapse command limits what I want to do with the "if" command. I want to make separate graphs for
      Code:
      if country=="UK"
      if country=="Ireland"
      Do you have any idea how I can utilize the collapse command while still maintaining that ability? Thanks so much!

      Comment


      • #4
        The panel variable in #2 is product, so collapse has already averaged across countries. If you want to have products, countries and years, then you have multiple product panels and cannot use xtline. You can use collapse + twoway with the -by()- option, or collapse + separate+ twoway.

        Code:
        gen newprod= cond(inlist(prod, "Apples (1 kg)", "Bananas (1 kg)"), "Fruits", "Others ")
        encode newprod, gen(product)
        preserve
        collapse abs_price, by(product country year)
        *ALL COMBINATIONS
         tw (line abs_price year, sort by(country product) scheme(s1mono) ytitle("Price") xtitle(""))
        *BY COUNTRY
        separate abs_price, by(product) veryshortlabel
        tw (line abs_price? year, by(country, note("")) lp(dash) scheme(s1mono) ytitle("Price") xtitle(""))
        restore
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	59.9 KB
ID:	1592274

        Click image for larger version

Name:	Graph2.png
Views:	1
Size:	53.0 KB
ID:	1592275

        Comment


        • #5
          Thanks so much that is perfect--exactly what I was looking for. I'm sorry I just have one more question because I am looking to divide everything by city now instead of country. The code I used is:

          Code:
              **graph price trends no regression  
          gen newprod= cond(inlist(prod, "Coca-Cola (1 l)", "Tonic water (200 ml)"), "Soft Drinks", "Others ")
          encode newprod, gen(product)
          preserve
          collapse abs_price_adj, by(store_type product city year)
          *ALL COMBINATIONS
           tw (line abs_price_adj year, sort by(city product store_type) scheme(s1mono) ytitle("Price") xtitle(""))
          *BY COUNTRY
          separate abs_price_adj, by(product) veryshortlabel
          tw (line abs_price_adj? year, by(city, note("")) lp(dash) scheme(s1mono) ytitle("Price") xtitle("")) //I'm not sure how to incorporate store_type here
          restore
          I thought that it would result in clear graphs with the average values, but instead it look like this ( https://imgur.com/a/iTWu1h8 ). If you can't see that image, it looks as though there are vertical lines in some years, making the data not make sense (since there should only be one observation for each year in each of these graphs).



          Do you have any ideas why this may be the case? I've also attached an output of my data below as well. Thank you so much for helping me through this.


          Best,
          Jim


          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input float abs_price_adj str66 prod float store_type int year str3 currency str7 country str10 city str11 newprod long product float(abs_price_adj1 abs_price_adj2)
           .9966667 "Apples (1 kg)"  0 2014 "EUR" "Ireland" "Dublin"     "Others " 1  .9966667 .
            .957265 "Apples (1 kg)"  1 2014 "EUR" "Ireland" "Dublin"     "Others " 1   .957265 .
                  1 "Apples (1 kg)"  0 2015 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
          1.0598291 "Apples (1 kg)"  1 2015 "EUR" "Ireland" "Dublin"     "Others " 1 1.0598291 .
                  1 "Apples (1 kg)"  0 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
                  1 "Apples (1 kg)"  1 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
          1.0666667 "Apples (1 kg)"  0 2017 "EUR" "Ireland" "Dublin"     "Others " 1 1.0666667 .
           .9188035 "Apples (1 kg)"  1 2017 "EUR" "Ireland" "Dublin"     "Others " 1  .9188035 .
           .9966667 "Apples (1 kg)"  0 2018 "EUR" "Ireland" "Dublin"     "Others " 1  .9966667 .
           .9358975 "Apples (1 kg)"  1 2018 "EUR" "Ireland" "Dublin"     "Others " 1  .9358975 .
           .8466667 "Apples (1 kg)"  0 2019 "EUR" "Ireland" "Dublin"     "Others " 1  .8466667 .
          1.0256411 "Apples (1 kg)"  1 2019 "EUR" "Ireland" "Dublin"     "Others " 1 1.0256411 .
                .87 "Apples (1 kg)"  0 2020 "EUR" "Ireland" "Dublin"     "Others " 1       .87 .
           .9615385 "Apples (1 kg)"  1 2020 "EUR" "Ireland" "Dublin"     "Others " 1  .9615385 .
                1.2 "Apples (1 kg)"  0 2014 "GBP" "UK"      "Manchester" "Others " 1       1.2 .
               .975 "Apples (1 kg)"  0 2014 "GBP" "UK"      "London"     "Others " 1      .975 .
                .93 "Apples (1 kg)"  1 2014 "GBP" "UK"      "London"     "Others " 1       .93 .
          1.1028571 "Apples (1 kg)"  1 2014 "GBP" "UK"      "Manchester" "Others " 1 1.1028571 .
               .925 "Apples (1 kg)"  0 2015 "GBP" "UK"      "London"     "Others " 1      .925 .
          1.0476191 "Apples (1 kg)"  0 2015 "GBP" "UK"      "Manchester" "Others " 1 1.0476191 .
                  1 "Apples (1 kg)"  1 2015 "GBP" "UK"      "Manchester" "Others " 1         1 .
               .875 "Apples (1 kg)"  1 2015 "GBP" "UK"      "London"     "Others " 1      .875 .
                  1 "Apples (1 kg)"  0 2016 "GBP" "UK"      "Manchester" "Others " 1         1 .
                  1 "Apples (1 kg)"  0 2016 "GBP" "UK"      "London"     "Others " 1         1 .
                  1 "Apples (1 kg)"  1 2016 "GBP" "UK"      "London"     "Others " 1         1 .
                  1 "Apples (1 kg)"  1 2016 "GBP" "UK"      "Manchester" "Others " 1         1 .
                  1 "Apples (1 kg)"  0 2017 "GBP" "UK"      "London"     "Others " 1         1 .
          1.0476191 "Apples (1 kg)"  0 2017 "GBP" "UK"      "Manchester" "Others " 1 1.0476191 .
                  1 "Apples (1 kg)"  1 2017 "GBP" "UK"      "Manchester" "Others " 1         1 .
                .99 "Apples (1 kg)"  1 2017 "GBP" "UK"      "London"     "Others " 1       .99 .
          1.0952381 "Apples (1 kg)"  0 2018 "GBP" "UK"      "Manchester" "Others " 1 1.0952381 .
               1.06 "Apples (1 kg)"  0 2018 "GBP" "UK"      "London"     "Others " 1      1.06 .
                  1 "Apples (1 kg)"  1 2018 "GBP" "UK"      "London"     "Others " 1         1 .
          1.1257143 "Apples (1 kg)"  1 2018 "GBP" "UK"      "Manchester" "Others " 1 1.1257143 .
               1.02 "Apples (1 kg)"  0 2019 "GBP" "UK"      "London"     "Others " 1      1.02 .
          1.0285715 "Apples (1 kg)"  0 2019 "GBP" "UK"      "Manchester" "Others " 1 1.0285715 .
               .895 "Apples (1 kg)"  1 2019 "GBP" "UK"      "London"     "Others " 1      .895 .
          1.1485714 "Apples (1 kg)"  1 2019 "GBP" "UK"      "Manchester" "Others " 1 1.1485714 .
          1.0190476 "Apples (1 kg)"  0 2020 "GBP" "UK"      "Manchester" "Others " 1 1.0190476 .
               1.05 "Apples (1 kg)"  0 2020 "GBP" "UK"      "London"     "Others " 1      1.05 .
               .925 "Apples (1 kg)"  1 2020 "GBP" "UK"      "London"     "Others " 1      .925 .
          1.0685714 "Apples (1 kg)"  1 2020 "GBP" "UK"      "Manchester" "Others " 1 1.0685714 .
          1.2462462 "Bacon (1 kg)"   0 2014 "EUR" "Ireland" "Dublin"     "Others " 1 1.2462462 .
          1.2387006 "Bacon (1 kg)"   1 2014 "EUR" "Ireland" "Dublin"     "Others " 1 1.2387006 .
           1.015015 "Bacon (1 kg)"   0 2015 "EUR" "Ireland" "Dublin"     "Others " 1  1.015015 .
          1.0508474 "Bacon (1 kg)"   1 2015 "EUR" "Ireland" "Dublin"     "Others " 1 1.0508474 .
                  1 "Bacon (1 kg)"   0 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
                  1 "Bacon (1 kg)"   1 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
           .8648649 "Bacon (1 kg)"   0 2017 "EUR" "Ireland" "Dublin"     "Others " 1  .8648649 .
           .8474576 "Bacon (1 kg)"   1 2017 "EUR" "Ireland" "Dublin"     "Others " 1  .8474576 .
           .6826827 "Bacon (1 kg)"   0 2018 "EUR" "Ireland" "Dublin"     "Others " 1  .6826827 .
           .8926554 "Bacon (1 kg)"   1 2018 "EUR" "Ireland" "Dublin"     "Others " 1  .8926554 .
           .6546547 "Bacon (1 kg)"   0 2019 "EUR" "Ireland" "Dublin"     "Others " 1  .6546547 .
           .6949152 "Bacon (1 kg)"   1 2019 "EUR" "Ireland" "Dublin"     "Others " 1  .6949152 .
           .5905906 "Bacon (1 kg)"   0 2020 "EUR" "Ireland" "Dublin"     "Others " 1  .5905906 .
           .6454802 "Bacon (1 kg)"   1 2020 "EUR" "Ireland" "Dublin"     "Others " 1  .6454802 .
          1.0718113 "Bacon (1 kg)"   0 2014 "GBP" "UK"      "Manchester" "Others " 1 1.0718113 .
           1.167224 "Bacon (1 kg)"   0 2014 "GBP" "UK"      "London"     "Others " 1  1.167224 .
           1.238592 "Bacon (1 kg)"   1 2014 "GBP" "UK"      "Manchester" "Others " 1  1.238592 .
           .7496252 "Bacon (1 kg)"   1 2014 "GBP" "UK"      "London"     "Others " 1  .7496252 .
          1.0334448 "Bacon (1 kg)"   0 2015 "GBP" "UK"      "London"     "Others " 1 1.0334448 .
          1.0182208 "Bacon (1 kg)"   0 2015 "GBP" "UK"      "Manchester" "Others " 1 1.0182208 .
                  1 "Bacon (1 kg)"   1 2015 "GBP" "UK"      "London"     "Others " 1         1 .
          1.0847458 "Bacon (1 kg)"   1 2015 "GBP" "UK"      "Manchester" "Others " 1 1.0847458 .
                  1 "Bacon (1 kg)"   0 2016 "GBP" "UK"      "London"     "Others " 1         1 .
                  1 "Bacon (1 kg)"   0 2016 "GBP" "UK"      "Manchester" "Others " 1         1 .
                  1 "Bacon (1 kg)"   1 2016 "GBP" "UK"      "Manchester" "Others " 1         1 .
                  1 "Bacon (1 kg)"   1 2016 "GBP" "UK"      "London"     "Others " 1         1 .
           .9063545 "Bacon (1 kg)"   0 2017 "GBP" "UK"      "London"     "Others " 1  .9063545 .
           .8724545 "Bacon (1 kg)"   0 2017 "GBP" "UK"      "Manchester" "Others " 1  .8724545 .
           .8057366 "Bacon (1 kg)"   1 2017 "GBP" "UK"      "Manchester" "Others " 1  .8057366 .
                  1 "Bacon (1 kg)"   1 2017 "GBP" "UK"      "London"     "Others " 1         1 .
           .7600334 "Bacon (1 kg)"   0 2018 "GBP" "UK"      "London"     "Others " 1  .7600334 .
           .8617364 "Bacon (1 kg)"   0 2018 "GBP" "UK"      "Manchester" "Others " 1  .8617364 .
          1.1214392 "Bacon (1 kg)"   1 2018 "GBP" "UK"      "London"     "Others " 1 1.1214392 .
           .8344198 "Bacon (1 kg)"   1 2018 "GBP" "UK"      "Manchester" "Others " 1  .8344198 .
           .8928189 "Bacon (1 kg)"   0 2019 "GBP" "UK"      "Manchester" "Others " 1  .8928189 .
           .9138796 "Bacon (1 kg)"   0 2019 "GBP" "UK"      "London"     "Others " 1  .9138796 .
          1.0989505 "Bacon (1 kg)"   1 2019 "GBP" "UK"      "London"     "Others " 1 1.0989505 .
           .8696219 "Bacon (1 kg)"   1 2019 "GBP" "UK"      "Manchester" "Others " 1  .8696219 .
           .9110397 "Bacon (1 kg)"   0 2020 "GBP" "UK"      "Manchester" "Others " 1  .9110397 .
           .9113712 "Bacon (1 kg)"   0 2020 "GBP" "UK"      "London"     "Others " 1  .9113712 .
          1.1694152 "Bacon (1 kg)"   1 2020 "GBP" "UK"      "London"     "Others " 1 1.1694152 .
           .9243807 "Bacon (1 kg)"   1 2020 "GBP" "UK"      "Manchester" "Others " 1  .9243807 .
           .8992806 "Bananas (1 kg)" 0 2014 "EUR" "Ireland" "Dublin"     "Others " 1  .8992806 .
                  1 "Bananas (1 kg)" 1 2014 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
           .8992806 "Bananas (1 kg)" 0 2015 "EUR" "Ireland" "Dublin"     "Others " 1  .8992806 .
                  1 "Bananas (1 kg)" 1 2015 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
                  1 "Bananas (1 kg)" 0 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
                  1 "Bananas (1 kg)" 1 2016 "EUR" "Ireland" "Dublin"     "Others " 1         1 .
          1.3597122 "Bananas (1 kg)" 0 2017 "EUR" "Ireland" "Dublin"     "Others " 1 1.3597122 .
              1.272 "Bananas (1 kg)" 1 2017 "EUR" "Ireland" "Dublin"     "Others " 1     1.272 .
          1.1438849 "Bananas (1 kg)" 0 2018 "EUR" "Ireland" "Dublin"     "Others " 1 1.1438849 .
              1.112 "Bananas (1 kg)" 1 2018 "EUR" "Ireland" "Dublin"     "Others " 1     1.112 .
          1.1438849 "Bananas (1 kg)" 0 2019 "EUR" "Ireland" "Dublin"     "Others " 1 1.1438849 .
               .952 "Bananas (1 kg)" 1 2019 "EUR" "Ireland" "Dublin"     "Others " 1      .952 .
          1.0503597 "Bananas (1 kg)" 0 2020 "EUR" "Ireland" "Dublin"     "Others " 1 1.0503597 .
               .952 "Bananas (1 kg)" 1 2020 "EUR" "Ireland" "Dublin"     "Others " 1      .952 .
           .9444444 "Bananas (1 kg)" 0 2014 "GBP" "UK"      "London"     "Others " 1  .9444444 .
           .9999999 "Bananas (1 kg)" 0 2014 "GBP" "UK"      "Manchester" "Others " 1  .9999999 .
          end
          label values product product
          label def product 1 "Others", modify
          Last edited by Jim Callegari; 01 Feb 2021, 17:16.

          Comment


          • #6
            If you want to combine variables, use the -group()- function of egen. Including the -label- option will tell you what those combinations represent. See

            Code:
            help egen

            If you graph not including all variables that you specify using collapse, you will have such jumps.

            Comment


            • #7
              Thank you so much for all of your help. I am having a bit of trouble with the addplot function (description of this user-created function here). My code and data is below, but I am not sure how I can add a plot just to the first graph (not to both at the same time). I want to add two lines to both of the graphs, but the lines will be at slightly different positions. Right now, I have the lines positioned at x=674 and x=699, but I only want those positions for the UK graph. For the Ireland graph, I would like x=675 and x=700. Do you have any idea how to do that with the same graph file, but for the different side-by-side graphs?

              Best,
              Jim


              Code:
              replace newprod = "Allitems" if prod== "Allitems"
              encode newprod, gen(product_test)
              preserve
              collapse rel_px, by(product_test country ym)
              *ALL COMBINATIONS
               tw (line rel_px ym, sort by(country product_test) scheme(s1mono) ytitle("Price") xtitle(""))
              *BY COUNTRY
              separate rel_px, by(product_test) veryshortlabel
              tw (line rel_px? ym, by(country, note("")) lp(dash) scheme(s1mono) ytitle("Price") xtitle(""))
              addplot: , xline(674, lpattern(dash)) norescaling 
              addplot: , xline(699, lpattern(dash)) norescaling


              Code:
              clear
              input str21 prod double rel_price int year byte month str7 country long id_new str4 category float(ym id) str11 newprod long(product id_new1) float soft_drink_new long country_id float(rel_px soft_drink)
              "Vegetables"             99.4 2017  5 "Ireland" 35 ""     688 33 "Others"      1 33 0 1  .9688109 0
              "Vegetables"             98.5 2017  6 "Ireland" 35 ""     689 33 "Others"      1 33 0 1   .960039 0
              "Vegetables"              100 2017  7 "Ireland" 35 ""     690 33 "Others"      1 33 0 1  .9746589 0
              "Vegetables"            100.5 2017  8 "Ireland" 35 ""     691 33 "Others"      1 33 0 1  .9795322 0
              "Vegetables"             98.3 2017  9 "Ireland" 35 ""     692 33 "Others"      1 33 0 1  .9580897 0
              "Vegetables"             99.1 2017 10 "Ireland" 35 ""     693 33 "Others"      1 33 0 1   .965887 0
              "Vegetables"             98.4 2017 11 "Ireland" 35 ""     694 33 "Others"      1 33 0 1  .9590644 0
              "Vegetables"             98.3 2017 12 "Ireland" 35 ""     695 33 "Others"      1 33 0 1  .9580897 0
              "Vegetables"             97.5 2018  1 "Ireland" 35 ""     696 33 "Others"      1 33 0 1  .9502924 0
              "Vegetables"               96 2018  2 "Ireland" 35 ""     697 33 "Others"      1 33 0 1  .9356725 0
              "Vegetables"             96.9 2018  3 "Ireland" 35 ""     698 33 "Others"      1 33 0 1  .9444445 0
              "Vegetables"             95.4 2018  4 "Ireland" 35 ""     699 33 "Others"      1 33 0 1  .9298246 0
              "Vegetables"             96.6 2018  5 "Ireland" 35 ""     700 33 "Others"      1 33 0 1  .9415205 0
              "Vegetables"             95.2 2018  6 "Ireland" 35 ""     701 33 "Others"      1 33 0 1  .9278753 0
              "Vegetables"             95.8 2018  7 "Ireland" 35 ""     702 33 "Others"      1 33 0 1  .9337232 0
              "Vegetables"               96 2018  8 "Ireland" 35 ""     703 33 "Others"      1 33 0 1  .9356725 0
              "Vegetables"               95 2018  9 "Ireland" 35 ""     704 33 "Others"      1 33 0 1  .9259259 0
              "Vegetables"             98.9 2018 10 "Ireland" 35 ""     705 33 "Others"      1 33 0 1  .9639376 0
              "Vegetables"             97.3 2018 11 "Ireland" 35 ""     706 33 "Others"      1 33 0 1  .9483431 0
              "Vegetables"             99.2 2018 12 "Ireland" 35 ""     707 33 "Others"      1 33 0 1  .9668616 0
              "Vegetables"             98.4 2019  1 "Ireland" 35 ""     708 33 "Others"      1 33 0 1  .9590644 0
              "Vegetables"             98.9 2019  2 "Ireland" 35 ""     709 33 "Others"      1 33 0 1  .9639376 0
              "Vegetables"             98.7 2019  3 "Ireland" 35 ""     710 33 "Others"      1 33 0 1  .9619883 0
              "Vegetables"             99.1 2019  4 "Ireland" 35 ""     711 33 "Others"      1 33 0 1   .965887 0
              "Vegetables"             99.6 2019  5 "Ireland" 35 ""     712 33 "Others"      1 33 0 1  .9707602 0
              "Vegetables"               97 2019  6 "Ireland" 35 ""     713 33 "Others"      1 33 0 1  .9454191 0
              "Vegetables"             99.4 2019  7 "Ireland" 35 ""     714 33 "Others"      1 33 0 1  .9688109 0
              "Vegetables"             98.9 2019  8 "Ireland" 35 ""     715 33 "Others"      1 33 0 1  .9639376 0
              "Vegetables"             96.5 2019  9 "Ireland" 35 ""     716 33 "Others"      1 33 0 1  .9405458 0
              "Vegetables"               96 2019 10 "Ireland" 35 ""     717 33 "Others"      1 33 0 1  .9356725 0
              "Vegetables"             96.7 2019 11 "Ireland" 35 ""     718 33 "Others"      1 33 0 1  .9424952 0
              "Vegetables"             96.4 2019 12 "Ireland" 35 ""     719 33 "Others"      1 33 0 1  .9395711 0
              "Vegetables"             95.8 2020  1 "Ireland" 35 ""     720 33 "Others"      1 33 0 1  .9337232 0
              "Vegetables"             95.3 2020  2 "Ireland" 35 ""     721 33 "Others"      1 33 0 1  .9288499 0
              "Vegetables"             94.7 2020  3 "Ireland" 35 ""     722 33 "Others"      1 33 0 1  .9230019 0
              "Vegetables"             95.5 2020  4 "Ireland" 35 ""     723 33 "Others"      1 33 0 1  .9307992 0
              "Vegetables"             95.8 2020  5 "Ireland" 35 ""     724 33 "Others"      1 33 0 1  .9337232 0
              "Vegetables"             94.3 2020  6 "Ireland" 35 ""     725 33 "Others"      1 33 0 1  .9191033 0
              "Vegetables"             94.4 2020  7 "Ireland" 35 ""     726 33 "Others"      1 33 0 1   .920078 0
              "Vegetables"             93.7 2020  8 "Ireland" 35 ""     727 33 "Others"      1 33 0 1  .9132554 0
              "Vegetables"             93.8 2020  9 "Ireland" 35 ""     728 33 "Others"      1 33 0 1    .91423 0
              "Yoghurt"               103.7 2014  1 "Ireland" 36 ""     648 34 "Others"      1 34 0 1  1.018664 0
              "Yoghurt"               103.8 2014  2 "Ireland" 36 ""     649 34 "Others"      1 34 0 1 1.0196463 0
              "Yoghurt"               102.2 2014  3 "Ireland" 36 ""     650 34 "Others"      1 34 0 1 1.0039293 0
              "Yoghurt"                 104 2014  4 "Ireland" 36 ""     651 34 "Others"      1 34 0 1  1.021611 0
              "Yoghurt"               104.3 2014  5 "Ireland" 36 ""     652 34 "Others"      1 34 0 1  1.024558 0
              "Yoghurt"               103.5 2014  6 "Ireland" 36 ""     653 34 "Others"      1 34 0 1 1.0166994 0
              "Yoghurt"               103.2 2014  7 "Ireland" 36 ""     654 34 "Others"      1 34 0 1 1.0137525 0
              "Yoghurt"               104.4 2014  8 "Ireland" 36 ""     655 34 "Others"      1 34 0 1 1.0255402 0
              "Yoghurt"               101.7 2014  9 "Ireland" 36 ""     656 34 "Others"      1 34 0 1  .9990177 0
              "Yoghurt"               103.5 2014 10 "Ireland" 36 ""     657 34 "Others"      1 34 0 1 1.0166994 0
              "Yoghurt"                 103 2014 11 "Ireland" 36 ""     658 34 "Others"      1 34 0 1 1.0117878 0
              "Yoghurt"               103.3 2014 12 "Ireland" 36 ""     659 34 "Others"      1 34 0 1 1.0147347 0
              "Yoghurt"               104.1 2015  1 "Ireland" 36 ""     660 34 "Others"      1 34 0 1 1.0225933 0
              "Yoghurt"               103.1 2015  2 "Ireland" 36 ""     661 34 "Others"      1 34 0 1   1.01277 0
              "Yoghurt"               101.7 2015  3 "Ireland" 36 ""     662 34 "Others"      1 34 0 1  .9990177 0
              "Yoghurt"               103.2 2015  4 "Ireland" 36 ""     663 34 "Others"      1 34 0 1 1.0137525 0
              "Yoghurt"               103.3 2015  5 "Ireland" 36 ""     664 34 "Others"      1 34 0 1 1.0147347 0
              "Yoghurt"               101.7 2015  6 "Ireland" 36 ""     665 34 "Others"      1 34 0 1  .9990177 0
              "Yoghurt"               102.1 2015  7 "Ireland" 36 ""     666 34 "Others"      1 34 0 1  1.002947 0
              "Yoghurt"               102.8 2015  8 "Ireland" 36 ""     667 34 "Others"      1 34 0 1 1.0098232 0
              "Yoghurt"               100.1 2015  9 "Ireland" 36 ""     668 34 "Others"      1 34 0 1  .9833006 0
              "Yoghurt"               102.1 2015 10 "Ireland" 36 ""     669 34 "Others"      1 34 0 1  1.002947 0
              "Yoghurt"                 103 2015 11 "Ireland" 36 ""     670 34 "Others"      1 34 0 1 1.0117878 0
              "Yoghurt"               102.2 2015 12 "Ireland" 36 ""     671 34 "Others"      1 34 0 1 1.0039293 0
              "Yoghurt"               101.8 2016  1 "Ireland" 36 ""     672 34 "Others"      1 34 0 1  .9999999 0
              "Yoghurt"               102.9 2016  2 "Ireland" 36 ""     673 34 "Others"      1 34 0 1 1.0108055 0
              "Yoghurt"               101.8 2016  3 "Ireland" 36 ""     674 34 "Others"      1 34 0 1  .9999999 0
              "Yoghurt"               100.7 2016  4 "Ireland" 36 ""     675 34 "Others"      1 34 0 1  .9891945 0
              "Yoghurt"               103.3 2016  5 "Ireland" 36 ""     676 34 "Others"      1 34 0 1 1.0147347 0
              "Yoghurt"                 103 2016  6 "Ireland" 36 ""     677 34 "Others"      1 34 0 1 1.0117878 0
              "Yoghurt"               100.9 2016  7 "Ireland" 36 ""     678 34 "Others"      1 34 0 1  .9911591 0
              "Yoghurt"               101.5 2016  8 "Ireland" 36 ""     679 34 "Others"      1 34 0 1   .997053 0
              "Yoghurt"                98.4 2016  9 "Ireland" 36 ""     680 34 "Others"      1 34 0 1  .9666011 0
              "Yoghurt"                99.7 2016 10 "Ireland" 36 ""     681 34 "Others"      1 34 0 1  .9793713 0
              "Yoghurt"                99.1 2016 11 "Ireland" 36 ""     682 34 "Others"      1 34 0 1  .9734774 0
              "Yoghurt"                 100 2016 12 "Ireland" 36 ""     683 34 "Others"      1 34 0 1  .9823182 0
              "Yoghurt"                97.7 2017  1 "Ireland" 36 ""     684 34 "Others"      1 34 0 1  .9597249 0
              "Yoghurt"                98.4 2017  2 "Ireland" 36 ""     685 34 "Others"      1 34 0 1  .9666011 0
              "Yoghurt"                98.2 2017  3 "Ireland" 36 ""     686 34 "Others"      1 34 0 1  .9646365 0
              "Yoghurt"                97.2 2017  4 "Ireland" 36 ""     687 34 "Others"      1 34 0 1  .9548133 0
              "Yoghurt"                97.7 2017  5 "Ireland" 36 ""     688 34 "Others"      1 34 0 1  .9597249 0
              "Yoghurt"                  99 2017  6 "Ireland" 36 ""     689 34 "Others"      1 34 0 1  .9724951 0
              "Yoghurt"                97.7 2017  7 "Ireland" 36 ""     690 34 "Others"      1 34 0 1  .9597249 0
              "Yoghurt"                99.4 2017  8 "Ireland" 36 ""     691 34 "Others"      1 34 0 1  .9764243 0
              "Yoghurt"                98.8 2017  9 "Ireland" 36 ""     692 34 "Others"      1 34 0 1  .9705305 0
              "Yoghurt"                  99 2017 10 "Ireland" 36 ""     693 34 "Others"      1 34 0 1  .9724951 0
              "Yoghurt"                99.3 2017 11 "Ireland" 36 ""     694 34 "Others"      1 34 0 1   .975442 0
              "Yoghurt"                97.7 2017 12 "Ireland" 36 ""     695 34 "Others"      1 34 0 1  .9597249 0
              "Yoghurt"                96.4 2018  1 "Ireland" 36 ""     696 34 "Others"      1 34 0 1  .9469548 0
              "Yoghurt"                97.7 2018  2 "Ireland" 36 ""     697 34 "Others"      1 34 0 1  .9597249 0
              "Yoghurt"                98.5 2018  3 "Ireland" 36 ""     698 34 "Others"      1 34 0 1  .9675835 0
              "Yoghurt"                97.1 2018  4 "Ireland" 36 ""     699 34 "Others"      1 34 0 1   .953831 0
              "Yoghurt"                96.4 2018  5 "Ireland" 36 ""     700 34 "Others"      1 34 0 1  .9469548 0
              "Yoghurt"                96.9 2018  6 "Ireland" 36 ""     701 34 "Others"      1 34 0 1  .9518664 0
              "Yoghurt"               100.5 2018  7 "Ireland" 36 ""     702 34 "Others"      1 34 0 1  .9872298 0
              "Yoghurt"               101.9 2018  8 "Ireland" 36 ""     703 34 "Others"      1 34 0 1 1.0009823 0
              "Yoghurt"               102.1 2018  9 "Ireland" 36 ""     704 34 "Others"      1 34 0 1  1.002947 0
              "Yoghurt"               102.3 2018 10 "Ireland" 36 ""     705 34 "Others"      1 34 0 1 1.0049115 0
              "Yoghurt"               103.8 2018 11 "Ireland" 36 ""     706 34 "Others"      1 34 0 1 1.0196463 0
              "Yoghurt"               103.1 2018 12 "Ireland" 36 ""     707 34 "Others"      1 34 0 1   1.01277 0
              "Yoghurt"               101.3 2019  1 "Ireland" 36 ""     708 34 "Others"      1 34 0 1  .9950884 0
              "Yoghurt"               100.9 2019  2 "Ireland" 36 ""     709 34 "Others"      1 34 0 1  .9911591 0
              "Yoghurt"               102.6 2019  3 "Ireland" 36 ""     710 34 "Others"      1 34 0 1 1.0078585 0
              "Yoghurt"               100.6 2019  4 "Ireland" 36 ""     711 34 "Others"      1 34 0 1  .9882122 0
              "Yoghurt"               100.4 2019  5 "Ireland" 36 ""     712 34 "Others"      1 34 0 1  .9862475 0
              "Yoghurt"               101.5 2019  6 "Ireland" 36 ""     713 34 "Others"      1 34 0 1   .997053 0
              "Yoghurt"               102.3 2019  7 "Ireland" 36 ""     714 34 "Others"      1 34 0 1 1.0049115 0
              "Yoghurt"               101.6 2019  8 "Ireland" 36 ""     715 34 "Others"      1 34 0 1  .9980353 0
              "Yoghurt"                98.1 2019  9 "Ireland" 36 ""     716 34 "Others"      1 34 0 1  .9636542 0
              "Yoghurt"               102.2 2019 10 "Ireland" 36 ""     717 34 "Others"      1 34 0 1 1.0039293 0
              "Yoghurt"               101.9 2019 11 "Ireland" 36 ""     718 34 "Others"      1 34 0 1 1.0009823 0
              "Yoghurt"               102.4 2019 12 "Ireland" 36 ""     719 34 "Others"      1 34 0 1 1.0058938 0
              "Yoghurt"                99.4 2020  1 "Ireland" 36 ""     720 34 "Others"      1 34 0 1  .9764243 0
              "Yoghurt"               100.2 2020  2 "Ireland" 36 ""     721 34 "Others"      1 34 0 1  .9842829 0
              "Yoghurt"               102.9 2020  3 "Ireland" 36 ""     722 34 "Others"      1 34 0 1 1.0108055 0
              "Yoghurt"               103.1 2020  4 "Ireland" 36 ""     723 34 "Others"      1 34 0 1   1.01277 0
              "Yoghurt"               102.9 2020  5 "Ireland" 36 ""     724 34 "Others"      1 34 0 1 1.0108055 0
              "Yoghurt"               102.9 2020  6 "Ireland" 36 ""     725 34 "Others"      1 34 0 1 1.0108055 0
              "Yoghurt"               106.7 2020  7 "Ireland" 36 ""     726 34 "Others"      1 34 0 1 1.0481336 0
              "Yoghurt"                 105 2020  8 "Ireland" 36 ""     727 34 "Others"      1 34 0 1 1.0314342 0
              "Yoghurt"                99.2 2020  9 "Ireland" 36 ""     728 34 "Others"      1 34 0 1  .9744597 0
              "Allitems"                 99 2014  1 "UK"       2 ""     648 35 "Others"      1  1 0 2   .988024 0
              "Allitems"               99.5 2014  2 "UK"       2 ""     649 35 "Others"      1  1 0 2   .993014 0
              "Allitems"               99.7 2014  3 "UK"       2 ""     650 35 "Others"      1  1 0 2    .99501 0
              "Allitems"              100.1 2014  4 "UK"       2 ""     651 35 "Others"      1  1 0 2   .999002 0
              "Allitems"                100 2014  5 "UK"       2 ""     652 35 "Others"      1  1 0 2   .998004 0
              "Allitems"              100.2 2014  6 "UK"       2 ""     653 35 "Others"      1  1 0 2         1 0
              "Allitems"               99.9 2014  7 "UK"       2 ""     654 35 "Others"      1  1 0 2   .997006 0
              "Allitems"              100.2 2014  8 "UK"       2 ""     655 35 "Others"      1  1 0 2         1 0
              "Allitems"              100.3 2014  9 "UK"       2 ""     656 35 "Others"      1  1 0 2  1.000998 0
              "Allitems"              100.4 2014 10 "UK"       2 ""     657 35 "Others"      1  1 0 2  1.001996 0
              "Allitems"              100.1 2014 11 "UK"       2 ""     658 35 "Others"      1  1 0 2   .999002 0
              "Allitems"              100.1 2014 12 "UK"       2 ""     659 35 "Others"      1  1 0 2   .999002 0
              "Allitems"               99.3 2015  1 "UK"       2 ""     660 35 "Others"      1  1 0 2   .991018 0
              "Allitems"               99.5 2015  2 "UK"       2 ""     661 35 "Others"      1  1 0 2   .993014 0
              "Allitems"               99.7 2015  3 "UK"       2 ""     662 35 "Others"      1  1 0 2    .99501 0
              "Allitems"               99.9 2015  4 "UK"       2 ""     663 35 "Others"      1  1 0 2   .997006 0
              "Allitems"              100.1 2015  5 "UK"       2 ""     664 35 "Others"      1  1 0 2   .999002 0
              "Allitems"              100.2 2015  6 "UK"       2 ""     665 35 "Others"      1  1 0 2         1 0
              "Allitems"                100 2015  7 "UK"       2 ""     666 35 "Others"      1  1 0 2   .998004 0
              "Allitems"              100.3 2015  8 "UK"       2 ""     667 35 "Others"      1  1 0 2  1.000998 0
              "Allitems"              100.2 2015  9 "UK"       2 ""     668 35 "Others"      1  1 0 2         1 0
              "Allitems"              100.3 2015 10 "UK"       2 ""     669 35 "Others"      1  1 0 2  1.000998 0
              "Allitems"              100.3 2015 11 "UK"       2 ""     670 35 "Others"      1  1 0 2  1.000998 0
              "Allitems"              100.3 2015 12 "UK"       2 ""     671 35 "Others"      1  1 0 2  1.000998 0
              "Allitems"               99.5 2016  1 "UK"       2 ""     672 35 "Others"      1  1 0 2   .993014 0
              "Allitems"               99.8 2016  2 "UK"       2 ""     673 35 "Others"      1  1 0 2   .996008 0
              "Allitems"              100.2 2016  3 "UK"       2 ""     674 35 "Others"      1  1 0 2         1 0
              "Allitems"              100.2 2016  4 "UK"       2 ""     675 35 "Others"      1  1 0 2         1 0
              "Allitems"              100.4 2016  5 "UK"       2 ""     676 35 "Others"      1  1 0 2  1.001996 0
              "Allitems"              100.6 2016  6 "UK"       2 ""     677 35 "Others"      1  1 0 2 1.0039921 0
              "Allitems"              100.6 2016  7 "UK"       2 ""     678 35 "Others"      1  1 0 2 1.0039921 0
              "Allitems"              100.9 2016  8 "UK"       2 ""     679 35 "Others"      1  1 0 2  1.006986 0
              "Allitems"              101.1 2016  9 "UK"       2 ""     680 35 "Others"      1  1 0 2 1.0089821 0
              "Allitems"              101.2 2016 10 "UK"       2 ""     681 35 "Others"      1  1 0 2 1.0099801 0
              "Allitems"              101.4 2016 11 "UK"       2 ""     682 35 "Others"      1  1 0 2 1.0119761 0
              "Allitems"              101.9 2016 12 "UK"       2 ""     683 35 "Others"      1  1 0 2 1.0169661 0
              "Allitems"              101.4 2017  1 "UK"       2 ""     684 35 "Others"      1  1 0 2 1.0119761 0
              "Allitems"              102.1 2017  2 "UK"       2 ""     685 35 "Others"      1  1 0 2 1.0189621 0
              "Allitems"              102.5 2017  3 "UK"       2 ""     686 35 "Others"      1  1 0 2 1.0229541 0
              "Allitems"              102.9 2017  4 "UK"       2 ""     687 35 "Others"      1  1 0 2 1.0269462 0
              "Allitems"              103.3 2017  5 "UK"       2 ""     688 35 "Others"      1  1 0 2 1.0309381 0
              "Allitems"              103.3 2017  6 "UK"       2 ""     689 35 "Others"      1  1 0 2 1.0309381 0
              "Allitems"              103.2 2017  7 "UK"       2 ""     690 35 "Others"      1  1 0 2 1.0299401 0
              "Allitems"              103.8 2017  8 "UK"       2 ""     691 35 "Others"      1  1 0 2 1.0359281 0
              "Allitems"              104.1 2017  9 "UK"       2 ""     692 35 "Others"      1  1 0 2 1.0389222 0
              "Allitems"              104.2 2017 10 "UK"       2 ""     693 35 "Others"      1  1 0 2 1.0399202 0
              "Allitems"              104.6 2017 11 "UK"       2 ""     694 35 "Others"      1  1 0 2 1.0439122 0
              "Allitems"              104.9 2017 12 "UK"       2 ""     695 35 "Others"      1  1 0 2 1.0469062 0
              "Allitems"              104.4 2018  1 "UK"       2 ""     696 35 "Others"      1  1 0 2 1.0419163 0
              "Allitems"              104.9 2018  2 "UK"       2 ""     697 35 "Others"      1  1 0 2 1.0469062 0
              "Allitems"                105 2018  3 "UK"       2 ""     698 35 "Others"      1  1 0 2 1.0479043 0
              "Allitems"              105.4 2018  4 "UK"       2 ""     699 35 "Others"      1  1 0 2 1.0518962 0
              "Allitems"              105.8 2018  5 "UK"       2 ""     700 35 "Others"      1  1 0 2 1.0558883 0
              "Allitems"              105.8 2018  6 "UK"       2 ""     701 35 "Others"      1  1 0 2 1.0558883 0
              "Allitems"              105.8 2018  7 "UK"       2 ""     702 35 "Others"      1  1 0 2 1.0558883 0
              "Allitems"              106.5 2018  8 "UK"       2 ""     703 35 "Others"      1  1 0 2 1.0628743 0
              "Allitems"              106.6 2018  9 "UK"       2 ""     704 35 "Others"      1  1 0 2 1.0638723 0
              "Allitems"              106.7 2018 10 "UK"       2 ""     705 35 "Others"      1  1 0 2 1.0648702 0
              "Allitems"                107 2018 11 "UK"       2 ""     706 35 "Others"      1  1 0 2 1.0678643 0
              "Allitems"              107.1 2018 12 "UK"       2 ""     707 35 "Others"      1  1 0 2 1.0688623 0
              "Allitems"              106.3 2019  1 "UK"       2 ""     708 35 "Others"      1  1 0 2 1.0608783 0
              "Allitems"              106.8 2019  2 "UK"       2 ""     709 35 "Others"      1  1 0 2 1.0658683 0
              "Allitems"                107 2019  3 "UK"       2 ""     710 35 "Others"      1  1 0 2 1.0678643 0
              "Allitems"              107.6 2019  4 "UK"       2 ""     711 35 "Others"      1  1 0 2 1.0738523 0
              "Allitems"              107.9 2019  5 "UK"       2 ""     712 35 "Others"      1  1 0 2 1.0768464 0
              "Allitems"              107.9 2019  6 "UK"       2 ""     713 35 "Others"      1  1 0 2 1.0768464 0
              "Allitems"              107.9 2019  7 "UK"       2 ""     714 35 "Others"      1  1 0 2 1.0768464 0
              "Allitems"              108.4 2019  8 "UK"       2 ""     715 35 "Others"      1  1 0 2 1.0818363 0
              "Allitems"              108.5 2019  9 "UK"       2 ""     716 35 "Others"      1  1 0 2 1.0828344 0
              "Allitems"              108.3 2019 10 "UK"       2 ""     717 35 "Others"      1  1 0 2 1.0808383 0
              "Allitems"              108.5 2019 11 "UK"       2 ""     718 35 "Others"      1  1 0 2 1.0828344 0
              "Allitems"              108.5 2019 12 "UK"       2 ""     719 35 "Others"      1  1 0 2 1.0828344 0
              "Allitems"              108.2 2020  1 "UK"       2 ""     720 35 "Others"      1  1 0 2 1.0798403 0
              "Allitems"              108.6 2020  2 "UK"       2 ""     721 35 "Others"      1  1 0 2 1.0838324 0
              "Allitems"              108.6 2020  3 "UK"       2 ""     722 35 "Others"      1  1 0 2 1.0838324 0
              "Allitems"              108.5 2020  4 "UK"       2 ""     723 35 "Others"      1  1 0 2 1.0828344 0
              "Allitems"              108.5 2020  5 "UK"       2 ""     724 35 "Others"      1  1 0 2 1.0828344 0
              "Allitems"              108.6 2020  6 "UK"       2 ""     725 35 "Others"      1  1 0 2 1.0838324 0
              "Allitems"              109.1 2020  7 "UK"       2 ""     726 35 "Others"      1  1 0 2 1.0888224 0
              "Allitems"              108.6 2020  8 "UK"       2 ""     727 35 "Others"      1  1 0 2 1.0838324 0
              "Allitems"              109.1 2020  9 "UK"       2 ""     728 35 "Others"      1  1 0 2 1.0888224 0
              "Allitems"              109.1 2020 10 "UK"       2 ""     729 35 "Others"      1  1 0 2 1.0888224 0
              "Bread"                     . 2014  1 "UK"       3 ""     648 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  2 "UK"       3 ""     649 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  3 "UK"       3 ""     650 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  4 "UK"       3 ""     651 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  5 "UK"       3 ""     652 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  6 "UK"       3 ""     653 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  7 "UK"       3 ""     654 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  8 "UK"       3 ""     655 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014  9 "UK"       3 ""     656 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014 10 "UK"       3 ""     657 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014 11 "UK"       3 ""     658 36 "Others"      1  2 0 2         . 0
              "Bread"                     . 2014 12 "UK"       3 ""     659 36 "Others"      1  2 0 2         . 0
              "Bread"                 103.7 2015  1 "UK"       3 ""     660 36 "Others"      1  2 0 2 1.0690721 0
              "Bread"                 102.7 2015  2 "UK"       3 ""     661 36 "Others"      1  2 0 2 1.0587629 0
              "Bread"                 102.4 2015  3 "UK"       3 ""     662 36 "Others"      1  2 0 2 1.0556701 0
              "Bread"                  99.1 2015  4 "UK"       3 ""     663 36 "Others"      1  2 0 2 1.0216495 0
              "Bread"                  99.9 2015  5 "UK"       3 ""     664 36 "Others"      1  2 0 2 1.0298969 0
              "Bread"                  99.6 2015  6 "UK"       3 ""     665 36 "Others"      1  2 0 2 1.0268041 0
              "Bread"                  98.4 2015  7 "UK"       3 ""     666 36 "Others"      1  2 0 2  1.014433 0
              "Bread"                  99.3 2015  8 "UK"       3 ""     667 36 "Others"      1  2 0 2 1.0237113 0
              "Bread"                  99.6 2015  9 "UK"       3 ""     668 36 "Others"      1  2 0 2 1.0268041 0
              "Bread"                  99.1 2015 10 "UK"       3 ""     669 36 "Others"      1  2 0 2 1.0216495 0
              "Bread"                  97.2 2015 11 "UK"       3 ""     670 36 "Others"      1  2 0 2 1.0020618 0
              "Bread"                  98.9 2015 12 "UK"       3 ""     671 36 "Others"      1  2 0 2 1.0195876 0
              "Bread"                  97.2 2016  1 "UK"       3 ""     672 36 "Others"      1  2 0 2 1.0020618 0
              "Bread"                  98.7 2016  2 "UK"       3 ""     673 36 "Others"      1  2 0 2 1.0175258 0
              "Bread"                    97 2016  3 "UK"       3 ""     674 36 "Others"      1  2 0 2         1 0
              "Bread"                  96.8 2016  4 "UK"       3 ""     675 36 "Others"      1  2 0 2  .9979382 0
              "Bread"                  96.1 2016  5 "UK"       3 ""     676 36 "Others"      1  2 0 2  .9907216 0
              "Bread"                  97.7 2016  6 "UK"       3 ""     677 36 "Others"      1  2 0 2 1.0072165 0
              "Bread"                  95.3 2016  7 "UK"       3 ""     678 36 "Others"      1  2 0 2  .9824742 0
              "Bread"                  97.3 2016  8 "UK"       3 ""     679 36 "Others"      1  2 0 2 1.0030928 0
              "Bread"                  97.1 2016  9 "UK"       3 ""     680 36 "Others"      1  2 0 2 1.0010309 0
              "Bread"                  96.9 2016 10 "UK"       3 ""     681 36 "Others"      1  2 0 2  .9989691 0
              "Bread"                  97.9 2016 11 "UK"       3 ""     682 36 "Others"      1  2 0 2 1.0092783 0
              "Bread"                  98.1 2016 12 "UK"       3 ""     683 36 "Others"      1  2 0 2 1.0113403 0
              "Bread"                  99.3 2017  1 "UK"       3 ""     684 36 "Others"      1  2 0 2 1.0237113 0
              "Bread"                  99.9 2017  2 "UK"       3 ""     685 36 "Others"      1  2 0 2 1.0298969 0
              "Bread"                 100.1 2017  3 "UK"       3 ""     686 36 "Others"      1  2 0 2 1.0319588 0
              "Bread"                 100.3 2017  4 "UK"       3 ""     687 36 "Others"      1  2 0 2 1.0340207 0
              end
              format %tm ym
              label values id_new id_new
              label def id_new 2 "Allitems", modify
              label def id_new 3 "Bread", modify
              label def id_new 4 "Breadandcereals", modify
              label def id_new 5 "Chocolate", modify
              label def id_new 6 "Cocoaandpowderedchoc", modify
              label def id_new 7 "Coffee", modify
              label def id_new 8 "Coffeeteaandcocoa", modify
              label def id_new 9 "Confectioneryproducts", modify
              label def id_new 10 "Crisps", modify
              label def id_new 11 "Edibleicesandicecre", modify
              label def id_new 12 "Eggs", modify
              label def id_new 13 "Electricitygasandot", modify
              label def id_new 14 "Fish", modify
              label def id_new 15 "Floursandothercereal", modify
              label def id_new 16 "Food", modify
              label def id_new 17 "Footwear", modify
              label def id_new 18 "Freshlowfatmilk", modify
              label def id_new 19 "Freshwholemilk", modify
              label def id_new 20 "Fruit", modify
              label def id_new 21 "Fruitandvegetablejui", modify
              label def id_new 22 "Housingwaterelectri", modify
              label def id_new 23 "Jamsmarmaladesandho", modify
              label def id_new 24 "Meat", modify
              label def id_new 25 "Milkcheeseandeggs", modify
              label def id_new 26 "Mineralorspringwater", modify
              label def id_new 27 "Mineralwaterssoftdr", modify
              label def id_new 29 "Rice", modify
              label def id_new 30 "Softdrinks", modify
              label def id_new 31 "Sugar", modify
              label def id_new 32 "Sugarjamhoneychoc", modify
              label def id_new 33 "Tea", modify
              label def id_new 34 "Tobacco", modify
              label def id_new 35 "Vegetables", modify
              label def id_new 36 "Yoghurt", modify
              label values product product
              label def product 1 "Others", modify
              label def product 2 "Soft Drinks", modify
              label values id_new1 id_new1
              label def id_new1 1 "Allitems", modify
              label def id_new1 2 "Bread", modify
              label def id_new1 3 "Breadandcereals", modify
              label def id_new1 4 "Chocolate", modify
              label def id_new1 5 "Cocoaandpowderedchoc", modify
              label def id_new1 6 "Coffee", modify
              label def id_new1 7 "Coffeeteaandcocoa", modify
              label def id_new1 8 "Confectioneryproducts", modify
              label def id_new1 9 "Crisps", modify
              label def id_new1 10 "Edibleicesandicecre", modify
              label def id_new1 11 "Eggs", modify
              label def id_new1 12 "Electricitygasandot", modify
              label def id_new1 13 "Fish", modify
              label def id_new1 14 "Floursandothercereal", modify
              label def id_new1 15 "Food", modify
              label def id_new1 16 "Footwear", modify
              label def id_new1 17 "Freshlowfatmilk", modify
              label def id_new1 18 "Freshwholemilk", modify
              label def id_new1 19 "Fruit", modify
              label def id_new1 20 "Fruitandvegetablejui", modify
              label def id_new1 21 "Housingwaterelectri", modify
              label def id_new1 22 "Jamsmarmaladesandho", modify
              label def id_new1 23 "Meat", modify
              label def id_new1 24 "Milkcheeseandeggs", modify
              label def id_new1 25 "Mineralorspringwater", modify
              label def id_new1 26 "Mineralwaterssoftdr", modify
              label def id_new1 27 "Rice", modify
              label def id_new1 28 "Softdrinks", modify
              label def id_new1 29 "Sugar", modify
              label def id_new1 30 "Sugarjamhoneychoc", modify
              label def id_new1 31 "Tea", modify
              label def id_new1 32 "Tobacco", modify
              label def id_new1 33 "Vegetables", modify
              label def id_new1 34 "Yoghurt", modify
              label values country_id country_id
              label def country_id 1 "Ireland", modify
              label def country_id 2 "UK", modify

              Comment


              • #8
                Right now, I have the lines positioned at x=674 and x=699, but I only want those positions for the UK graph. For the Ireland graph, I would like x=675 and x=700.
                I do not use the community contributed command addplot, so I cannot help you with that, sorry. Leaving some room, y-axis max is about 1.1. You can generate new variables and add other by graphs.

                Code:
                replace newprod = "Allitems" if prod== "Allitems"
                encode newprod, gen(product_test)
                preserve
                collapse rel_px, by(product_test country ym)
                *ALL COMBINATIONS
                 tw (line rel_px ym, sort by(country product_test) scheme(s1mono) ytitle("Price") xtitle(""))
                *BY COUNTRY
                separate rel_px, by(product_test) veryshortlabel
                
                gen max=1.1
                gen x= cond(country=="Ireland", 675, 674)
                gen xx= cond(country=="Ireland", 700, 699)
                
                tw (line rel_px? ym, by(country, note("")) lp(dash) ///
                scheme(s1mono) ytitle("Price") xtitle("")) ///
                (dropline max x, by(country, note("")) lp("_-.") ///
                lw(thin) mcolor(none)) (dropline max xx, by(country, ///
                note("")) lp("_-.") lw(thin) mcolor(none) ///
                plotregion(margin(zero)) leg(order(1 2)))
                Res.:

                Click image for larger version

Name:	Graph.png
Views:	1
Size:	41.7 KB
ID:	1593676

                Comment


                • #9
                  You can make a separate graph for each of the two countries, so that each graph has the xline in the approriate place. Then combine them with a single legend using, for example,
                  Code:
                  view net describe grc1leg2, from("http://digital.cgdev.org/doc/stata/MO/Misc")

                  Comment


                  • #10
                    Sure, you can use graph combine. But do note that in a number of cases, the by() option of graph can work better than graph combine. In many instances such as #8, exploiting the flexibility of twoway negates the need to resort to graph combine.

                    Comment


                    • #11
                      Thanks, @Andrew Musau , for the link to Nick Cox 's Stata tip #139. The help file to grc1leg2 now references his exposition. I agree that graph ... , by() should be the first choice for producing a multipanel graph with a single legend in many situations. Still, as I pointed out here, there are some occasions when I find it more convenient to use grc1leg2 than graph ... , by().

                      Comment


                      • #12
                        Mead Over, there are indeed a great number of situations where using the -by()- option of graph is not feasible. I will update my copy of grc1leg2 and thanks for such a useful and convenient command.

                        Comment


                        • #13
                          Hi All,

                          Thank you for all the help on this--I have been trying to use the by feature (paired with the user-created addplot command) and the combine feature unfortunately to no avail. Using your guidance, I was able to create a plot of "Soft drinks" vs "Sweet" and a plot of "Soft drinks" vs "Substitutes" for each country side by side which are great on their own, but I would like to overlay them so it's a plot of "Soft drinks" vs "Sweet" vs "Substitutes." This would not be a problem if the "Sweet" grouping included some of the same products as the "Substitutes" grouping does, so I cannot simply replace my "category" variable with different values for which category the observation is in because some products are in both groupings. I've attached my data below as well as the code I have tried to use. Please let me know if you have any suggestions for this--the combine command did not overly (they just squished all 4 sections together).


                          Code:
                          preserve
                          replace newprod = "Allitems" if prod== "Allitems"
                          
                          replace category="Soft Drink" if prod=="Softdrinks"
                          
                          replace category ="" if prod=="Crisps" | inlist(prod,"Sugar", "Jamsmarmaladesandho", "Chocolate", "Confectioneryproducts", "Edibleicesandicecre") 
                          
                          replace category="Substitute" if category=="sub"
                          
                          collapse rel_px, by(category country ym)
                          
                          drop if category==""
                          
                           tw (line rel_px ym, sort by(country category) scheme(s1mono) ytitle("Price") xtitle(""))
                          *BY COUNTRY
                          separate rel_px, by(category) veryshortlabel
                          
                          gen max=1.2
                          gen x= cond(country=="Ireland", 675, 674)
                          gen xx= cond(country=="Ireland", 700, 699)
                          
                          drop if ym<660
                          
                          
                          tw (line rel_px? ym, by(country, note("")) lp(dash) ///
                          scheme(s1mono) xlab(660 684 708   ) ytitle("Price") xtitle("")) ///
                          (dropline max x, by(country, note("")) lp("_-.") ///
                          lw(thin) mcolor(none)) (dropline max xx, by(country, ///
                          note("")) lp("_-.") lw(thin) mcolor(none) ///
                          plotregion(margin(zero)) leg(order(1 2)))
                          ***this worked^^
                          **********
                          
                          
                          *******trying addplot to merge figure 3/4
                          
                          restore
                          
                          replace category=""
                          replace category="Sweet" if sweet==1
                          replace category="Soft Drink" if prod=="Softdrinks"
                          
                          
                          collapse rel_px, by(category country ym)
                          
                          drop if category==""
                          
                          separate rel_px, by(category) veryshortlabel
                          
                          gen max=1.2
                          gen x= cond(country=="Ireland", 675, 674)
                          gen xx= cond(country=="Ireland", 700, 699)
                          
                          drop if ym<660
                          
                          addplot: (line rel_px? ym, by(country, note("")) lp(dash) ///
                          scheme(s1mono) xlab(660 684 708   ) ytitle("Price") xtitle("")) ///
                          (dropline max x, by(country, note("")) lp("_-.") ///
                          lw(thin) mcolor(none)) (dropline max xx, by(country, ///
                          note("")) lp("_-.") lw(thin) mcolor(none) ///
                          plotregion(margin(zero)) leg(order(1 2)))

                          Code:
                          option by() not allowed
                          r(198);
                          Code:
                          * Example generated by -dataex-. To install: ssc install dataex
                          clear
                          input str21 prod double rel_price int year byte month float ym str7 country str4 category float sweet long product
                          "Allitems"  99.1 2015  1 660 "Ireland" "" 0 1
                          "Allitems"  99.7 2015  2 661 "Ireland" "" 0 1
                          "Allitems" 100.3 2015  3 662 "Ireland" "" 0 1
                          "Allitems" 100.3 2015  4 663 "Ireland" "" 0 1
                          "Allitems" 100.7 2015  5 664 "Ireland" "" 0 1
                          "Allitems" 100.9 2015  6 665 "Ireland" "" 0 1
                          "Allitems" 100.7 2015  7 666 "Ireland" "" 0 1
                          "Allitems" 101.1 2015  8 667 "Ireland" "" 0 1
                          "Allitems" 100.6 2015  9 668 "Ireland" "" 0 1
                          "Allitems" 100.4 2015 10 669 "Ireland" "" 0 1
                          "Allitems" 100.1 2015 11 670 "Ireland" "" 0 1
                          "Allitems"   100 2015 12 671 "Ireland" "" 0 1
                          "Allitems"  99.2 2016  1 672 "Ireland" "" 0 1
                          "Allitems"  99.6 2016  2 673 "Ireland" "" 0 1
                          "Allitems"   100 2016  3 674 "Ireland" "" 0 1
                          "Allitems" 100.2 2016  4 675 "Ireland" "" 0 1
                          "Allitems" 100.7 2016  5 676 "Ireland" "" 0 1
                          "Allitems" 101.4 2016  6 677 "Ireland" "" 0 1
                          "Allitems" 101.2 2016  7 678 "Ireland" "" 0 1
                          "Allitems"   101 2016  8 679 "Ireland" "" 0 1
                          "Allitems" 100.6 2016  9 680 "Ireland" "" 0 1
                          "Allitems" 100.1 2016 10 681 "Ireland" "" 0 1
                          "Allitems"   100 2016 11 682 "Ireland" "" 0 1
                          "Allitems"   100 2016 12 683 "Ireland" "" 0 1
                          "Allitems"  99.5 2017  1 684 "Ireland" "" 0 1
                          "Allitems" 100.1 2017  2 685 "Ireland" "" 0 1
                          "Allitems" 100.7 2017  3 686 "Ireland" "" 0 1
                          "Allitems" 101.1 2017  4 687 "Ireland" "" 0 1
                          "Allitems" 100.9 2017  5 688 "Ireland" "" 0 1
                          "Allitems"   101 2017  6 689 "Ireland" "" 0 1
                          "Allitems"   101 2017  7 690 "Ireland" "" 0 1
                          "Allitems" 101.4 2017  8 691 "Ireland" "" 0 1
                          "Allitems" 100.8 2017  9 692 "Ireland" "" 0 1
                          "Allitems" 100.7 2017 10 693 "Ireland" "" 0 1
                          "Allitems" 100.5 2017 11 694 "Ireland" "" 0 1
                          "Allitems" 100.4 2017 12 695 "Ireland" "" 0 1
                          "Allitems"  99.7 2018  1 696 "Ireland" "" 0 1
                          "Allitems" 100.6 2018  2 697 "Ireland" "" 0 1
                          "Allitems" 100.9 2018  3 698 "Ireland" "" 0 1
                          "Allitems" 100.7 2018  4 699 "Ireland" "" 0 1
                          "Allitems" 101.3 2018  5 700 "Ireland" "" 0 1
                          "Allitems" 101.4 2018  6 701 "Ireland" "" 0 1
                          "Allitems" 101.8 2018  7 702 "Ireland" "" 0 1
                          "Allitems" 102.1 2018  8 703 "Ireland" "" 0 1
                          "Allitems" 101.7 2018  9 704 "Ireland" "" 0 1
                          "Allitems" 101.6 2018 10 705 "Ireland" "" 0 1
                          "Allitems" 101.1 2018 11 706 "Ireland" "" 0 1
                          "Allitems" 101.1 2018 12 707 "Ireland" "" 0 1
                          "Allitems" 100.4 2019  1 708 "Ireland" "" 0 1
                          "Allitems" 101.2 2019  2 709 "Ireland" "" 0 1
                          "Allitems"   102 2019  3 710 "Ireland" "" 0 1
                          "Allitems" 102.4 2019  4 711 "Ireland" "" 0 1
                          "Allitems" 102.3 2019  5 712 "Ireland" "" 0 1
                          "Allitems" 102.5 2019  6 713 "Ireland" "" 0 1
                          "Allitems" 102.3 2019  7 714 "Ireland" "" 0 1
                          "Allitems" 102.8 2019  8 715 "Ireland" "" 0 1
                          "Allitems" 102.6 2019  9 716 "Ireland" "" 0 1
                          "Allitems" 102.3 2019 10 717 "Ireland" "" 0 1
                          "Allitems" 102.2 2019 11 718 "Ireland" "" 0 1
                          "Allitems" 102.4 2019 12 719 "Ireland" "" 0 1
                          "Allitems" 101.7 2020  1 720 "Ireland" "" 0 1
                          "Allitems" 102.3 2020  2 721 "Ireland" "" 0 1
                          "Allitems" 102.7 2020  3 722 "Ireland" "" 0 1
                          "Allitems" 102.3 2020  4 723 "Ireland" "" 0 1
                          "Allitems" 101.8 2020  5 724 "Ireland" "" 0 1
                          "Allitems" 102.1 2020  6 725 "Ireland" "" 0 1
                          "Allitems" 101.9 2020  7 726 "Ireland" "" 0 1
                          "Allitems" 101.8 2020  8 727 "Ireland" "" 0 1
                          "Allitems" 101.4 2020  9 728 "Ireland" "" 0 1
                          "Bread"    101.9 2015  1 660 "Ireland" "" 0 1
                          "Bread"    102.2 2015  2 661 "Ireland" "" 0 1
                          "Bread"    101.6 2015  3 662 "Ireland" "" 0 1
                          "Bread"    101.5 2015  4 663 "Ireland" "" 0 1
                          "Bread"    101.3 2015  5 664 "Ireland" "" 0 1
                          "Bread"    100.6 2015  6 665 "Ireland" "" 0 1
                          "Bread"    100.6 2015  7 666 "Ireland" "" 0 1
                          "Bread"    100.1 2015  8 667 "Ireland" "" 0 1
                          "Bread"    100.3 2015  9 668 "Ireland" "" 0 1
                          "Bread"     99.8 2015 10 669 "Ireland" "" 0 1
                          "Bread"     99.9 2015 11 670 "Ireland" "" 0 1
                          "Bread"      100 2015 12 671 "Ireland" "" 0 1
                          "Bread"    100.1 2016  1 672 "Ireland" "" 0 1
                          "Bread"      100 2016  2 673 "Ireland" "" 0 1
                          "Bread"      100 2016  3 674 "Ireland" "" 0 1
                          "Bread"     99.9 2016  4 675 "Ireland" "" 0 1
                          "Bread"      100 2016  5 676 "Ireland" "" 0 1
                          "Bread"    100.4 2016  6 677 "Ireland" "" 0 1
                          "Bread"    100.3 2016  7 678 "Ireland" "" 0 1
                          "Bread"      100 2016  8 679 "Ireland" "" 0 1
                          "Bread"    100.2 2016  9 680 "Ireland" "" 0 1
                          "Bread"      100 2016 10 681 "Ireland" "" 0 1
                          "Bread"     99.9 2016 11 682 "Ireland" "" 0 1
                          "Bread"      100 2016 12 683 "Ireland" "" 0 1
                          "Bread"     99.7 2017  1 684 "Ireland" "" 0 1
                          "Bread"     99.8 2017  2 685 "Ireland" "" 0 1
                          "Bread"     99.9 2017  3 686 "Ireland" "" 0 1
                          "Bread"     99.9 2017  4 687 "Ireland" "" 0 1
                          "Bread"     99.6 2017  5 688 "Ireland" "" 0 1
                          "Bread"     99.4 2017  6 689 "Ireland" "" 0 1
                          "Bread"     99.7 2017  7 690 "Ireland" "" 0 1
                          end
                          format %tm ym
                          label values product product
                          label def product 1 "Others", modify

                          Comment


                          • #14
                            If your question is directed to me, sorry I do not follow. I did not use the user-written addplot command in #8, but the -addplot()- option of twoway as explicitly stated. I am unable to advise how you can proceed using the addplot command as I do not use it, but your question remains open for anyone who has insights on this.

                            Comment


                            • #15
                              Correction: Read #14 as "but twoway as explicity stated". There is no -addplot()- option in twoway. The reason is obvious: twoway allows multiple plots. The -addplot()- option is available for other twoway-type Stata graphs that are themselves not twoway, an example being marginsplot.

                              Comment

                              Working...
                              X