library(tidyverse)
math_score<-read.csv("ECLSK_98_99_math.csv")
math_score<-filter(math_score,!( P1DISABL ==1), !( C1R4MSCL ==-1), RACE %in%c(1, 3, 4) ) 
subset_math_hisp<-math_score[c(1, 2, 138:140, 260, 533:537, 800:801, 809, 812:813, 822, 961, 1270:1272, 1276, 1537, 1823, 2000)]
subset_math_hisp$ R1_KAGE  [subset_math_hisp$  R1_KAGE  == -9] <- NA
subset_math_hisp$ P1LEARN  [subset_math_hisp$  P1LEARN == -9] <- NA
subset_math_hisp$ C1R4MSCL [subset_math_hisp$  C1R4MSCL   == -9] <- NA

subset_math_hisp$ P1CONTRO [subset_math_hisp$  P1CONTRO == -9] <- NA
subset_math_hisp$ P1SOCIAL [subset_math_hisp$  P1SOCIAL == -9] <- NA
subset_math_hisp$ P1SADLON [subset_math_hisp$  P1SADLON == -9] <- NA
subset_math_hisp$ P1IMPULS [subset_math_hisp$  P1IMPULS == -9] <- NA

subset_math_hisp$ P1DISABL  [subset_math_hisp$  P1DISABL  == -9] <- NA
subset_math_hisp$  P1CENTER        [subset_math_hisp$  P1CENTER      == -9] <- NA
 
subset_math_hisp$ P1FIRKDG    [subset_math_hisp$  P1FIRKDG    <= -8] <- NA
subset_math_hisp$ P1YYINT     [subset_math_hisp$  P1YYINT    <= -8] <- NA
subset_math_hisp$ P1CHLBOO      [subset_math_hisp$ P1CHLBOO     <= -7] <- NA
subset_math_hisp$  P1DIAGNO       [subset_math_hisp$  P1DIAGNO     <= -8] <- NA
subset_math_hisp<-na.omit(subset_math_hisp)
subset_math_hisp<-subset_math_hisp%>%
  mutate(race =sjmisc::rec(RACE, rec = "1=1; 3=2; 4=2"))%>%
   mutate(learning_difficulty =sjmisc::rec( P1DIAGNO, rec = "-1=2; 1=1; 2=2")) %>% 
mutate(home_lang=sjmisc::rec( C1SCREEN, rec = "1=2; 2=1")) %>% 
  mutate(Home_language_binary=sjmisc::rec( home_lang, rec = "1=1; 2=0")) %>% 
  mutate(c_age=R1_KAGE-mean(R1_KAGE))%>% 
  mutate(Center_binary=sjmisc::rec( P1CENTER, rec = "1=1; 2=0"))
subset_math_hisp$gender<-factor(subset_math_hisp$GENDER, levels = c(1, 2), 
               labels = c("Male","Female"))
subset_math_hisp$race<-factor(subset_math_hisp$race, levels = c (1, 2), 
                  labels = c("White", "Hispanic"))
subset_math_hisp$center<-factor(subset_math_hisp$P1CENTER, levels = c(1, 2), 
               labels = c("Yes","No"))
subset_math_hisp$family_type<-factor(subset_math_hisp$P1HFAMIL, levels = c(1, 2, 3, 4, 5), 
               labels = c("Both parents & sib","Both parents & no sib", "Single parent & sib", " Single parent & no sib", "Other"))

subset_math_hisp$kindergarten<-factor(subset_math_hisp$P1FIRKDG , levels = c(1, 2), 
               labels = c("Yes","No"))
subset_math_hisp$assess_spanish<-factor(subset_math_hisp$C1SPASMT  , levels = c(1, 2), 
               labels = c("Yes","No"))
subset_math_hisp$home_lang<-factor(subset_math_hisp$home_lang  , levels = c(1, 2), 
               labels = c("English","Non-English"))

subset_math_hisp$learning_difficulty<-factor(subset_math_hisp$learning_difficulty  , levels = c(1, 2), 
               labels = c("Yes","No"))
subset_math_hisp$SES<-factor(subset_math_hisp$W1SESQ5  , levels = c(1, 2, 3, 4, 5), 
               labels = c("First quintile", "Second quintile", "Third quintile", "Fourth quintile", "Fifth quintile"))
my_mathdata<-subset_math_hisp[c(5:11, 14:15, 24, 26:37 )]
library(reshape2)

