I'm working with some survey data and need to produce line graphs to display how the percentage of respondents giving a particular answer has changed over time, ideally being able to plot multiple demographics on one graph. I have several different variables I need to do this for, and each variable needs to be broken out by half a dozen different demographic groups. I can generate the data I want easily enough with tab ..., nofreq row, but am struggling with how to get Stata to extract that information into something that can be graphed.
So in the example below, I want to plot the percentage of under-35 non-voters by year, along with the percentage of over-35 non-voters by year.
Code:
. tab year voter if age<35, nofreq row year | Did r vote in any | election | 0 1 | Total -----------+----------------------+---------- 1998 | 46.84 53.16 | 100.00 2000 | 59.49 40.51 | 100.00 2002 | 47.91 52.09 | 100.00 2004 | 61.59 38.41 | 100.00 2006 | 46.69 53.31 | 100.00 2008 | 60.83 39.17 | 100.00 2010 | 44.09 55.91 | 100.00 2012 | 51.41 48.59 | 100.00 2014 | 45.33 54.67 | 100.00 2016 | 60.52 39.48 | 100.00 2018 | 47.31 52.69 | 100.00 -----------+----------------------+---------- Total | 51.86 48.14 | 100.00 . tab year voter if age>35, nofreq row year | Did r vote in any | election | 0 1 | Total -----------+----------------------+---------- 1998 | 22.24 77.76 | 100.00 2000 | 29.15 70.85 | 100.00 2002 | 19.60 80.40 | 100.00 2004 | 26.80 73.20 | 100.00 2006 | 23.57 76.43 | 100.00 2008 | 30.12 69.88 | 100.00 2010 | 19.50 80.50 | 100.00 2012 | 27.03 72.97 | 100.00 2014 | 22.09 77.91 | 100.00 2016 | 28.30 71.70 | 100.00 2018 | 20.94 79.06 | 100.00 -----------+----------------------+---------- Total | 24.45 75.55 | 100.00
Array
I'm on Stata 11, so some of the solutions I've come across like tab2xl or putexcel aren't available to me.
I have seen some suggestions that I could generate a new variable that would capture the information I want—i.e., in the example above, every case that matched under 35 and 2018, that new variable would tagged 47.31, and then I just plot the mean of that variable sorted by year. But I haven't figured that out yet.
Again, apologies if my question isn't stated very clearly. I appreciate any guidance, and thanks.
0 Response to Producing line plots from two-way table frequency categories
Post a Comment