Load libraries

Read in data

Visualize DVs

## [1] "Visualize distribution of outcome variables"

Create covs

Create sample

Assess & drop missing data

print("Percentage of missing values by column and in DF- ")
## [1] "Percentage of missing values by column and in DF- "
100*(colSums(is.na(dfSample)) / nrow(dfSample))
##          state           year        entered        entryRt          child 
##           0.00           0.00           0.00           0.00           0.00 
##        agedout          fcPop         agedRt         LessHS        foodIns 
##           0.00           0.00           0.00           0.00           0.00 
##        unempRt        singPar        chpovRt          gspPc policy_updated 
##           0.00           0.00           0.00           0.00           0.00 
##        crimeRt         pctBlk         pctHis       tanf3fam        mediPpl 
##           0.00           0.00           0.00           0.00           0.00 
##        snapPpl        tanfPpl      welfarePc        incarRt        deathRt 
##           0.00           0.00           0.25           0.00           0.25 
##       policePc 
##           0.25
(sum(is.na(dfSample))/prod(dim(dfSample)))*100
## [1] 0.02884615
dfSample <- na.omit(dfSample)

Center variables

scaled <- scale(dfSample[c(9:26)])
dfSample_scaled <- cbind(dfSample[c(1:8)],scaled)
dfSample_scaled$year_c <- dfSample_scaled$year - 2004
obsN=1:nrow(dfSample_scaled)

Replicate Edwards multilevel entry model

enterModel <- glmer(entered ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc + policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl + mediPpl + tanfPpl*welfarePc + incarRt + deathRt + policePc + (1 | state) + (1 | year_c) + (1 | obsN), offset=log(child),data=dfSample_scaled,family=poisson)

summary(enterModel)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: entered ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc +  
##     policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl +  
##     mediPpl + tanfPpl * welfarePc + incarRt + deathRt + policePc +  
##     (1 | state) + (1 | year_c) + (1 | obsN)
##    Data: dfSample_scaled
##  Offset: log(child)
## 
##      AIC      BIC   logLik deviance df.resid 
##  12547.7  12650.7  -6251.9  12503.7      774 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -0.86772 -0.07050  0.00174  0.05521  0.59608 
## 
## Random effects:
##  Groups Name        Variance  Std.Dev.
##  obsN   (Intercept) 2.251e-02 0.150038
##  state  (Intercept) 1.005e-01 0.316957
##  year_c (Intercept) 2.779e-05 0.005272
## Number of obs: 796, groups:  obsN, 796; state, 50; year_c, 16
## 
## Fixed effects:
##                    Estimate Std. Error  z value Pr(>|z|)    
## (Intercept)       -5.516188   0.045295 -121.783  < 2e-16 ***
## unempRt           -0.036678   0.013165   -2.786 0.005334 ** 
## singPar           -0.002707   0.033728   -0.080 0.936040    
## foodIns           -0.010893   0.009614   -1.133 0.257221    
## chpovRt            0.039929   0.022912    1.743 0.081390 .  
## LessHS            -0.053588   0.024207   -2.214 0.026845 *  
## gspPc             -0.065049   0.019317   -3.367 0.000759 ***
## policy_updated     0.218737   0.033182    6.592 4.34e-11 ***
## crimeRt            0.033664   0.016983    1.982 0.047460 *  
## pctBlk            -0.236345   0.048275   -4.896 9.79e-07 ***
## tanf3fam           0.035964   0.024327    1.478 0.139317    
## snapPpl           -0.058738   0.013627   -4.310 1.63e-05 ***
## mediPpl            0.074239   0.014351    5.173 2.30e-07 ***
## tanfPpl            0.023493   0.011340    2.072 0.038301 *  
## welfarePc          0.016663   0.018311    0.910 0.362823    
## incarRt            0.048840   0.023001    2.123 0.033718 *  
## deathRt            0.023635   0.007701    3.069 0.002148 ** 
## policePc          -0.005718   0.012742   -0.449 0.653638    
## tanfPpl:welfarePc -0.000757   0.010063   -0.075 0.940030    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 19 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it

Multilevel aged out model

agedoutModel <- glmer(agedout ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc + policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl + mediPpl + tanfPpl*welfarePc + incarRt + deathRt + policePc + (1 | state) + (1 | year_c) + (1 | obsN), offset=log(fcPop),data=dfSample_scaled,family=poisson)

