Insecurity Code 3

This do-file creates Table 2 (p. 63), Table 3 (p. 64-65), and Table 4 (p. 67) in the SMH paper.

// Task: models
// Project: insecurity in context

******************************************
*** 0. Program setup
******************************************

version 11.2
set linesize 80
set maxvar 10000
clear all
macro drop _all

******************************************
*** 1. Open the data set
******************************************

use "2013-05-11 vars generated.dta"
drop if age > 65
drop if selfemployed == 1

******************************************
*** 2. Analytic sample and weight
******************************************

misschk generalhappy mntlhlth jobinsecurity logincome female age black divorced widow nvmarried babies preteen teens selfemployed PT year, gen(m)

// weight set-up
svyset sampcode [pw = wtssnr], strata(year)

******************************************
*** 3. Prepare vars
******************************************

sum incomerec if mnumber == 0, d
gen income1 = (incomerec <= 18750) if mnumber == 0 & incomerec < .
gen income2 = (incomerec > 18750 & incomerec <= 32500) if mnumber == 0 & incomerec < .
gen income3 = (incomerec > 32500 & incomerec <= 55000) if mnumber == 0 & incomerec < .
gen income4 = (incomerec > 55000) if mnumber == 0 & incomerec < .
gen incomer = 1 if income1 == 1
  replace incomer = 2 if income2 == 1
  replace incomer = 3 if income3 == 1
  replace incomer = 4 if income4 == 1

gen jobinsecurityyear2010 = jobinsecurity * year2010
  label var jobinsecurityyear2010 "jobinsecurity * year2010"

global covar "female age agesq black divorced widow nvmarried babies preteen teens selfemployed PT"

// global output
global outreg1 "outreg2 using "gss1", excel bdec(3) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)"
global outreg2 "outreg2 using "gss2", excel bdec(3) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)"
global outreg3 "outreg2 using "gss3", excel bdec(3) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, +)"

******************************************
*** 4. Tables
******************************************
**************************
*** 4.1. Table 2
**************************

foreach var of varlist generalhappy {
  svy, subpop(if mnumber == 0): reg `var' year2010 jobinsecurity $covar logincome if mnumber == 0
  $outreg1

  svy, subpop(if mnumber == 0 & year == 2006): reg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & year == 2006
  est store m1
  $outreg1
  svy, subpop(if mnumber == 0 & year == 2010): reg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & year == 2010
  est store m2
  $outreg1
}
suest m1 m2
test [m1]jobinsecurity = [m2]jobinsecurity

foreach var of varlist mntlhlth {
  svy, subpop(if mnumber == 0): nbreg `var' year2010 jobinsecurity $covar logincome if mnumber == 0
  $outreg1

  svy, subpop(if mnumber == 0 & year == 2006): nbreg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & year == 2006
  est store m3
  $outreg1
  svy, subpop(if mnumber == 0 & year == 2010): nbreg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & year == 2010
  est store m4
  $outreg1
}
suest m3 m4
test [m3_mntlhlth]jobinsecurity = [m4_mntlhlth]jobinsecurity
est clear

**************************
*** 4.2. Table 3
**************************

foreach var of varlist generalhappy {
  svy, subpop(if mnumber == 0 & income1 == 1): reg `var' year2010 jobinsecurity $covar if mnumber == 0 & income1 == 1
  est store m1
  $outreg2
  svy, subpop(if mnumber == 0 & income2 == 1): reg `var' year2010 jobinsecurity $covar if mnumber == 0 & income2 == 1
  est store m2
  $outreg2
  svy, subpop(if mnumber == 0 & income3 == 1): reg `var' year2010 jobinsecurity $covar if mnumber == 0 & income3 == 1
  est store m3
  $outreg2
  svy, subpop(if mnumber == 0 & income4 == 1): reg `var' year2010 jobinsecurity $covar if mnumber == 0 & income4 == 1
  est store m4
  $outreg2

  svy, subpop(if mnumber == 0 & income1 == 1): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income1 == 1
  est store m5
  $outreg2
  svy, subpop(if mnumber == 0 & income2 == 1): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income2 == 1
  est store m6
  $outreg2
  svy, subpop(if mnumber == 0 & income3 == 1): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income3 == 1
  est store m7
  $outreg2
  svy, subpop(if mnumber == 0 & income4 == 1): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income4 == 1
  est store m8
  $outreg2
}
suest m1 m2 m3 m4
test [m1]jobinsecurity = [m2]jobinsecurity = [m3]jobinsecurity = [m4]jobinsecurity
suest m5 m6 m7 m8
test [m5]jobinsecurityyear2010 = [m6]jobinsecurityyear2010 = [m7]jobinsecurityyear2010 = [m8]jobinsecurityyear2010
est clear

