Mar 9, 2018

Mediation analysis

This replicates two illustrations from Iacobucci (2008).

// Section 3.3 (pp. 21-23)
  // Illustration in section 3.4.1 (pp. 25-26) is identical, just the number of 
  // observations should be 100

  // Read in data
clear
ssd init y x m
ssd set observations 50
#delimit ;
ssd set corr 
 1.00 \
 0.45 1.00 \
 0.63 0.55 1.00
;
#delimit cr

// SEM approach
sem (m <- x) (y <- m x)
  // Calculation by hand
di (_b[m:x] * _b[y:m]) / ((_b[m:x] * _b[y:m]) +  _b[y:x])
  // Calculation via estat, teffects
estat teffects, compact
matrix b_indirect = r(indirect)
matrix b_total = r(total)

scalar indirect  = el(b_indirect, 1, 3)
scalar total = el(b_total, 1, 3)

di "Proportion of total effect mediated by M: "  indirect/total
  
// Section 4.2 (pp. 35-38)
  // Read in data
clear
ssd init y x m q
ssd set observations 50
#delimit ;
ssd set corr 
 1.00 \
 0.45 1.00 \
 0.63 0.55 1.00 \
 0.40 0.40 0.40 1.00
;
#delimit cr

// Figure 4.3
  // Baseline
sem (m <- x) (y <- m x) 
  // (a)
sem (m <- x) (y <- m x) (x <- q)
  // (b)
sem (m <- x) (y <- m x) (x -> q)
  // (d)
sem (m <- x) (y <- m x) (m -> q)
  // (e)
sem (m <- x) (y <- m x) (y -> q)

// Figure 4.4
  // (c) r's = .40
sem (m <- x) (y <- m x) (m <- q)  
  // (e) r's = .40
sem (m <- x) (y <- m x) (y <- q)  

clear
ssd init y x m q
ssd set observations 50
#delimit ;
ssd set corr 
 1.00 \
 0.45 1.00 \
 0.63 0.55 1.00 \
 0.70 0.70 0.70 1.00
;
#delimit cr
  // (c') r's = .70
sem (m <- x) (y <- m x) (m <- q)  
  // (e') r's = .70
sem (m <- x) (y <- m x) (y <- q)  

//


Reference

Iacobucci, Dawn. 2008. Mediation Analysis. Sage. doi: 10.4135/9781412984966