names(my_mathdata)<-c("Child_Age", "Math_score", "Approach_to_Learning", "Self_control", "Social_interaction", "Sad_alone", "Impulsive", "Number_of_sibling", "Total_household_member", "Number_of_book", "Race", "Learning difficulty","Home_language","Home_language_binary", "Child_assessment_age", "Center_binary", "Gender", "Center", "Types_family" , "Kindergarten", "Spanish_assessment ","SES" )
head(my_mathdata)
##   Child_Age Math_score Approach_to_Learning Self_control
## 1     77.20      44.44                 3.00          3.0
## 2     64.10      28.57                 3.67          3.0
## 3     74.53      40.88                 3.50          3.2
## 4     63.60      19.65                 2.67          2.8
## 5     70.63      26.85                 3.00          2.8
## 6     62.63      22.27                 3.33          2.0
##   Social_interaction Sad_alone Impulsive Number_of_sibling
## 1               3.00      1.50       2.0                 2
## 2               4.00      1.50       1.5                 2
## 3               4.00      1.25       2.5                 1
## 4               3.00      1.75       2.0                 1
## 5               3.67      1.67       1.5                 1
## 6               4.00      1.75       2.0                 1
##   Total_household_member Number_of_book  Race Learning difficulty
## 1                      5            100 White                  No
## 2                      5             40 White                  No
## 3                      4             75 White                  No
## 4                      4            100 White                  No
## 5                      4            200 White                  No
## 6                      4            200 White                  No
##   Home_language Home_language_binary Child_assessment_age Center_binary
## 1       English                    1             8.744793             1
## 2       English                    1            -4.355207             1
## 3       English                    1             6.074793             1
## 4       English                    1            -4.855207             1
## 5       English                    1             2.174793             1
## 6       English                    1            -5.825207             1
##   Gender Center       Types_family Kindergarten Spanish_assessment 
## 1 Female    Yes Both parents & sib          Yes                  No
## 2 Female    Yes Both parents & sib          Yes                  No
## 3 Female    Yes Both parents & sib          Yes                  No
## 4   Male    Yes Both parents & sib          Yes                  No
## 5 Female    Yes Both parents & sib          Yes                  No
## 6   Male    Yes Both parents & sib          Yes                  No
##              SES
## 1 Fifth quintile
## 2 Fifth quintile
## 3 Fifth quintile
## 4 Fifth quintile
## 5 Fifth quintile
## 6 Fifth quintile
summary(my_mathdata)
##    Child_Age       Math_score    Approach_to_Learning  Self_control 
##  Min.   :56.90   Min.   :10.60   Min.   :1.170        Min.   :1.00  
##  1st Qu.:65.20   1st Qu.:20.81   1st Qu.:2.830        1st Qu.:2.60  
##  Median :68.27   Median :26.03   Median :3.170        Median :2.80  
##  Mean   :68.46   Mean   :27.50   Mean   :3.148        Mean   :2.86  
##  3rd Qu.:71.53   3rd Qu.:32.26   3rd Qu.:3.500        3rd Qu.:3.20  
##  Max.   :79.00   Max.   :95.44   Max.   :4.000        Max.   :4.00  
##  Social_interaction   Sad_alone       Impulsive     Number_of_sibling
##  Min.   :1.330      Min.   :1.000   Min.   :1.000   Min.   : 0.000   
##  1st Qu.:3.000      1st Qu.:1.250   1st Qu.:1.500   1st Qu.: 1.000   
##  Median :3.330      Median :1.500   Median :2.000   Median : 1.000   
##  Mean   :3.354      Mean   :1.514   Mean   :1.873   Mean   : 1.424   
##  3rd Qu.:3.670      3rd Qu.:1.750   3rd Qu.:2.000   3rd Qu.: 2.000   
##  Max.   :4.000      Max.   :3.750   Max.   :4.000   Max.   :10.000   
##  Total_household_member Number_of_book         Race     
##  Min.   : 2.000         Min.   :  0.00   White   :6804  
##  1st Qu.: 4.000         1st Qu.: 40.00   Hispanic:1958  
##  Median : 4.000         Median : 75.00                  
##  Mean   : 4.477         Mean   : 84.18                  
##  3rd Qu.: 5.000         3rd Qu.:100.00                  
##  Max.   :13.000         Max.   :200.00                  
##  Learning difficulty     Home_language  Home_language_binary
##  Yes:   0            English    :7627   Min.   :0.0000      
##  No :8762            Non-English:1135   1st Qu.:1.0000      
##                                         Median :1.0000      
##                                         Mean   :0.8705      
##                                         3rd Qu.:1.0000      
##                                         Max.   :1.0000      
##  Child_assessment_age Center_binary       Gender     Center    
##  Min.   :-11.5552     Min.   :0.0000   Male  :4306   Yes:6623  
##  1st Qu.: -3.2552     1st Qu.:1.0000   Female:4456   No :2139  
##  Median : -0.1852     Median :1.0000                           
##  Mean   :  0.0000     Mean   :0.7559                           
##  3rd Qu.:  3.0748     3rd Qu.:1.0000                           
##  Max.   : 10.5448     Max.   :1.0000                           
##                   Types_family  Kindergarten Spanish_assessment 
##  Both parents & sib     :6503   Yes:8460     Yes: 621           
##  Both parents & no sib  : 900   No : 302     No :8141           
##  Single parent & sib    : 844                                   
##   Single parent & no sib: 437                                   
##  Other                  :  78                                   
##                                                                 
##               SES      
##  First quintile :1115  
##  Second quintile:1522  
##  Third quintile :1712  
##  Fourth quintile:2027  
##  Fifth quintile :2386  
## 

##Descriptive Analysis of Data

library(dplyr)
library(knitr)
library(DT)
library(xtable)
library(devtools)
library(ggplot2)
library(pastecs)
library(kableExtra)
library(ztable)
T1.1<-sapply(my_mathdata[,1:10], min)
T1.2<-sapply(my_mathdata[,1:10], mean)
T1.3<-sapply(my_mathdata[,1:10], median)
T1.4<-sapply(my_mathdata[,1:10], sd)
T1.5<-sapply(my_mathdata[,1:10], max)
kable(cbind(Min=T1.1, Max=T1.5, Mean=T1.2, Median=T1.3, Sd=T1.4), format = "html", caption = "Table 1: Descriptive Analysis of Continuous Variables", booktabs = T) 
Table 1: Descriptive Analysis of Continuous Variables
Min Max Mean Median Sd
Child_Age 56.90 79.00 68.455207 68.27 4.1941982
Math_score 10.60 95.44 27.501615 26.03 9.4071097
Approach_to_Learning 1.17 4.00 3.148142 3.17 0.4624071
Self_control 1.00 4.00 2.859770 2.80 0.4765388
Social_interaction 1.33 4.00 3.354468 3.33 0.5367221
Sad_alone 1.00 3.75 1.513802 1.50 0.3656078
Impulsive 1.00 4.00 1.873145 2.00 0.6180660
Number_of_sibling 0.00 10.00 1.423648 1.00 1.0795026
Total_household_member 2.00 13.00 4.477060 4.00 1.2545040
Number_of_book 0.00 200.00 84.182949 75.00 60.5478430
T2.1 <- my_mathdata$Gender
cbind(freq=table(T2.1), percentage=prop.table(table(T2.1))*100)
##        freq percentage
## Male   4306   49.14403
## Female 4456   50.85597
T2.2 <- my_mathdata$Race
cbind(freq=table(T2.2), percentage=prop.table(table(T2.2))*100)
##          freq percentage
## White    6804    77.6535
## Hispanic 1958    22.3465
T2.3 <- my_mathdata$Types_family
cbind(freq=table(T2.3), percentage=prop.table(table(T2.3))*100)
##                         freq percentage
## Both parents & sib      6503 74.2182150
## Both parents & no sib    900 10.2716275
## Single parent & sib      844  9.6325040
##  Single parent & no sib  437  4.9874458
## Other                     78  0.8902077
 T2.4 <- my_mathdata$SES
