From the course: The Modern Stata Playbook: Critical Enhancements You Need to Know
Unlock this course with a free trial
Join today to access over 25,100 courses taught by industry experts.
Using variables to color graphs - Stata Tutorial
From the course: The Modern Stata Playbook: Critical Enhancements You Need to Know
Using variables to color graphs
Colors matter a lot in graphs. One powerful use of color is mapping a third variable onto a two-way plot, Y versus X for example, and that can reveal new and complex patterns. In older versions of Stata you often had to use repetitive if-qualifiers to achieve this kind of effect. That resulted in some pretty long code segments. Thankfully now you can avoid all of this with the new ColorVar option. The new ColorVar option can be used across many two-way graphs, including scatter plots, line plots, bar charts, and more. Simply add the ColorVar option to the relevant graph command, and that's it. You have to specify a variable. The variable can be continuous or categorical. If you specify a continuous variable, it produces gradient scales, and if you specify a categorical variable, it produces discrete color levels. So let's go have a look at this in Stata. Here we are in Stata. I've already loaded the auto-training data, and let's call the help file for two-way. This is where most of…