Announcement

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

  • #16
    Hi Andrew,

    Thanks for your reply--I'm not wedded to using the -addplot()- option in twoway (and clearly that is not possible). I was more wondering if you may have any suggestions on how to plot graphs in a similar style to the kind which I have above (Ireland on the left and the UK on the right, plotting the average of a group of products called "sweet" and a single product soft drink). Rather than graphing just sweet vs. soft drink, I would like to plot another category substitutes, but I was running into a problem because some products (namely "Cocoaandpowderedchoc") are contained within both "sweet" and "sub." Thus, in the "category" variable, I cannot simply reassign the value to be a specific group depending on what variables are in the group because for "Cocoaandpowderedchoc", I want to classify it both as "sweet" and "sub." Do you possibly have any suggestions for methods to plot an average of a group of products alongside another group of products while the groups contain some of the same products? My original method involves doing something like:

    Code:
    replace category ="sweet" if prod=="Chocolate" | prod=="Cocoaandpowderedchoc" | prod=="Confectioneryproducts" | prod=="Edibleicesandicecre" | prod=="sugar"
    And then it would result in 1 variable that has all of the group names I was interested in and then collapsing and graphing based on that. But now because some products fall into two groups, it does not seem like the same method will work in the same way. Please let me know if you have any ideas on how to solve this! Thanks so much.

    Many thanks

    Comment


    • #17
      Nothing stops you from generating the averages yourself. Below, company 1 is in both groups.

      Code:
      webuse grunfeld, clear
      bys year: egen invest_g1= mean(cond(inlist(company, 1, 2, 3), invest, .))
      bys year: egen invest_g2= mean(cond(inlist(company, 1, 9, 10), invest, .))
      tw (line invest_g1 year) (line invest_g2 year, lp(--) xtitle("") scheme(s1mono))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	49.6 KB
ID:	1597311

      Last edited by Andrew Musau; 11 Mar 2021, 06:14.

      Comment

      Working...
      X