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
Multilevel (mixed): How to decide between different COV() options?Dear Statalist members, I am currently running some multi-level models. However, I wonder how to de…
reorder rows from -expand-I would like the output from the -expand- command but with the rows in a different order. As a simpl…
Merging datasetsHi Users, I just got access to a dataset (M) which I need to merge with another data based on id an…
Graph bar by two groups in one chart (not combined)Hello Statalist, I would like to put two graphs in one chart. (1) bar graph (mean) of output by nat…
Working with dates and loopIs it possible to get a loop that works with every string variable which are in date format (CCYY-NN…
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