Showing posts with label plotmatix. Show all posts
Showing posts with label plotmatix. Show all posts

Aug 13, 2017

Random graphs (110): Correlation heatmap

// Open Allbus 2010 data
use "ZA4612_v1-0-1.dta", clear

// Men 25-64 only
keep if v298 == 1
keep if inrange(v301, 20, 64)

// Combine top bottom variables into one 
// (Seems pointless, though, as education in years
//  was only measured in one of the splits)
generate topbot = v933 if v933 <= 10
replace  topbot = v827 if missing(topbot)
replace  topbot =    . if topbot > 10

// Education, truncated to 5th-95th percentile
qui sum v917 if v917 < 94, detail 
generate education = v917 if v917 < 94
replace  education = r(p95) if education >=  r(p95) & !missing(education)
replace  education = r(p95) if education >=  r(p95) & !missing(education)
replace  education =  r(p5) if education <=   r(p5) & !missing(education)

// ISEI
generate isei88 = v358 if !inlist(v358, 0, 99)
replace  isei88 = v392 if !inlist(v392, 0, 99)

// Household income, logged
generate income = v674 if !inlist(v674, 99997, 99999)
generate lnincome = log(income)

// Generate correlation matrix
cor topbot education income isei
matrix correlations = r(C)

// Plot
plotmatrix, mat(correlations) split(-1(0.10)1) color(vermillion) ///
            freq formatcells(%6.2f) nodiag legend(title(Pearson's {it:r}) col(1))