cbind(freq=table(T2.4), percentage=prop.table(table(T2.4))*100)
##                 freq percentage
## First quintile  1115   12.72541
## Second quintile 1522   17.37046
## Third quintile  1712   19.53892
## Fourth quintile 2027   23.13399
## Fifth quintile  2386   27.23123
 T2.5 <- my_mathdata$Home_language
cbind(freq=table(T2.5), percentage=prop.table(table(T2.5))*100)
##             freq percentage
## English     7627   87.04634
## Non-English 1135   12.95366
 T2.6 <- my_mathdata$Center
cbind(freq=table(T2.6), percentage=prop.table(table(T2.6))*100)
##     freq percentage
## Yes 6623   75.58777
## No  2139   24.41223
 T2.7 <- my_mathdata$Kindergarten
cbind(freq=table(T2.7), percentage=prop.table(table(T2.7))*100)
##     freq percentage
## Yes 8460  96.553298
## No   302   3.446702
c1<-table(   my_mathdata$Race, my_mathdata$Gender)
c2<-table(    my_mathdata$Race, my_mathdata$SES)
c3<-table(  my_mathdata$Race, my_mathdata$Home_language)
c4<-table(   my_mathdata$Race, my_mathdata$Types_family)
c5<-table( my_mathdata$Center,  my_mathdata$Race)
c6<-table(my_mathdata$Race, my_mathdata$Kindergarten )
v1=round(prop.table(c1, 1), 2)
v2=round(prop.table(c2, 1), 2)
 v3=round(prop.table(c3, 1), 2)
 v4=round(prop.table(c4, 1), 2)
 v5=round(prop.table(c5, 1), 2)
v6=round(prop.table(c6, 1), 2)
kable(v1, format = "html", caption = "Table 3.1: Percentage of Gender by Race", booktabs = T)  
Table 3.1: Percentage of Gender by Race
Male Female
White 0.49 0.51
Hispanic 0.50 0.50
kable(v2, format = "html", caption = "Table 3.2: Percentage of SES by Race", booktabs = T)  
Table 3.2: Percentage of SES by Race
First quintile Second quintile Third quintile Fourth quintile Fifth quintile
White 0.06 0.16 0.20 0.26 0.32
Hispanic 0.37 0.22 0.17 0.15 0.09
kable(v3, format = "html", caption = "Table 3.3: Percentage of Home Language by Race", booktabs = T)  
Table 3.3: Percentage of Home Language by Race
English Non-English
White 0.98 0.02
Hispanic 0.47 0.53
kable(v4, format = "html", caption = "Table 3.4: Percentage of Family Types by Race", booktabs = T)  
Table 3.4: Percentage of Family Types by Race
Both parents & sib Both parents & no sib Single parent & sib Single parent & no sib Other
White 0.76 0.1 0.08 0.04 0.01
Hispanic 0.68 0.1 0.14 0.07 0.01
kable(v5, format = "html", caption = "Table 3.5: Percentage of Center-based Care by Race", booktabs = T)  
Table 3.5: Percentage of Center-based Care by Race
White Hispanic
Yes 0.82 0.18
No 0.64 0.36
kable(v6, format = "html", caption = "Table 3.6: Percentage of First-time at Kindergarten by Race", booktabs = T)
Table 3.6: Percentage of First-time at Kindergarten by Race
Yes No
White 0.97 0.03
Hispanic 0.95 0.05
kable(v2, format = "html",caption = "Table 3.2: Percentage of Center-based care by Race", booktabs = T)
Table 3.2: Percentage of Center-based care by Race
First quintile Second quintile Third quintile Fourth quintile Fifth quintile
White 0.06 0.16 0.20 0.26 0.32
Hispanic 0.37 0.22 0.17 0.15 0.09
  kable(v3, format = "html",caption = "Table 3.3: Percentage of Gender by Race", booktabs = T)
Table 3.3: Percentage of Gender by Race
English Non-English
White 0.98 0.02
Hispanic 0.47 0.53
kable(v4, format = "html",caption = "Table 3.4: Percentage of Home language by Race", booktabs = T)
Table 3.4: Percentage of Home language by Race
Both parents & sib Both parents & no sib Single parent & sib Single parent & no sib Other
White 0.76 0.1 0.08 0.04 0.01
Hispanic 0.68 0.1 0.14 0.07 0.01
  kable(v5, format = "html",caption = "Table 3.5: Percentage of Family types by Race", booktabs = T)
Table 3.5: Percentage of Family types by Race
White Hispanic
Yes 0.82 0.18
No 0.64 0.36
kable(v6, format = "html",caption = "Table 3.6: Percentage of First time in Kindergarten by Race", booktabs = T)
Table 3.6: Percentage of First time in Kindergarten by Race
Yes No
White 0.97 0.03
Hispanic 0.95 0.05
 library(pander)
des2 <- my_mathdata %>% 
  group_by(Race, Home_language, Center) %>% 
  summarize(N = length(Math_score),  
            Mean = mean(Math_score),
            SD = sd(Math_score),
            SE = SD/sqrt(N)) 
