Announcement

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

  • Plotting Proportions of Groups Over Time

    Consider the following
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year float(over50 grassnew)
    1973 1 0
    1973 1 0
    1973 0 1
    1973 0 0
    1973 1 0
    1973 0 0
    1973 0 0
    1973 0 1
    1973 1 0
    1973 0 0
    1973 1 0
    1973 0 0
    1973 1 0
    1973 0 0
    1973 0 0
    1973 1 1
    1973 0 1
    1973 0 0
    1973 1 1
    1973 1 0
    1973 1 0
    1973 0 0
    1973 0 0
    1973 1 0
    1973 1 1
    1973 0 0
    1973 1 0
    1973 0 0
    1973 1 0
    1973 0 1
    1973 1 0
    1973 1 0
    1973 1 0
    1973 1 0
    1973 0 1
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 1 0
    1973 0 1
    1973 1 0
    1973 1 0
    1973 0 1
    1973 0 0
    1973 0 1
    1973 1 1
    1973 0 0
    1973 0 1
    1973 0 0
    1973 0 0
    1973 0 1
    1973 1 0
    1973 0 0
    1973 1 0
    1973 0 0
    1973 1 0
    1973 0 0
    1973 1 0
    1973 1 0
    1973 0 1
    1973 0 0
    1973 1 0
    1973 1 0
    1973 1 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 1
    1973 0 1
    1973 0 1
    1973 1 0
    1973 0 0
    1973 0 0
    1973 0 1
    1973 1 0
    1973 1 1
    1973 0 0
    1973 1 0
    1973 1 0
    1973 1 0
    1973 1 0
    1973 0 1
    1973 0 1
    1973 0 0
    1973 0 0
    1973 0 0
    1973 0 1
    1973 1 0
    1973 1 0
    1973 0 0
    1973 0 0
    1973 0 0
    1973 1 0
    1973 0 0
    1973 1 0
    end
    I have survey respondent data, from 1973 to 2018. I want to plot, by age group (over50, over/under 50, 1, 0 respectively) how many people support legalizing cannabis (grassnew, 1 who supports, else 0). My first thought is to collapse this, so we get the proportion/mean of people who say yes in each year, and in each age group... But this would be tricky, since I'd need to create more variables/frames to do this.

    is there a more elaborate way to do this, simply to plot the group level support trends over time?

  • #2
    Code:
    egen toshow = mean(grassnew), by(over50 year)
    gets you the proportions and using instead

    Code:
    mean(100 * grassnew)
    gets you the percents.

    Now that's only 46 X 2 distinct data points so to avoid massive overplotting

    Code:
    egen tag = tag(over50 year) 
    
    
    line toshow year if over50 & tag || line toshow year if !over50 & tag , legend(order(1 "over 50" 2 "under 50"))
    Which way do 50 year olds go?

    Comment


    • #3
      So, the first way that comes to my mind for this is
      Code:
      collapse (mean) grassnew, by(year over50)
      reshape wide grassnew, i(year) j(over50)
      graph twoway connect grassnew* year
      And I take it you saw this, too. I guess I don't grasp what you consider tricky about this. If you object to the reshape, you could do this:
      Code:
      collapse (mean) grassnew, by(year over50)
      twoway (connect grassnew year if over50 == 0) (connect grassnew year if over50 == 1)

      Comment


      • #4
        Do you have survey weights or design elements to consider?

        Comment


        • #5
          No thankfully🤣 either way, Nick and Clyde's ways both worked!

          Comment

          Working...
          X