Greetings,
I'm running Stata 15.1 on OSX. I'd like to graph the % of respondents who use social media by political ideology and survey year. That is, I'd like to be able to illustrate what percent of liberals, moderates and conservatives, respectively, use social media overtime. I can obtain the weighted proportions in a bar graph, but am unable to reproduce them in a two-way line graph. I tried browsing the archives here, but didn't find any help. My example data below consists of 5 variables: sns_use (the social media variable), 3 dummy-coded ideology variables, a year variable (year_sns) and the sample weights.
This is the code I've been using:
And here is some example data:
Any help will be much appreciated. Thanks!
I'm running Stata 15.1 on OSX. I'd like to graph the % of respondents who use social media by political ideology and survey year. That is, I'd like to be able to illustrate what percent of liberals, moderates and conservatives, respectively, use social media overtime. I can obtain the weighted proportions in a bar graph, but am unable to reproduce them in a two-way line graph. I tried browsing the archives here, but didn't find any help. My example data below consists of 5 variables: sns_use (the social media variable), 3 dummy-coded ideology variables, a year variable (year_sns) and the sample weights.
This is the code I've been using:
Code:
egen libsns_mean=mean(sns_use) if ideo3==1, by(year_sns) egen modsns_mean=mean(sns_use) if ideo3==2, by(year_sns) egen consns_mean=mean(sns_use) if ideo3==3, by(year_sns) egen allsns_mean=mean(sns_use), by(year_sns)
Code:
twoway (line allsns_mean libsns_mean modsns_mean consns_mean year_sns [pweight=weight]), xlabel(2010 2012 2014 2015 2016) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle("Year") ytitle("Percent") legend(order(1 "Overall" 2 "Liberal" 3 "Moderate" 4 "Conservative"))
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double sns_use float year_sns double(ideo3 weight) 0 2010 3 1.08 0 2010 2 1.92 0 2010 2 4.32 0 2010 3 1.96 1 2010 2 4.24 0 2010 2 4.24 1 2010 3 3.24 0 2010 . 1.12 0 2010 . 3.96 0 2010 1 5.72 0 2010 3 2.4 0 2010 1 8.08 0 2010 3 8.92 1 2010 3 5.04 0 2010 1 5.16 1 2010 2 4.44 0 2010 1 1 1 2010 3 3.44 1 2010 3 4.4 0 2010 2 3 0 2010 3 1.72 0 2010 2 6 0 2010 1 5.96 0 2010 2 5.96 0 2010 3 1 1 2010 2 4.72 0 2010 3 2 1 2010 3 3.64 0 2010 2 2.8 0 2010 3 2.36 0 2010 3 5.64 0 2010 3 3.8 0 2010 3 1.96 0 2010 2 3 1 2010 3 3.24 0 2010 2 2.88 0 2010 3 1.24 1 2010 3 2.88 0 2010 2 4.76 0 2010 2 2.88 1 2010 1 3 1 2010 . 3.36 0 2010 1 2.48 0 2010 . 1.72 0 2010 1 9.84 0 2010 2 2.8 1 2010 1 10.72 1 2010 1 3.76 0 2010 3 5.96 1 2010 3 3.88 1 2010 3 1.72 0 2010 2 1.72 1 2010 1 5.96 0 2010 3 2.36 0 2010 3 2.68 1 2010 2 2.64 1 2010 3 4.8 1 2010 3 5.96 0 2010 2 3.04 1 2010 3 1.72 0 2010 2 1.08 0 2010 1 1 1 2010 3 2.52 0 2010 1 2.28 0 2010 2 1.72 0 2010 1 5.96 0 2010 3 4.44 0 2010 3 1 1 2010 2 6.48 0 2010 2 1.72 0 2010 3 5.96 1 2010 1 2.36 0 2010 1 3.24 0 2010 2 1.72 0 2010 3 2.08 0 2010 2 1.72 0 2010 3 3.56 0 2010 3 1.76 0 2010 3 2.36 0 2010 3 1.72 0 2010 3 1.24 1 2010 2 5.96 0 2010 . 2.16 0 2010 2 3.28 0 2010 3 3.4 1 2010 3 5.96 0 2010 . 1.04 1 2010 2 1 0 2010 3 6.84 0 2010 . 2 0 2010 3 1.72 0 2010 2 2.56 1 2010 3 2.2 0 2010 3 2.48 0 2010 1 2.08 1 2010 2 4.96 0 2010 2 5.96 1 2010 2 2.56 1 2010 2 3.44 0 2010 3 2 end label values ideo3 ideo3 label def ideo3 1 "Liberal", modify label def ideo3 2 "Moderate", modify label def ideo3 3 "Conservative", modify
Comment