A Parallel Coordinate Plot in Stata

You can generate a parallel coordinate plot in Stata using macros and a forvalues{} loop. This graph also makes use of the ds command, so all string variables are removed from varlist without having to drop them from the dataset.

To generate this graph in Stata, use the following commands:

sysuse auto, clear
 
local count = 1
ds, not(type string)
foreach i of varlist `r(varlist)' {
    summarize `i', detail
    
    local labels `"`labels' text( 1.2 `count' `=char(34)'`i'`=char(34)' `=char(34)'`=string(`r(max)',"%8.2f")'`=char(34)' , orientation(vertical) placement(north) size(3) justification(left)) text( -0.1 `count' `=char(34)' `i'`=char(34)' `=char(34)'`=string(`r(min)',"%8.2f")'`=char(34)' , orientation(vertical) placement(south) size(3) justification(right)) "'
    
    generate x`count' = (`i' - r(min))/(r(max) - r(min))
    local ++count
}
 
display `"`labels'"'
 
drop if missing(rep78)
generate id = \_n
reshape long x, i(id) j(type)
 
drop if x > 100
 
twoway (line x type if for==1, lcolor(red) c(L)) (line x type if for==0, lcolor(blue) c(L)), xline(1/12) `labels' yscale( off range(0 1.1)) xscale(off) text(0 0 "MIN") text(1 0 "Max") graphregion(margin(t=20 b=20)) legend(off)