summary(agedoutModel)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: poisson  ( log )
## Formula: agedout ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc +  
##     policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl +  
##     mediPpl + tanfPpl * welfarePc + incarRt + deathRt + policePc +  
##     (1 | state) + (1 | year_c) + (1 | obsN)
##    Data: dfSample_scaled
##  Offset: log(fcPop)
## 
##      AIC      BIC   logLik deviance df.resid 
##   9642.4   9745.3  -4799.2   9598.4      774 
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.53191 -0.08100  0.00824  0.06868  1.16593 
## 
## Random effects:
##  Groups Name        Variance Std.Dev.
##  obsN   (Intercept) 0.14194  0.3767  
##  state  (Intercept) 0.30739  0.5544  
##  year_c (Intercept) 0.03999  0.2000  
## Number of obs: 796, groups:  obsN, 796; state, 50; year_c, 16
## 
## Fixed effects:
##                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)       -3.708859   0.094409 -39.285  < 2e-16 ***
## unempRt           -0.043093   0.045528  -0.947  0.34389    
## singPar           -0.124493   0.074171  -1.678  0.09326 .  
## foodIns           -0.003214   0.025801  -0.125  0.90086    
## chpovRt            0.157094   0.064580   2.433  0.01499 *  
## LessHS            -0.096027   0.071896  -1.336  0.18166    
## gspPc              0.051015   0.060157   0.848  0.39642    
## policy_updated    -0.009419   0.086410  -0.109  0.91320    
## crimeRt            0.062766   0.045502   1.379  0.16777    
## pctBlk             0.030263   0.095750   0.316  0.75195    
## tanf3fam          -0.082325   0.062092  -1.326  0.18489    
## snapPpl            0.063881   0.038824   1.645  0.09989 .  
## mediPpl           -0.002817   0.042226  -0.067  0.94682    
## tanfPpl            0.027445   0.028891   0.950  0.34214    
## welfarePc         -0.092340   0.045323  -2.037  0.04161 *  
## incarRt           -0.109581   0.055460  -1.976  0.04817 *  
## deathRt           -0.074309   0.019765  -3.760  0.00017 ***
## policePc           0.077915   0.043429   1.794  0.07280 .  
## tanfPpl:welfarePc  0.060973   0.025795   2.364  0.01809 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 19 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it

TWFE Models

Check balance

dfSample_scaled %>% is.pbalanced() 
## [1] FALSE

TWFE model: entry

twfe_entryRt <- plm(log(entryRt) ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc + policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl + mediPpl + tanfPpl*welfarePc + incarRt + deathRt + policePc, data=dfSample_scaled, effect="twoway", model="within", index=c("state","year_c"))

# summary(twfe_entryRt)

par(mfrow=c(1,2))
qqnorm(residuals(twfe_entryRt), ylab = 'Residuals')
qqline(residuals(twfe_entryRt)) 
hist(residuals(twfe_entryRt), xlab = 'Residuals')

bptest(twfe_entryRt, studentize = F) 
## 
##  Breusch-Pagan test
## 
## data:  twfe_entryRt
## BP = 117.67, df = 18, p-value < 2.2e-16
pbgtest(twfe_entryRt) 
## 
##  Breusch-Godfrey/Wooldridge test for serial correlation in panel models
## 
## data:  log(entryRt) ~ unempRt + singPar + foodIns + chpovRt + LessHS +  ...
## chisq = 343.55, df = 15, p-value < 2.2e-16
## alternative hypothesis: serial correlation in idiosyncratic errors
coeftest(twfe_entryRt, vcov = vcovHC(twfe_entryRt, method = "arellano", type = "HC0", cluster = "group"))
## 
## t test of coefficients:
## 
##                     Estimate Std. Error t value Pr(>|t|)   
## unempRt           -0.0048323  0.0277689 -0.1740 0.861901   
## singPar           -0.0379966  0.0576229 -0.6594 0.509852   
## foodIns           -0.0069413  0.0137136 -0.5062 0.612899   
## chpovRt            0.0091827  0.0387251  0.2371 0.812628   
## LessHS            -0.0653270  0.0715153 -0.9135 0.361305   
## gspPc             -0.0509728  0.0431756 -1.1806 0.238158   
## policy_updated     0.2205517  0.0873422  2.5251 0.011781 * 
## crimeRt            0.0229072  0.0412958  0.5547 0.579267   
## pctBlk            -0.0845178  0.2731381 -0.3094 0.757083   
## tanf3fam           0.0368083  0.0897076  0.4103 0.681699   
## snapPpl           -0.0695715  0.0248446 -2.8003 0.005244 **
## mediPpl            0.0735174  0.0414290  1.7745 0.076400 . 
## tanfPpl            0.0156208  0.0260254  0.6002 0.548554   
## welfarePc          0.0055500  0.0454819  0.1220 0.902912   
## incarRt            0.0477526  0.0583352  0.8186 0.413294   
## deathRt            0.0259446  0.0118415  2.1910 0.028776 * 
## policePc           0.0245910  0.0380665  0.6460 0.518488   
## tanfPpl:welfarePc  0.0037847  0.0245461  0.1542 0.877507   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

