Reputation: 9
I want to plot linear graph of the fraction of 1's and 0's I have in my main variable of interest by gender.
I know how to do that using bargraphs, either using count or mean but these commands do not seem to work in twoway graphs.
Can someone provide me with a quick guide?
Upvotes: 0
Views: 8709
Reputation: 37278
OP reports in a comment that this works:
graph bar (mean) fertzer, over(sexhead2) by(wave)
Here fertzer
is an indicator variable (dummy, so-called) with value 1 if households use fertilizer and 0 otherwise; sexhead2
is also an indicator for household head being male or female and wave
indicates year 2011 or 2012.
But trying to get a line graph with this syntax fails:
graph twoway (mean) fertzer, over(sexhead2) by(wave)
Here is an analogue of this question with syntax that works:
sysuse auto, clear
gen himpg = mpg > 20
egen mean = mean(himpg), by(foreign rep78)
line mean rep78, by(foreign) ytitle(fraction with more than 20 miles/gallon) yla(, ang(h)) sort
twoway connected mean rep78, by(foreign) ytitle(fraction with more than 20 miles/gallon) yla(, ang(h)) sort
With twoway
, unlike graph hbar
, graph bar
or graph dot
you must create the means as a new variable before graphing. Syntax such as (mean)
is not offered with twoway
.
Upvotes: 0