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
Create a variable measuring change of score from one wave to anotherThere are three waves of data in the survey I use. My independent variable (a score) is continuous a…
winsor or truncate variable into a dummy variableGreetings everyone, is there any way I can use stata to get variables are winsorized so that the la…
Interacting with stata temporary variables within mata functionsI am attempting to pass a value within a mata function to a stata temporary variable in an ado file.…
Exporting a table to LatexHi everyone, I have the following code: table prov immig sex if inlist(immig,1,2) and I am trying …
Reversing scale for variables like life expectancy, enrollment ratesHello wonderful Stata helpers, I know this is less Stata-specific and more conceptual, but I would a…
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