Dec 28, 2017

Random graphs (123): Descriptive statistics

// Open Allbus 2010
use v11 v13 v15 v17 v19 using ZA4612_v1-0-1.dta, clear

// Prepare variables
recode v11 v13 v15 v17 v19 (99 = .)
label define x 1 `""1" "Unimportant""' 7 `""7 Very" "important"'

label var v11 "v11: Job security"
label var v13 "v13: High income"
label var v15 "v15: Opportunities for promotion"
label var v17 "v17: Respectable occupation"
label var v19 "v19: Lots of leisure time"

// Plot histograms
foreach x of varlist v11 v13 v15 v17 v19 {
  label val `x' x
  histogram `x', frequency ///
                 xlabel(1 (1) 7, val) ///
                 ylabel(0 (500) 1500) ///
                 ytick(0 (250) 1750) ///
                 name(`x', replace) nodraw
}

// Calculate correlation matrix
cor v11-v19
matrix correlations = r(C)

// Plot correlation matrix
plotmatrix, mat(correlations) split(-1(0.10)1) color(sienna) ///
            freq formatcells(%6.2f) nodiag legend(title(Pearson's {it:r}) col(1)) ///
            name(cormatrix, replace) nodraw 

// Combine plots
graph combine v11 v13 v15 v17 v19 cormatrix, col(2) ysize(8) xsize(6) altshrink