pander(des2, digit=2)
Race Home_language Center N Mean SD SE
White English Yes 5349 30 9.5 0.13
White English No 1348 26 8.5 0.23
White Non-English Yes 77 29 8.6 0.98
White Non-English No 30 26 5.8 1.1
Hispanic English Yes 668 26 8.3 0.32
Hispanic English No 262 23 6.8 0.42
Hispanic Non-English Yes 529 21 6.2 0.27
Hispanic Non-English No 499 19 5.8 0.26

Linear Regression Model for Math Skills

 mym1<-lm(Math_score~Child_assessment_age+Race+Gender+Approach_to_Learning+Self_control+Social_interaction+Sad_alone+Impulsive+Kindergarten+Center+Number_of_sibling+Total_household_member+Types_family+SES+Home_language+Number_of_book  , data = my_mathdata)

mym2<-lm(Math_score~Child_assessment_age+Race*Center+Home_language*Race+Gender+Approach_to_Learning+Social_interaction+Self_control+Sad_alone+Impulsive+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book, data = my_mathdata)

mym3<-lm(Math_score~Child_assessment_age+Race*Center*Home_language+Gender+Approach_to_Learning+Social_interaction+Self_control+Sad_alone+Impulsive+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book, data = my_mathdata)
 AIC(mym1, mym2, mym3)
##      df      AIC
## mym1 24 60893.60
## mym2 26 60891.55
## mym3 28 60894.97

Logistic regression model: Center-based care and race as predictor of home language

mylan1<-glm(Home_language_binary~Race+Center+Gender+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book,  data = my_mathdata)
mylan2<-glm(Home_language_binary~Race*Center+Gender+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book, data = my_mathdata)
AIC(mylan1, mylan2)
##        df      AIC
## mylan1 17 393.3411
## mylan2 18 251.1772

Logistic regression model: Race as a predictor of Center-based care

myc1<-glm(Center_binary~Race+Gender+Number_of_sibling+Total_household_member+Types_family+SES,  data = my_mathdata)
 
myc2<-glm(Center_binary~Race*SES+Gender+Number_of_sibling+Total_household_member+Types_family,  data = my_mathdata)
 AIC(myc1, myc2)
##      df      AIC
## myc1 14 9236.458
## myc2 18 9232.393

##Table-4: Best-fitted Regresstion models for Math skills, home language, and Center-based care

library(broom)
library(huxtable)
huxreg('Mathmatics skills'=mym2, 'Home language'=mylan2, 'Center-based care'= myc2,  number_format = 2, note = 'White children were reference group, {stars}', error_pos = 'same') 
Mathmatics skills Home language Center-based care
(Intercept) 20.58 *** (1.20) 0.79 *** (0.02)     0.77 *** (0.03)
Child_assessment_age 0.61 *** (0.02)              
RaceHispanic -1.57 *** (0.30) -0.36 *** (0.01)     -0.16 *** (0.03)
CenterNo -1.59 *** (0.24) 0.01 (0.01)         
Home_languageNon-English -0.36 (0.76)              
GenderFemale -0.41 * (0.17) -0.00 (0.01)     0.00 (0.01)
Approach_to_Learning 2.39 *** (0.20)              
Social_interaction -0.65 *** (0.18)              
Self_control 0.46 * (0.20)              
Sad_alone -0.16 (0.25)              
Impulsive -0.77 *** (0.15)              
KindergartenNo -0.97 * (0.47) -0.02 (0.01)         
Number_of_sibling -0.08 (0.16) 0.02 *** (0.00)     -0.03 *** (0.01)
Total_household_member -0.41 ** (0.13) -0.02 *** (0.00)     -0.02 ** (0.01)
Types_familyBoth parents & no sib -0.03 (0.32) 0.02 (0.01)     -0.00 (0.02)
Types_familySingle parent & sib -1.17 *** (0.31) 0.05 *** (0.01)     0.04 ** (0.02)
Types_family Single parent & no sib -0.89 * (0.42) 0.04 ** (0.01)     0.06 ** (0.02)
Types_familyOther -1.03 (0.90) 0.10 *** (0.03)     0.04 (0.05)
SESSecond quintile 1.56 *** (0.33) 0.18 *** (0.01)     0.02 (0.02)
SESThird quintile 3.17 *** (0.34) 0.20 *** (0.01)     0.09 *** (0.02)
SESFourth quintile 4.52 *** (0.34) 0.19 *** (0.01)     0.16 *** (0.02)
SESFifth quintile 7.81 *** (0.35) 0.18 *** (0.01)     0.23 *** (0.02)
Number_of_book 0.01 *** (0.00) 0.00 *** (4.92e-05)     
RaceHispanic:CenterNo 0.91 * (0.44) -0.16 *** (0.01)         
RaceHispanic:Home_languageNon-English -1.27 (0.85)              
RaceHispanic:SESSecond quintile               0.11 ** (0.03)
RaceHispanic:SESThird quintile               0.07 (0.04)
RaceHispanic:SESFourth quintile               0.08 * (0.04)
RaceHispanic:SESFifth quintile               0.12 ** (0.04)
N 8762     8762         8762    
R 2 0.31               
logLik -30419.77  -107.59      -4598.20 
AIC 60891.55  251.18      9232.39 
White children were reference group, *** p < 0.001; ** p < 0.01; * p < 0.05

##Best fitted models estimated by using Zelig

library(ZeligChoice)
library(Zelig)
 z.out.math <- zelig(Math_score~Child_assessment_age+Race*Center+Home_language*Race+Gender+Approach_to_Learning+Social_interaction+Self_control+Sad_alone+Impulsive+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book, model = "ls",  data = my_mathdata, cite = FALSE)
 summary(z.out.math)