TWFE model: aged out

twfe_agedRt <- plm(agedRt ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc + policy_updated + crimeRt + pctBlk + tanf3fam + snapPpl + mediPpl + tanfPpl*welfarePc + incarRt + deathRt + policePc, data=dfSample_scaled, effect="twoway", model="within", index=c("state","year_c"))

# summary(twfe_agedRt)

par(mfrow=c(1,2))
qqnorm(residuals(twfe_agedRt), ylab = 'Residuals')
qqline(residuals(twfe_agedRt)) 
hist(residuals(twfe_agedRt), xlab = 'Residuals')

bptest(twfe_agedRt, studentize = F) 
## 
##  Breusch-Pagan test
## 
## data:  twfe_agedRt
## BP = 179.94, df = 18, p-value < 2.2e-16
pbgtest(twfe_agedRt) 
## 
##  Breusch-Godfrey/Wooldridge test for serial correlation in panel models
## 
## data:  agedRt ~ unempRt + singPar + foodIns + chpovRt + LessHS + gspPc +  ...
## chisq = 372.94, df = 15, p-value < 2.2e-16
## alternative hypothesis: serial correlation in idiosyncratic errors
coeftest(twfe_agedRt, vcov = vcovHC(twfe_agedRt, method = "arellano", type = "HC0", cluster = "group"))
## 
## t test of coefficients:
## 
##                    Estimate Std. Error t value Pr(>|t|)   
## unempRt           -0.039305   0.243098 -0.1617 0.871601   
## singPar           -0.294525   0.353998 -0.8320 0.405690   
## foodIns            0.032311   0.077900  0.4148 0.678436   
## chpovRt            0.526947   0.177279  2.9724 0.003054 **
## LessHS            -0.473083   0.416189 -1.1367 0.256045   
## gspPc              0.408244   0.388116  1.0519 0.293220   
## policy_updated     0.196969   0.423345  0.4653 0.641882   
## crimeRt            0.160232   0.188329  0.8508 0.395159   
## pctBlk             1.210939   1.687056  0.7178 0.473127   
## tanf3fam          -0.019518   0.232787 -0.0838 0.933202   
## snapPpl            0.356863   0.211416  1.6880 0.091855 . 
## mediPpl            0.073061   0.146890  0.4974 0.619073   
## tanfPpl           -0.037108   0.216578 -0.1713 0.864007   
## welfarePc         -0.286048   0.190328 -1.5029 0.133303   
## incarRt           -0.298342   0.282325 -1.0567 0.290992   
## deathRt           -0.156446   0.084368 -1.8543 0.064104 . 
## policePc           0.060124   0.199692  0.3011 0.763438   
## tanfPpl:welfarePc  0.180619   0.108440  1.6656 0.096229 . 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Glmer diagnostics

R2

r2(enterModel) 
## Warning: mu of 0.0 is too close to zero, estimate of random effect variances may
##   be unreliable.
## # R2 for Mixed Models
## 
##   Conditional R2: 0.033
##      Marginal R2: 0.016

ICC

icc(enterModel) 
## Warning: mu of 0.0 is too close to zero, estimate of random effect variances may
##   be unreliable.
## # Intraclass Correlation Coefficient
## 
##     Adjusted ICC: 0.018
##   Unadjusted ICC: 0.018

Diagnostics

# check for multicollinearity
x <- check_collinearity(enterModel)
plot(x)
## Variable `Component` is not in your data frame :/

# check for singularity 
tt <- getME(enterModel,"theta")
ll <- getME(enterModel,"lower")
min(tt[ll==0])
## [1] 0.00527183
# check for overdispersion
check_overdispersion(enterModel) 
## # Overdispersion test
## 
##        dispersion ratio =  0.023
##   Pearson's Chi-Squared = 17.867
##                 p-value =      1
## No overdispersion detected.
# check residuals
par(mfrow=c(1,2))
plot(residuals(enterModel) ~ fitted(enterModel), main = "residuals v.s. fitted") 
qqnorm(residuals(enterModel))

# random effects
plot(ranef(enterModel))
## $obsN

## 
## $state

## 
## $year_c