May 10, 2016

Chapter 6 of Allison's (2009) book on Fixed-Effects Regression Models using Stata

use http://statisticalhorizons.com/wp-content/uploads/nlsy.dta, clear
 
// Random effects model
sem (Falpha -> anti90@1 anti92@1 anti94@1) /// 
    (anti90 <- pov90@a self90@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
    (anti92 <- pov92@a self92@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) ///  
    (anti94 <- pov94@a self94@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
   , cov(Falpha*pov90@0   Falpha*pov92@0    Falpha*pov94@0    /// 
         Falpha*self90@0  Falpha*self92@0   Falpha*self94@0   /// 
         Falpha*black@0   Falpha*hispanic@0 Falpha*childage@0 /// 
         Falpha*married@0 Falpha*gender@0   Falpha*momage@0   /// 
         Falpha*momwork@0)                                    /// 
     var(e.anti90@j       e.anti92@j        e.anti94@j)
estimates store random
  
// Fixed effects model
sem (Falpha -> anti90@1 anti92@1 anti94@1) /// 
    (anti90 <- pov90@a self90@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
    (anti92 <- pov92@a self92@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) ///  
    (anti94 <- pov94@a self94@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
   , cov(Falpha*black@0   Falpha*hispanic@0 Falpha*childage@0 /// 
         Falpha*married@0 Falpha*gender@0   Falpha*momage@0   /// 
         Falpha*momwork@0)                                    /// 
     var(e.anti90@j       e.anti92@j        e.anti94@j)
estimates store fixed
  
// Compromise model
sem (Falpha -> anti90@1 anti92@1 anti94@1) /// 
    (anti90 <- pov90@a self90@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
    (anti92 <- pov92@a self92@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) ///  
    (anti94 <- pov94@a self94@b black@c hispanic@d childage@e married@f gender@g momage@h momwork@i) /// 
   , cov(Falpha*self90@0  Falpha*self92@0   Falpha*self94@0   /// 
         Falpha*black@0   Falpha*hispanic@0 Falpha*childage@0 /// 
         Falpha*married@0 Falpha*gender@0   Falpha*momage@0   /// 
         Falpha*momwork@0)                                    /// 
     var(e.anti90@j       e.anti92@j        e.anti94@j)
estimates store compromise

// Table 6.1
estimates table random fixed compromise, ///
          b(%9.3f) se(%9.3f) ///
          keep(anti90:self90   anti90:pov90    anti90:black ///
               anti90:hispanic anti90:childage anti90:married ///
               anti90:gender   anti90:momage   anti90:momwork)

// Table 6.2
// Shows covariances instead of correlations
estimates table fixed, b t keep(cov(pov90,Falpha):_cons cov(pov92,Falpha):_cons cov(pov94,Falpha):_cons ///
                            cov(self90,Falpha):_cons cov(self92,Falpha):_cons cov(self94,Falpha):_cons)

// Table 6.3
use http://statisticalhorizons.com/wp-content/uploads/occ.dta, clear  
// Thanks to http://www.stata.com/statalist/archive/2013-10/msg00019.html

sem (Falpha -> pf2@1 pf3@1 pf4@1) ///
    (pf4 <- pf3@a mdwgf3@b) /// 
    (pf3 <- pf2@a mdwgf2@b) /// 
    (pf2 <- pf1@a mdwgf1@b ERR1@1), ///
    cov(e.pf2@0) cov(ERR1*_oexogenous@0 ERR1*Falpha@0 ERR1*mdwgf3) method(mlmv)
estimates store medianwage

sem (Falpha -> mdwgf2@1 mdwgf3@1 mdwgf4@1) /// 
    (mdwgf4 <- pf3@a mdwgf3@b) /// 
    (mdwgf3 <- pf2@a mdwgf2@b) /// 
    (mdwgf2 <- pf1@a mdwgf1@b ERR1@1), ///
    cov(e.mdwgf2@0) cov(ERR1*_oexogenous@0 ERR1*Falpha@0 ERR1*pf3) method(mlmv)
estimates store proportionfemale

esttab medianwage proportionfemale, ///
       b(%9.3f) se(%9.3f) ///
       keep(main:pf1 main:mdwgf1)

Reference

Allison, Paul D. 2009. Fixed Effects Regression Models. Sage. doi: 10.4135/9781412993869