Hi all, moderately new Stata user here using Version 15.1.
I have two groups (male and female) to be different colors on a two way rcap scatter plot (code attached below), but I cannot seem to get that to work. Males are coded as 1 and females as 0, and I need them on the same panel (not two separate panels), so I can't do by(male1female0). Every time I try and change the color in the code by using mcolor(blue) for example, it changes all of them. I have the data in rows, with each row representing 1 age and sex category (so 12 lines in total, since there are 6 age groups and 2 sexes). I created an "agecatjitter" variable, so for males it's slightly right of the marker, and for females it's slightly left of the marker.
Here's my code:
label define agecat 1 "12-14" 2 "14-16" 3 "16-18" 4 "18-20" 5 "20-22" 6 "Over 22"
label values agecat agecat
label define male1fe0 0 "Female" 1 "Male"
label values male1fe0 male1fe0
gen agecatjitter = agecat + 0.20 if male1fe0 == 1
replace agecatjitter = agecat - 0.20 if male1fe0 == 0
twoway rcap upper lower agecatjitter, lstyle(ci) || scatter prop agecatjitter, xlabel(,valuelabel) xlabel(1(1)6) xtitle(Age Category) ylabel(0(10)100) legend(off) ytitle(Percentage) title(Statistic by sex)
This produces a scatter plot with 12 markers with confidence intervals, but they're all the same color. I'm wanting the males whose age categories end in .20 to be one color (say blue), and the females whose age categories end in .80 to be another (say gray) while keeping them on the same graph. Any advice is appreciated. Thank you!
Best,
Andrea
Related Posts with Using rcap scatter but can't figure out how to get 2 different colors of markers
Converting a code from Stata to RHello guys, I'm new to both Satata and R. I'm trying to do a regression to find the causal effect be…
Dividing a column by anotherHello everyone, I use the command below in Stata 17 to calculate the total income and total tax paid…
Negative predicted values after xtnbreg on nested count dataI am analyzing how many comments a social media picture of a women gets based on how good looking th…
data structure transformationHi How can the left structure be transformed into the right one? The 'school' indicates school id.…
Poisson regression formulaHello everyone, I am trying to write this Code: xtpoisson patents cl.ln_xrdintensity##cl.Numberof…
Subscribe to:
Post Comments (Atom)
0 Response to Using rcap scatter but can't figure out how to get 2 different colors of markers
Post a Comment