Insecurity Code 2

This do-file creates Table 1 (p. 61) in the SMH paper.

// Task: descriptives for table 1
// 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. Check missing patterns and generate vars
******************************************

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

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 < .

******************************************
*** 3. Descriptives
******************************************

// overall
global var "generalhappy mntlhlth jobinsecurity income1 income2 income3 income4 female age black married divorced widow nvmarried babies preteen teens PT year2006"
matrix stats = J(19, 5, -99)
matrix list stats
matrix colnames stats = N Mean StdDev Min Max
matrix rownames stats = $var

local irow = 0
foreach varname in $var {
local ++irow
  quietly sum `varname' if mnumber == 0 [aw = wtssnr]
  matrix stats[`irow', 1] = r(N)
  matrix stats[`irow', 2] = r(mean)
  matrix stats[`irow', 3] = r(sd)
  matrix stats[`irow', 4] = r(min)
  matrix stats[`irow', 5] = r(max)
}
matrix list stats, format(%9.2f)

// year 2006
matrix stats = J(19, 5, -99)
matrix list stats
matrix colnames stats = N Mean StdDev Min Max
matrix rownames stats = $var

local irow = 0
foreach varname in $var {
  local ++irow
  quietly sum `varname' if mnumber == 0 & year == 2006 [aw = wtssnr]
  matrix stats[`irow', 1] = r(N)
  matrix stats[`irow', 2] = r(mean)
  matrix stats[`irow', 3] = r(sd)
  matrix stats[`irow', 4] = r(min)
  matrix stats[`irow', 5] = r(max)
}
matrix list stats, format(%9.2f)

// year 2010
matrix stats = J(19, 5, -99)
matrix list stats
matrix colnames stats = N Mean StdDev Min Max
matrix rownames stats = $var

local irow = 0
foreach varname in $var {
  local ++irow
  quietly sum `varname' if mnumber == 0 & year == 2010 [aw = wtssnr]
  matrix stats[`irow', 1] = r(N)
  matrix stats[`irow', 2] = r(mean)
  matrix stats[`irow', 3] = r(sd)
  matrix stats[`irow', 4] = r(min)
  matrix stats[`irow', 5] = r(max)
}
matrix list stats, format(%9.2f)

******************************************
*** 4. t-tests between years
******************************************

foreach var in $var {
  display "**********`var'"
  ttest `var' if mnumber == 0, by(year2006)
}

******************************************
*** 5. Correlation matrix
******************************************

corr $var if mnumber == 0