## Model: 
## 
## Call:
## z5$zelig(formula = Math_score ~ Child_assessment_age + Race * 
##     Center + Home_language * Race + Gender + Approach_to_Learning + 
##     Social_interaction + Self_control + Sad_alone + Impulsive + 
##     Kindergarten + Number_of_sibling + Total_household_member + 
##     Types_family + SES + Number_of_book, data = my_mathdata)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -20.946  -5.157  -0.981   3.974  57.169 
## 
## Coefficients:
##                                        Estimate Std. Error t value
## (Intercept)                           20.579781   1.199557  17.156
## Child_assessment_age                   0.609541   0.020638  29.534
## RaceHispanic                          -1.565943   0.304408  -5.144
## CenterNo                              -1.590022   0.241401  -6.587
## Home_languageNon-English              -0.357878   0.763822  -0.469
## GenderFemale                          -0.414212   0.169712  -2.441
## Approach_to_Learning                   2.386975   0.204373  11.680
## Social_interaction                    -0.650842   0.179123  -3.633
## Self_control                           0.462243   0.201140   2.298
## Sad_alone                             -0.162220   0.247378  -0.656
## Impulsive                             -0.774385   0.152605  -5.074
## KindergartenNo                        -0.966217   0.469149  -2.060
## Number_of_sibling                     -0.080765   0.156528  -0.516
## Total_household_member                -0.411521   0.127971  -3.216
## Types_familyBoth parents & no sib     -0.031293   0.322241  -0.097
## Types_familySingle parent & sib       -1.170353   0.305181  -3.835
## Types_family Single parent & no sib   -0.886677   0.423776  -2.092
## Types_familyOther                     -1.027808   0.898209  -1.144
## SESSecond quintile                     1.562552   0.331274   4.717
## SESThird quintile                      3.168882   0.337772   9.382
## SESFourth quintile                     4.520057   0.338938  13.336
## SESFifth quintile                      7.811676   0.346588  22.539
## Number_of_book                         0.013381   0.001588   8.424
## RaceHispanic:CenterNo                  0.909675   0.440747   2.064
## RaceHispanic:Home_languageNon-English -1.270735   0.849252  -1.496
##                                       Pr(>|t|)
## (Intercept)                            < 2e-16
## Child_assessment_age                   < 2e-16
## RaceHispanic                          2.74e-07
## CenterNo                              4.76e-11
## Home_languageNon-English              0.639413
## GenderFemale                          0.014680
## Approach_to_Learning                   < 2e-16
## Social_interaction                    0.000281
## Self_control                          0.021579
## Sad_alone                             0.511997
## Impulsive                             3.97e-07
## KindergartenNo                        0.039475
## Number_of_sibling                     0.605881
## Total_household_member                0.001306
## Types_familyBoth parents & no sib     0.922641
## Types_familySingle parent & sib       0.000126
## Types_family Single parent & no sib   0.036438
## Types_familyOther                     0.252537
## SESSecond quintile                    2.43e-06
## SESThird quintile                      < 2e-16
## SESFourth quintile                     < 2e-16
## SESFifth quintile                      < 2e-16
## Number_of_book                         < 2e-16
## RaceHispanic:CenterNo                 0.039053
## RaceHispanic:Home_languageNon-English 0.134612
## 
## Residual standard error: 7.801 on 8737 degrees of freedom
## Multiple R-squared:  0.3142, Adjusted R-squared:  0.3123 
## F-statistic: 166.8 on 24 and 8737 DF,  p-value: < 2.2e-16
## 
## Next step: Use 'setx' method
 z.out.lan<- zelig(Home_language_binary~Race*Center+Gender+Kindergarten+Number_of_sibling+Total_household_member+Types_family+SES+Number_of_book, model = "logit",  data = my_mathdata, cite = FALSE)
summary(z.out.lan)
## Model: 
## 
## Call:
## z5$zelig(formula = Home_language_binary ~ Race * Center + Gender + 
##     Kindergarten + Number_of_sibling + Total_household_member + 
##     Types_family + SES + Number_of_book, data = my_mathdata)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -3.8137   0.0586   0.1421   0.2221   2.2255  
## 
## Coefficients:
##                                      Estimate Std. Error z value Pr(>|z|)
## (Intercept)                          2.012424   0.256016   7.861 3.82e-15
## RaceHispanic                        -3.355617   0.137627 -24.382  < 2e-16
## CenterNo                            -0.191977   0.222392  -0.863  0.38801
## GenderFemale                        -0.074282   0.091913  -0.808  0.41899
## KindergartenNo                      -0.311231   0.220436  -1.412  0.15798
## Number_of_sibling                    0.201036   0.068596   2.931  0.00338
## Total_household_member              -0.099815   0.050331  -1.983  0.04735
## Types_familyBoth parents & no sib    0.324000   0.177790   1.822  0.06840
## Types_familySingle parent & sib      0.700547   0.145811   4.804 1.55e-06
## Types_family Single parent & no sib  0.569943   0.207428   2.748  0.00600
## Types_familyOther                    1.150867   0.448460   2.566  0.01028
## SESSecond quintile                   1.032055   0.129463   7.972 1.56e-15
## SESThird quintile                    1.302557   0.145914   8.927  < 2e-16
## SESFourth quintile                   1.050792   0.152374   6.896 5.34e-12
## SESFifth quintile                    0.926266   0.177212   5.227 1.72e-07
## Number_of_book                       0.018497   0.001492  12.393  < 2e-16
## RaceHispanic:CenterNo               -0.274122   0.245337  -1.117  0.26386
## 
## (Dispersion parameter for binomial family taken to be 1)
## 
##     Null deviance: 6755.6  on 8761  degrees of freedom
## Residual deviance: 3206.6  on 8745  degrees of freedom
## AIC: 3240.6
## 
## Number of Fisher Scoring iterations: 7
## 
## Next step: Use 'setx' method
 z.out.center <- zelig(Center_binary~Race*SES+Gender+Number_of_sibling+Total_household_member+Types_family, model = "ls",  data = my_mathdata, cite = FALSE)