foreach var of varlist mntlhlth {
  svy, subpop(if mnumber == 0 & income1 == 1): nbreg `var' year2010 jobinsecurity $covar if mnumber == 0 & income1 == 1
  est store m1
  $outreg2
  svy, subpop(if mnumber == 0 & income2 == 1): nbreg `var' year2010 jobinsecurity $covar if mnumber == 0 & income2 == 1
  est store m2
  $outreg2
  svy, subpop(if mnumber == 0 & income3 == 1): nbreg `var' year2010 jobinsecurity $covar if mnumber == 0 & income3 == 1
  est store m3
  $outreg2
  svy, subpop(if mnumber == 0 & income4 == 1): nbreg `var' year2010 jobinsecurity $covar if mnumber == 0 & income4 == 1
  est store m4
  $outreg2

  svy, subpop(if mnumber == 0 & income1 == 1): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income1 == 1
  est store m5
  $outreg2
  svy, subpop(if mnumber == 0 & income2 == 1): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income2 == 1
  est store m6
  $outreg2
  svy, subpop(if mnumber == 0 & income3 == 1): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income3 == 1
  est store m7
  $outreg2
  svy, subpop(if mnumber == 0 & income4 == 1): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar if mnumber == 0 & income4 == 1
  est store m8
  $outreg2
}
suest m1 m2 m3 m4
test [m1_mntlhlth]jobinsecurity = [m2_mntlhlth]jobinsecurity = [m3_mntlhlth]jobinsecurity = [m4_mntlhlth]jobinsecurity
suest m5 m6 m7 m8
test [m5_mntlhlth]jobinsecurityyear2010 = [m6_mntlhlth]jobinsecurityyear2010 = [m7_mntlhlth]jobinsecurityyear2010 = [m8_mntlhlth]jobinsecurityyear2010
est clear

**************************
*** 4.3. Table 4
**************************

foreach var of varlist generalhappy {
  svy, subpop(if mnumber == 0 & female == 0): reg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & female == 0
  est store m1
  $outreg3
  svy, subpop(if mnumber == 0 & female == 1): reg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & female == 1
  est store m2
  $outreg3

  svy, subpop(if mnumber == 0 & female == 0): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar logincome if mnumber == 0 & female == 0
  est store m3
  $outreg3
  svy, subpop(if mnumber == 0 & female == 1): reg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar logincome if mnumber == 0 & female == 1
  est store m4
  $outreg3
}
suest m1 m2
test [m1]jobinsecurity = [m2]jobinsecurity
suest m3 m4
test [m3]jobinsecurityyear2010 = [m4]jobinsecurityyear2010
est clear

foreach var of varlist mntlhlth {
  svy, subpop(if mnumber == 0 & female == 0): nbreg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & female == 0
  est store m1
  $outreg3
  svy, subpop(if mnumber == 0 & female == 1): nbreg `var' year2010 jobinsecurity $covar logincome if mnumber == 0 & female == 1
  est store m2
  $outreg3

  svy, subpop(if mnumber == 0 & female == 0): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar logincome if mnumber == 0 & female == 0
  est store m3
  $outreg3
  svy, subpop(if mnumber == 0 & female == 1): nbreg `var' year2010 jobinsecurity jobinsecurityyear2010 $covar logincome if mnumber == 0 & female == 1
  est store m4
  $outreg3
}
suest m1 m2
test [m1_mntlhlth]jobinsecurity = [m2_mntlhlth]jobinsecurity
suest m3 m4
test [m3_mntlhlth]jobinsecurityyear2010 = [m4_mntlhlth]jobinsecurityyear2010
est clear