summary(z.out.center)
## Model: 
## 
## Call:
## z5$zelig(formula = Center_binary ~ Race * SES + Gender + Number_of_sibling + 
##     Total_household_member + Types_family, data = my_mathdata)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.02989  0.00837  0.15283  0.25274  0.90231 
## 
## Coefficients:
##                                      Estimate Std. Error t value Pr(>|t|)
## (Intercept)                          0.770807   0.031685  24.327  < 2e-16
## RaceHispanic                        -0.162518   0.025827  -6.292 3.28e-10
## SESSecond quintile                   0.017171   0.024128   0.712 0.476693
## SESThird quintile                    0.092407   0.023549   3.924 8.77e-05
## SESFourth quintile                   0.159819   0.023079   6.925 4.68e-12
## SESFifth quintile                    0.231921   0.022720  10.208  < 2e-16
## GenderFemale                         0.002062   0.008755   0.236 0.813792
## Number_of_sibling                   -0.027524   0.008183  -3.363 0.000773
## Total_household_member              -0.018264   0.006704  -2.724 0.006454
## Types_familyBoth parents & no sib   -0.003179   0.016836  -0.189 0.850227
## Types_familySingle parent & sib      0.042584   0.015932   2.673 0.007536
## Types_family Single parent & no sib  0.061631   0.022159   2.781 0.005425
## Types_familyOther                    0.041734   0.047117   0.886 0.375768
## RaceHispanic:SESSecond quintile      0.105982   0.034630   3.060 0.002217
## RaceHispanic:SESThird quintile       0.067929   0.035755   1.900 0.057483
## RaceHispanic:SESFourth quintile      0.079729   0.036817   2.166 0.030374
## RaceHispanic:SESFifth quintile       0.116561   0.040895   2.850 0.004379
## 
## Residual standard error: 0.4094 on 8745 degrees of freedom
## Multiple R-squared:  0.09366,    Adjusted R-squared:  0.092 
## F-statistic: 56.48 on 16 and 8745 DF,  p-value: < 2.2e-16
## 
## Next step: Use 'setx' method

##Table-5: White-Hispanic Difference in Math skills, home language, and center-based care

###Math skills

x.math_w <- setx(z.out.math, Race="White")
x.math_his <- setx(z.out.math, Race="Hispanic")
s.w.his <- sim(z.out.math, x = x.math_w, x1=x.math_his)
summary(s.w.his)
## 
##  sim x :
##  -----
## ev
##      mean        sd      50%     2.5%    97.5%
## 1 32.1006 0.1957422 32.10272 31.73689 32.48205
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 31.91969 7.711393 32.13008 17.51948 47.25856
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 30.53356 0.3508173 30.51894 29.86826 31.22913
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 30.78719 7.802699 31.01172 14.58959 45.96568
## fd
##        mean       sd       50%      2.5%      97.5%
## 1 -1.567045 0.308383 -1.576511 -2.135768 -0.9368095
plot(s.w.his)

###Home language

x.l_w <- setx(z.out.lan, Race="White")
x.l_his <- setx(z.out.lan, Race="Hispanic")
s.l.w.his <- sim(z.out.lan, x = x.l_w  , x1=x.l_his)
summary(s.l.w.his)
## 
##  sim x :
##  -----
## ev
##           mean          sd       50%      2.5%     97.5%
## [1,] 0.9858749 0.002306249 0.9860427 0.9810921 0.9899962
## pv
##          0     1
## [1,] 0.011 0.989
## 
##  sim x1 :
##  -----
## ev
##           mean         sd      50%      2.5%     97.5%
## [1,] 0.7108612 0.03080715 0.711925 0.6499192 0.7679808
## pv
##          0     1
## [1,] 0.262 0.738
## fd
##            mean         sd        50%       2.5%      97.5%
## [1,] -0.2750137 0.02946264 -0.2735908 -0.3333681 -0.2206657
plot(s.l.w.his)

###Center-based care

x.c.w <- setx(z.out.center, Race="White")
x.c.his <- setx(z.out.center, Race="Hispanic")
s.c.w.his <- sim(z.out.center, x = x.c.w  , x1=x.c.his)
summary(s.c.w.his)
## 
##  sim x :
##  -----
## ev
##        mean         sd       50%      2.5%     97.5%
## 1 0.8832465 0.01017769 0.8833186 0.8646198 0.9032662
## pv
##           mean        sd       50%      2.5%   97.5%
## [1,] 0.9002213 0.3931954 0.9123816 0.1426104 1.66667
## 
##  sim x1 :
##  -----
## ev
##       mean         sd       50%      2.5%     97.5%
## 1 0.836611 0.03120618 0.8369688 0.7743973 0.8976316
## pv
##           mean        sd       50%       2.5%    97.5%
## [1,] 0.8335882 0.4026554 0.8345641 0.05607799 1.680856
## fd
##          mean        sd         50%       2.5%      97.5%
## 1 -0.04663552 0.0319186 -0.04627316 -0.1085466 0.01300679

##Center-based care as a predictor of home language

x.l_his.cy <- setx(z.out.lan, Race="Hispanic", Center="Yes")
x.l_his.cn <- setx(z.out.lan, Race="Hispanic", Center="No")
s.l.his.cyn <- sim(z.out.lan, x = x.l_his.cy  , x1=x.l_his.cn)
summary(s.l.his.cyn)
## 
##  sim x :
##  -----
## ev
##           mean         sd       50%     2.5%     97.5%
## [1,] 0.7120602 0.03238202 0.7134157 0.644844 0.7713082
## pv
##          0     1
## [1,] 0.262 0.738
## 
##  sim x1 :
##  -----
## ev
##           mean         sd       50%      2.5%    97.5%
## [1,] 0.6081503 0.04331983 0.6080602 0.5192793 0.690639
## pv
##         0    1
## [1,] 0.38 0.62
## fd
##            mean         sd        50%     2.5%       97.5%
## [1,] -0.1039098 0.02616043 -0.1041059 -0.15292 -0.05185476
plot(s.l.his.cyn)

x.l_w.cy <- setx(z.out.lan, Race="White", Center="Yes")
x.l_w.cn <- setx(z.out.lan, Race="White", Center="No")
s.l.w.cyn <- sim(z.out.lan, x = x.l_w.cy  , x1=x.l_w.cn)
summary(s.l.w.cyn)
## 
##  sim x :
##  -----
## ev
##           mean          sd       50%      2.5%     97.5%
## [1,] 0.9859132 0.002318563 0.9860919 0.9807919 0.9899759
## pv
##          0     1
## [1,] 0.017 0.983
## 
##  sim x1 :
##  -----
## ev
##           mean          sd       50%      2.5%     97.5%
## [1,] 0.9829438 0.003902609 0.9833417 0.9742012 0.9895962
## pv
##          0     1
## [1,] 0.014 0.986
## fd
##              mean          sd          50%        2.5%       97.5%
## [1,] -0.002969379 0.003626362 -0.002667761 -0.01128016 0.003042756
plot(s.l.w.cyn)

x.l_w.cy <- setx(z.out.lan, Race="White", Center="Yes")
x.l_his.cn <- setx(z.out.lan, Race="Hispanic", Center="No")
s.l.w.his.cyn <- sim(z.out.lan, x = x.l_w.cy  , x1=x.l_his.cn)
summary(s.l.w.his.cyn)
## 
##  sim x :
##  -----
## ev
##           mean          sd       50%      2.5%     97.5%
## [1,] 0.9859195 0.002276966 0.9862105 0.9810538 0.9897421
## pv
##          0     1
## [1,] 0.025 0.975
## 
##  sim x1 :
##  -----
## ev
##           mean         sd       50%      2.5%     97.5%
## [1,] 0.6061789 0.04093127 0.6058145 0.5281883 0.6825027
## pv
##          0     1
## [1,] 0.417 0.583
## fd
##            mean         sd        50%       2.5%      97.5%
## [1,] -0.3797407 0.03967391 -0.3807568 -0.4576849 -0.3054714
x.l_w.cy <- setx(z.out.lan, Race="White", Center="Yes")
x.l_his.cy <- setx(z.out.lan, Race="Hispanic", Center="Yes")
s.l.w.his.cyy <- sim(z.out.lan, x = x.l_w.cy  , x1=x.l_his.cy)
summary(s.l.w.his.cyy)
## 
##  sim x :
##  -----
## ev
##           mean          sd       50%      2.5%     97.5%
## [1,] 0.9858908 0.002270797 0.9860832 0.9811529 0.9897006
## pv
##          0     1
## [1,] 0.013 0.987
## 
##  sim x1 :
##  -----
## ev
##           mean         sd      50%      2.5%     97.5%
## [1,] 0.7116791 0.03156291 0.712244 0.6457582 0.7739639
## pv
##          0     1
## [1,] 0.266 0.734
## fd
##            mean         sd        50%       2.5%      97.5%
## [1,] -0.2742118 0.03015369 -0.2738557 -0.3376053 -0.2150196

##Effect of Home language on White-Hispanic Gap of Math score

x.his.ma.le <- setx(z.out.math, Race="Hispanic", Home_language="English")
x.his.ma.lne <- setx(z.out.math, Race="Hispanic", Home_language="Non-English")
s.his.ma.le.lne <- sim(z.out.math, x = x.his.ma.le, x.his.ma.lne)
summary(s.his.ma.le.lne  )
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 30.54537 0.3327017 30.54918 29.88369 31.18767
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 30.36505 7.741376 29.87659 15.33498 45.08538
## 
##  sim x1 :
##  -----
## ev
##       mean        sd     50%     2.5%   97.5%
## 1 28.92916 0.3888702 28.9214 28.18625 29.6525
## pv
##          mean      sd      50%     2.5%    97.5%
## [1,] 29.38963 7.89886 29.30863 14.31814 45.19803
## fd
##        mean        sd       50%      2.5%      97.5%
## 1 -1.616211 0.3935906 -1.625579 -2.363111 -0.8338916
x.w.ma.le <- setx(z.out.math, Race="White", Home_language="English")
x.his.ma.lne <- setx(z.out.math, Race="Hispanic", Home_language="Non-English")
s.w.his.ma.le.lne <- sim(z.out.math, x = x.w.ma.le , x.his.ma.lne)
summary(s.w.his.ma.le.lne )
## 
##  sim x :
##  -----
## ev
##       mean       sd      50%    2.5%    97.5%
## 1 32.10592 0.194666 32.10797 31.7061 32.49096
## pv
##         mean       sd      50%     2.5%    97.5%
## [1,] 32.0925 7.888016 31.97545 16.13821 47.27745
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 28.92268 0.3890252 28.92469 28.18245 29.70115
## pv
##          mean      sd      50%     2.5%    97.5%
## [1,] 28.96399 7.71642 29.10733 13.55458 43.82159
## fd
##        mean        sd       50%      2.5%     97.5%
## 1 -3.183243 0.3694282 -3.186903 -3.891855 -2.504496
x.w.ma.le <- setx(z.out.math, Race="White", Home_language="English")
x.his.ma.le <- setx(z.out.math, Race="Hispanic", Home_language="English")
s.w.his.ma.le.le <- sim(z.out.math, x = x.w.ma.le, x.his.ma.le)
summary(s.w.his.ma.le.le  )
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%    2.5%    97.5%
## 1 32.09518 0.1991704 32.09438 31.7097 32.48545
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 31.90703 7.673923 31.89444 17.02879 46.91994
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 30.52838 0.3459793 30.51018 29.87153 31.19354
## pv
##          mean       sd     50%     2.5%    97.5%
## [1,] 30.20586 7.810606 30.1323 15.35409 45.51627
## fd
##        mean        sd       50%      2.5%      97.5%
## 1 -1.566806 0.3028893 -1.559413 -2.173274 -0.9933738

##Effect of Center on White-Hispanic Gap of Math score

x.his.ma.cy <- setx(z.out.math, Race="Hispanic", Center="Yes")
x.his.ma.cn <- setx(z.out.math, Race="Hispanic", Center="No")
s.his.ma.c <- sim(z.out.math, x = x.his.ma.cy, x1=x.his.ma.cn)
summary(s.his.ma.c )
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%   97.5%
## 1 30.55368 0.3337743 30.54288 29.90156 31.1899
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 30.68524 7.647597 30.86213 15.49687 44.85698
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 29.86597 0.4403972 29.86526 28.99291 30.75265
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 29.80594 7.803051 29.86831 13.25428 44.93023
## fd
##         mean       sd        50%      2.5%      97.5%
## 1 -0.6877054 0.384792 -0.6769337 -1.453861 0.03342578
x.w.ma.cy <- setx(z.out.math, Race="White", Center="Yes")
x.his.ma.cn <- setx(z.out.math, Race="Hispanic", Center="No")
s.w.his.ma.c <- sim(z.out.math, x = x.w.ma.cy, x1=x.his.ma.cn)
summary(s.w.his.ma.c )
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 32.10105 0.1980098 32.10623 31.70056 32.45915
## pv
##          mean      sd      50%     2.5%    97.5%
## [1,] 32.17057 7.79026 32.40657 17.00888 46.67234
## 
##  sim x1 :
##  -----
## ev
##       mean        sd     50%    2.5%    97.5%
## 1 29.85266 0.4349433 29.8821 29.0071 30.69187
## pv
##          mean       sd     50%     2.5%    97.5%
## [1,] 29.68881 7.600956 29.4041 14.74816 44.77908
## fd
##        mean        sd      50%      2.5%    97.5%
## 1 -2.248393 0.4020441 -2.24582 -3.016757 -1.47203
x.w.ma.cy <- setx(z.out.math, Race="White", Center="Yes")
x.his.ma.cy <- setx(z.out.math, Race="Hispanic", Center="Yes")
s.w.his.ma.cy <- sim(z.out.math, x = x.w.ma.cy, x1=x.his.ma.cy)
summary(s.w.his.ma.cy )
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 32.10581 0.2000318 32.10892 31.68511 32.47204
## pv
##         mean       sd      50%    2.5%    97.5%
## [1,] 31.6972 7.570976 31.92307 17.2055 46.36756
## 
##  sim x1 :
##  -----
## ev
##       mean        sd    50%    2.5%    97.5%
## 1 30.55552 0.3297788 30.554 29.9239 31.18123
## pv
##         mean       sd      50%     2.5%    97.5%
## [1,] 30.7262 7.773733 30.82127 16.15298 45.78373
## fd
##        mean        sd       50%      2.5%      97.5%
## 1 -1.550289 0.2962703 -1.538372 -2.139303 -0.9881587
x.w.ma.cn <- setx(z.out.math, Race="White", Center="No")
x.his.ma.cy <- setx(z.out.math, Race="Hispanic", Center="Yes")
s.w.his.ma.cny <- sim(z.out.math, x = x.w.ma.cn, x1=x.his.ma.cy)
summary(s.w.his.ma.cny )
## 
##  sim x :
##  -----
## ev
##       mean       sd      50%     2.5%    97.5%
## 1 30.51049 0.284965 30.50816 29.95095 31.09067
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 30.58303 7.778024 30.53294 14.89264 45.08588
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 30.53832 0.3458717 30.54363 29.85929 31.20401
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 30.50429 7.641836 30.48463 16.63039 46.12865
## fd
##         mean        sd        50%      2.5%     97.5%
## 1 0.02783073 0.3612707 0.02328402 -0.640659 0.7652891

##Effect of home language on the association of Center-based care and math skills

x.math1 <- setx(z.out.math, Race="Hispanic", Center="Yes", Home_language="English")
x.math2<- setx(z.out.math, Race="Hispanic", Center="Yes", Home_language="Non-English")
s.his2 <- sim(z.out.math, x = x.math1, x1=x.math2)
summary(s.his2)
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 30.51374 0.3455776 30.51575 29.85564 31.19588
## pv
##          mean      sd      50%     2.5%    97.5%
## [1,] 30.49554 7.69326 30.42948 15.20718 44.64617
## 
##  sim x1 :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 28.91677 0.3922084 28.90938 28.20484 29.72466
## pv
##          mean       sd      50%     2.5%   97.5%
## [1,] 28.94195 7.960025 29.16835 13.48229 44.4704
## fd
##        mean        sd       50%      2.5%      97.5%
## 1 -1.596966 0.3882095 -1.612538 -2.351803 -0.8360668
x.math11 <- setx(z.out.math, Race="White", Center="Yes", Home_language="English")
x.math22<- setx(z.out.math, Race="White", Center="Yes", Home_language="Non-English")
s.w2 <- sim(z.out.math, x = x.math11, x1=x.math22)
summary(s.w2)
## 
##  sim x :
##  -----
## ev
##       mean        sd      50%     2.5%    97.5%
## 1 32.09214 0.2034766 32.09629 31.69948 32.47487
## pv
##          mean      sd     50%     2.5%    97.5%
## [1,] 32.07852 7.65389 32.0739 17.04747 46.92753
## 
##  sim x1 :
##  -----
## ev
##       mean       sd      50%     2.5%    97.5%
## 1 31.72826 0.752917 31.73112 30.29667 33.15327
## pv
##          mean       sd      50%     2.5%    97.5%
## [1,] 32.38714 7.733448 32.62307 17.68402 47.59528
## fd
##         mean        sd        50%      2.5%    97.5%
## 1 -0.3638834 0.7576926 -0.3585656 -1.824768 1.133592