HW 2 EHA

Author

Brandon Flores

Bandon Flores Event History Analysis

Observing Educational Differences Between Hispanics and Non Hispanic Whites: College Educational Outcomes

  1. The event variable that I am using the whether the respondent earns a bachelors degree.

  2. The duration/time variable are those cohorts for the years 2004, 2010, and 2019 regarding the age that they earn they’re bachelors degree.

  3. The censoring indicator is any respondent who has already earned they’re bachelors degree.

  4. The two groups that are being compared are Hispanics and Non Hispanic Whites.

  5. Survival functions show below.

    When the t-tests for the survival functions below were conducted the first survival function was not statistically significant. The other two models showing years 2010 and 2019 showing a statistically significant difference between Hispanics and Non Hispanic whites regarding the timing of receiving a bachelors degree. For the statistically significant models it showed that those who were Hispanic tended to not earn their Bachelors Degree’s before Non Hispanic Whites.

  6. When observing the Kaplan-Meier survival analysis you can see in the first plot for the year 2004; Hispanics had a slight advantage over Non Hispanic Whites earning them at slightly higher proportions when aged between 20-22 years.

When observing the cohort for the year 2010; the differences begin to widen with Non Hispanic Whites earning they’re bachelors degree at much higher proportions than Hispanics. This is between the ages of 18 - 35. When they become almost equal would be the late 20’s and early 30’s it gets close again.

When observing the cohort for the year 2019; the educational differences widens even more with Non Hispanic Whites tending to earn their Bachelor Degrees earlier and at higher proportions than Hispanics. From this model it can show, outside for those first early years from the 2004 wave, the educational differences never truly were close to each other but rather widening the whole duration. With only a closeness happening with the age of 40 but a difference between the two still exists.

  1. a. Kaplan-Meier survival analysis below.
library(car)
Loading required package: carData
library(haven)
library(survival)
library(ggplot2)
library(tidyverse)
── Attaching packages
───────────────────────────────────────
tidyverse 1.3.2 ──
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.2      ✔ forcats 0.5.2 
✔ purrr   0.3.4      
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
✖ dplyr::recode() masks car::recode()
✖ purrr::some()   masks car::some()
library(survey)
Loading required package: grid
Loading required package: Matrix

Attaching package: 'Matrix'

The following objects are masked from 'package:tidyr':

    expand, pack, unpack


Attaching package: 'survey'

The following object is masked from 'package:graphics':

    dotchart
library(ggsurvfit)
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
dat97<-read_csv("C:\\Users\\BTP\\Desktop\\97cohortNLSYRnum.csv")
Rows: 8984 Columns: 13
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (13): ID, SEX, BDATEM, BDATEY, SAMPLETYPE, ETHNICITY, HDEGREE04, HDEGREE...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dat97$Bachelors04 <-Recode(dat97$HDEGREE04, recodes = "0:3 = 0; 4:7 = 1; else=NA", as.factor=T)

## Bachelors degree or higher = 1 & all lesser educations are labled 0
#tabyl(Bachelors04)
dat97$Bachelors10 <-Recode(dat97$HDEGREE2010, recodes = "0:3 = 0; 4:7 = 1; else=NA", as.factor=T)

## Bachelors degree or higher = 1 & all lesser educations are labled 0

dat97 %>%
  tabyl(Bachelors10) ## Bachelors degree or higher in 2010
 Bachelors10    n   percent valid_percent
           0 5570 0.6199911     0.7503705
           1 1853 0.2062556     0.2496295
        <NA> 1561 0.1737533            NA
dat97$Bachelors19 <-Recode(dat97$HDEGREE2019, recodes = "0:3 = 0; 4:7 = 1; else=NA", as.factor=T)

## Bachelors degree or higher = 1 & all lesser educations are labled 0

dat97 %>%
  tabyl(Bachelors19) ## Bachelors degree or higher in 2019
 Bachelors19    n   percent valid_percent
           0 4772 0.5311665     0.6893961
           1 2150 0.2393143     0.3106039
        <NA> 2062 0.2295191            NA
dat97$Hispanic<-Recode(dat97$ETHNICITY, recodes = "2 = 0; 4 = 1; else=NA", as.factor=T)

## Hispanics are coded as 0 & Non Hipanic whites are coded as 1, all other ethnicities are excluded

dat97$his1<-as.factor(ifelse(dat97$Hispanic==1, "Hispanic", "Non Hispanic"))


dat97 %>% 
  tabyl(his1) ## Hispanics  and Non Hispanic whites coded
         his1    n   percent valid_percent
     Hispanic 4665 0.5192565     0.7104782
 Non Hispanic 1901 0.2115984     0.2895218
         <NA> 2418 0.2691451            NA
summary(dat97)
       ID            SEX            BDATEM           BDATEY    
 Min.   :   1   Min.   :1.000   Min.   : 1.000   Min.   :1980  
 1st Qu.:2249   1st Qu.:1.000   1st Qu.: 3.000   1st Qu.:1981  
 Median :4502   Median :1.000   Median : 7.000   Median :1982  
 Mean   :4504   Mean   :1.488   Mean   : 6.556   Mean   :1982  
 3rd Qu.:6758   3rd Qu.:2.000   3rd Qu.:10.000   3rd Qu.:1983  
 Max.   :9022   Max.   :2.000   Max.   :12.000   Max.   :1984  
   SAMPLETYPE       ETHNICITY       HDEGREE04      HDEGREE2010    
 Min.   :0.0000   Min.   :1.000   Min.   :-5.00   Min.   :-5.000  
 1st Qu.:1.0000   1st Qu.:1.000   1st Qu.: 0.00   1st Qu.: 0.000  
 Median :1.0000   Median :4.000   Median : 2.00   Median : 2.000  
 Mean   :0.7511   Mean   :2.788   Mean   : 0.66   Mean   : 1.045  
 3rd Qu.:1.0000   3rd Qu.:4.000   3rd Qu.: 2.00   3rd Qu.: 3.000  
 Max.   :1.0000   Max.   :4.000   Max.   : 7.00   Max.   : 7.000  
  HDEGREE2019        VSTRAT            VPSU      samplingweight   
 Min.   :-5.00   Min.   :  1.00   Min.   :1.00   Min.   :      0  
 1st Qu.: 0.00   1st Qu.: 21.00   1st Qu.:1.00   1st Qu.:      0  
 Median : 2.00   Median : 41.00   Median :1.00   Median :      0  
 Mean   : 0.85   Mean   : 46.56   Mean   :1.49   Mean   : 215700  
 3rd Qu.: 3.00   3rd Qu.: 65.00   3rd Qu.:2.00   3rd Qu.: 518286  
 Max.   : 7.00   Max.   :117.00   Max.   :2.00   Max.   :2773108  
     DATEBA       Bachelors04 Bachelors10 Bachelors19 Hispanic   
 Min.   : -4.00   0   :6867   0   :5570   0   :4772   0   :1901  
 1st Qu.: -4.00   1   : 568   1   :1853   1   :2150   1   :4665  
 Median : -4.00   NA's:1549   NA's:1561   NA's:2062   NA's:2418  
 Mean   : 81.82                                                  
 3rd Qu.:269.00                                                  
 Max.   :481.00                                                  
           his1     
 Hispanic    :4665  
 Non Hispanic:1901  
 NA's        :2418  
                    
                    
                    
summary(dat97$DATEBA)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  -4.00   -4.00   -4.00   81.82  269.00  481.00 
dat97<- dat97 %>% filter(DATEBA>0)


dat97$BAYR<-ifelse(dat97$HDEGREE04==2,
                   (2004-dat97$BDATEY),
                   ifelse(dat97$HDEGREE04==4,dat97$DATEBA/12,NA)) ## For Censored because they dont have a bachelors degree yet


summary(dat97$BAYR)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  20.00   21.00   22.00   22.04   23.42   36.08     369 
                  ## For the wave of 2004
dat97$BAYR1<-ifelse(dat97$HDEGREE2010==2,
                   (2010-dat97$BDATEY),
                   ifelse(dat97$HDEGREE2010==4,dat97$DATEBA/12,NA)) ## For Censored because they dont have a bachelors degree yet


summary(dat97$BAYR1)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  21.42   25.33   26.42   26.48   28.00   36.08     663 
                  ## For the wave of 2010
dat97$BAYR2<-ifelse(dat97$HDEGREE2019==2,
                   (2019-dat97$BDATEY),
                   ifelse(dat97$HDEGREE2019==4,dat97$DATEBA/12,NA)) ## For Censored because they dont have a bachelors degree yet


summary(dat97$BAYR2)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
  21.42   25.42   26.92   28.06   29.67   40.08     972 
                  ## For the wave of 2019
dat97<- data.frame(dat97)

fit<-survfit(Surv(time = BAYR, event = as.numeric(Bachelors04) )~his1,
           data = dat97) 

summary(fit)
Call: survfit(formula = Surv(time = BAYR, event = as.numeric(Bachelors04)) ~ 
    his1, data = dat97)

743 observations deleted due to missingness 
                his1=Hispanic 
 time n.risk n.event survival  std.err lower 95% CI upper 95% CI
 20.4   1029       1  0.99903 0.000971     0.997126       1.0000
 21.4    752       5  0.99239 0.003114     0.986301       0.9985
 22.0    747       6  0.98441 0.004477     0.975678       0.9932
 22.1    548       1  0.98262 0.004816     0.973224       0.9921
 22.3    547       3  0.97723 0.005707     0.966108       0.9885
 22.4    544      40  0.90537 0.012147     0.881877       0.9295
 22.5    504       6  0.89460 0.012774     0.869906       0.9200
 22.6    498       1  0.89280 0.012874     0.867920       0.9184
 22.7    497       1  0.89100 0.012973     0.865936       0.9168
 22.8    496       1  0.88921 0.013071     0.863954       0.9152
 23.0    495      10  0.87124 0.013987     0.844256       0.8991
 23.2    382       1  0.86896 0.014135     0.841695       0.8971
 23.3    381       3  0.86212 0.014565     0.834040       0.8911
 23.4    378      99  0.63633 0.022264     0.594153       0.6815
 23.5    279      17  0.59755 0.022807     0.554485       0.6440
 23.6    262       2  0.59299 0.022860     0.549839       0.6395
 23.7    260       9  0.57247 0.023070     0.528990       0.6195
 24.0    251      41  0.47896 0.023473     0.435090       0.5272
 24.1    152       1  0.47580 0.023529     0.431853       0.5242
 24.2    151       2  0.46950 0.023636     0.425390       0.5182
 24.3    149      11  0.43484 0.024091     0.390098       0.4847
 24.4    138     108  0.09453 0.016141     0.067644       0.1321
 24.5     30      11  0.05987 0.013179     0.038890       0.0922
 24.6     19       3  0.05042 0.012176     0.031405       0.0809
 24.7     16      15  0.00315 0.003144     0.000446       0.0223
 36.1      1       1  0.00000      NaN           NA           NA

                his1=Non Hispanic 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
 22.4     99       4    0.960  0.0198      0.92158        0.999
 22.5     95       1    0.949  0.0220      0.90732        0.994
 22.6     94       1    0.939  0.0240      0.89355        0.988
 23.0     93       1    0.929  0.0258      0.88015        0.981
 23.1     62       1    0.914  0.0294      0.85849        0.974
 23.2     61       2    0.884  0.0352      0.81787        0.956
 23.2     59       1    0.869  0.0377      0.79850        0.946
 23.3     58       1    0.854  0.0399      0.77958        0.936
 23.4     57       7    0.749  0.0510      0.65577        0.856
 23.5     50       3    0.704  0.0542      0.60588        0.819
 23.6     47       2    0.674  0.0559      0.57341        0.793
 23.7     45       2    0.645  0.0573      0.54150        0.767
 23.8     43       2    0.615  0.0584      0.51010        0.740
 23.9     41       1    0.600  0.0589      0.49459        0.727
 24.0     40       4    0.540  0.0601      0.43372        0.671
 24.3     15       2    0.468  0.0704      0.34813        0.628
 24.4     13       9    0.144  0.0637      0.06045        0.342
 24.5      4       3    0.036  0.0350      0.00535        0.242
 24.7      1       1    0.000     NaN           NA           NA
fit %>%
ggsurvfit()+
  xlim(18, 25)
Warning: Removed 3 row(s) containing missing values (geom_path).

## Wave of 2004
fit1<-survfit(Surv(time = BAYR1, event = as.numeric(Bachelors10) )~his1,
           data = dat97) 

summary(fit1)
Call: survfit(formula = Surv(time = BAYR1, event = as.numeric(Bachelors10)) ~ 
    his1, data = dat97)

974 observations deleted due to missingness 
                his1=Hispanic 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
 21.4   1096       2  0.99818 0.00129     0.995652       1.0000
 22.0   1094       3  0.99544 0.00204     0.991456       0.9994
 22.1   1091       1  0.99453 0.00223     0.990167       0.9989
 22.3   1090       2  0.99270 0.00257     0.987674       0.9978
 22.4   1088      22  0.97263 0.00493     0.963016       0.9823
 22.5   1066       4  0.96898 0.00524     0.958768       0.9793
 22.6   1062       1  0.96807 0.00531     0.957712       0.9785
 22.7   1061       4  0.96442 0.00560     0.953511       0.9754
 23.0   1057       6  0.95894 0.00599     0.947266       0.9708
 23.2   1051       1  0.95803 0.00606     0.946231       0.9700
 23.3   1050       2  0.95620 0.00618     0.944166       0.9684
 23.4   1048      68  0.89416 0.00929     0.876132       0.9126
 23.5    980      13  0.88230 0.00973     0.863426       0.9016
 23.6    967       2  0.88047 0.00980     0.861477       0.8999
 23.7    965       9  0.87226 0.01008     0.852723       0.8923
 24.0    956      28  0.84672 0.01088     0.825653       0.8683
 24.2    928       2  0.84489 0.01093     0.823728       0.8666
 24.3    926       8  0.83759 0.01114     0.816038       0.8597
 24.4    918      80  0.76460 0.01281     0.739890       0.7901
 24.5    838       5  0.76004 0.01290     0.735169       0.7857
 24.6    833       2  0.75821 0.01293     0.733282       0.7840
 24.7    831       9  0.75000 0.01308     0.724798       0.7761
 24.8    822       1  0.74909 0.01310     0.723856       0.7752
 25.0    821      25  0.72628 0.01347     0.700355       0.7532
 25.1    796       3  0.72354 0.01351     0.697540       0.7505
 25.2    793       1  0.72263 0.01352     0.696603       0.7496
 25.3    792      13  0.71077 0.01370     0.684424       0.7381
 25.4    779      96  0.62318 0.01464     0.595136       0.6525
 25.5    683      10  0.61405 0.01470     0.585896       0.6436
 25.6    673       4  0.61040 0.01473     0.582203       0.6400
 25.7    669      16  0.59580 0.01482     0.567447       0.6256
 25.8    653       1  0.59489 0.01483     0.566526       0.6247
 26.0    652      45  0.55383 0.01502     0.525171       0.5841
 26.1    584       2  0.55194 0.01502     0.523261       0.5822
 26.2    582       1  0.55099 0.01503     0.522307       0.5812
 26.3    581       7  0.54435 0.01505     0.515628       0.5747
 26.4    574     117  0.43339 0.01508     0.404820       0.4640
 26.5    457      20  0.41443 0.01501     0.386035       0.4449
 26.6    437       2  0.41253 0.01500     0.384159       0.4430
 26.7    435      12  0.40115 0.01494     0.372913       0.4315
 26.8    423       4  0.39736 0.01492     0.369168       0.4277
 26.9    419       4  0.39356 0.01489     0.365425       0.4239
 27.0    415      56  0.34046 0.01448     0.313230       0.3700
 27.1    337       2  0.33843 0.01446     0.311245       0.3680
 27.2    335       1  0.33742 0.01445     0.310252       0.3670
 27.3    334       7  0.33035 0.01440     0.303309       0.3598
 27.4    327      78  0.25155 0.01345     0.226533       0.2793
 27.5    249      11  0.24044 0.01326     0.215802       0.2679
 27.6    238       2  0.23842 0.01323     0.213853       0.2658
 27.7    236      11  0.22731 0.01303     0.203153       0.2543
 27.8    225       2  0.22529 0.01299     0.201211       0.2522
 27.9    223       2  0.22327 0.01295     0.199269       0.2502
 28.0    221      28  0.19498 0.01237     0.172188       0.2208
 28.1    182       2  0.19284 0.01232     0.170136       0.2186
 28.2    180       2  0.19069 0.01228     0.168085       0.2163
 28.2    178       1  0.18962 0.01226     0.167060       0.2152
 28.3    177       1  0.18855 0.01223     0.166036       0.2141
 28.4    176      39  0.14677 0.01120     0.126375       0.1705
 28.5    137       5  0.14141 0.01105     0.121336       0.1648
 28.7    132       6  0.13499 0.01085     0.115305       0.1580
 28.8    126       1  0.13391 0.01082     0.114302       0.1569
 28.9    125       1  0.13284 0.01079     0.113299       0.1558
 29.0    124      21  0.11035 0.01001     0.092364       0.1318
 29.1     79       1  0.10895 0.00998     0.091036       0.1304
 29.3     78       2  0.10615 0.00992     0.088385       0.1275
 29.4     76      18  0.08101 0.00917     0.064890       0.1011
 29.5     58       3  0.07682 0.00901     0.061044       0.0967
 29.6     55       2  0.07403 0.00890     0.058492       0.0937
 29.7     53       3  0.06984 0.00872     0.054683       0.0892
 29.8     50       1  0.06844 0.00865     0.053419       0.0877
 29.8     49       3  0.06425 0.00846     0.049644       0.0832
 30.0     46      10  0.05028 0.00768     0.037269       0.0678
 30.4     25      14  0.02212 0.00603     0.012969       0.0377
 30.5     11       1  0.02011 0.00581     0.011422       0.0354
 30.6     10       1  0.01810 0.00556     0.009911       0.0331
 30.7      9       4  0.01006 0.00431     0.004345       0.0233
 31.3      5       1  0.00805 0.00389     0.003121       0.0207
 31.4      4       1  0.00603 0.00340     0.002003       0.0182
 32.1      3       1  0.00402 0.00280     0.001030       0.0157
 33.5      2       1  0.00201 0.00199     0.000288       0.0140
 36.1      1       1  0.00000     NaN           NA           NA

                his1=Non Hispanic 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
 22.4    256       1  0.99609 0.00390      0.98848       1.0000
 22.5    255       1  0.99219 0.00550      0.98146       1.0000
 22.6    254       1  0.98828 0.00673      0.97519       1.0000
 23.0    253       1  0.98438 0.00775      0.96930       0.9997
 23.1    252       1  0.98047 0.00865      0.96366       0.9976
 23.2    251       2  0.97266 0.01019      0.95288       0.9928
 23.2    249       1  0.96875 0.01087      0.94767       0.9903
 23.4    248       7  0.94141 0.01468      0.91307       0.9706
 23.5    241       2  0.93359 0.01556      0.90359       0.9646
 23.6    239       1  0.92969 0.01598      0.89889       0.9615
 23.7    238       1  0.92578 0.01638      0.89422       0.9585
 23.9    237       1  0.92188 0.01677      0.88958       0.9553
 24.0    236       3  0.91016 0.01787      0.87579       0.9459
 24.3    233       2  0.90234 0.01855      0.86670       0.9394
 24.4    231       6  0.87891 0.02039      0.83984       0.9198
 24.5    225       1  0.87500 0.02067      0.83541       0.9165
 24.7    224       1  0.87109 0.02094      0.83100       0.9131
 25.0    223       4  0.85547 0.02198      0.81346       0.8996
 25.2    219       1  0.85156 0.02222      0.80911       0.8962
 25.3    218       1  0.84766 0.02246      0.80476       0.8928
 25.4    217      17  0.78125 0.02584      0.73222       0.8336
 25.5    200       3  0.76953 0.02632      0.71963       0.8229
 25.6    197       1  0.76562 0.02648      0.71545       0.8193
 25.7    196       1  0.76172 0.02663      0.71128       0.8157
 25.8    195       1  0.75781 0.02678      0.70711       0.8122
 25.8    194       2  0.75000 0.02706      0.69879       0.8050
 26.0    192      10  0.71094 0.02833      0.65752       0.7687
 26.1    165       1  0.70663 0.02849      0.65294       0.7647
 26.3    164       1  0.70232 0.02864      0.64838       0.7608
 26.4    163      21  0.61184 0.03102      0.55397       0.6758
 26.5    142       4  0.59460 0.03132      0.53628       0.6593
 26.6    138       1  0.59029 0.03139      0.53188       0.6551
 26.7    137       3  0.57737 0.03157      0.51869       0.6427
 26.8    134       1  0.57306 0.03163      0.51430       0.6385
 27.0    133       8  0.53859 0.03199      0.47940       0.6051
 27.4    119      13  0.47975 0.03239      0.42029       0.5476
 27.5    106       1  0.47523 0.03240      0.41578       0.5432
 27.6    105       1  0.47070 0.03241      0.41128       0.5387
 27.7    104       1  0.46617 0.03241      0.40679       0.5342
 28.0    103      12  0.41186 0.03220      0.35334       0.4801
 28.1     84       2  0.40206 0.03217      0.34369       0.4703
 28.2     82       1  0.39715 0.03215      0.33888       0.4654
 28.2     81       1  0.39225 0.03213      0.33408       0.4606
 28.3     80       1  0.38735 0.03210      0.32928       0.4557
 28.4     79      13  0.32361 0.03131      0.26771       0.3912
 28.5     66       1  0.31870 0.03122      0.26304       0.3862
 28.6     65       1  0.31380 0.03112      0.25837       0.3811
 28.7     64       1  0.30890 0.03102      0.25372       0.3761
 28.8     63       1  0.30399 0.03091      0.24907       0.3710
 29.0     62       7  0.26967 0.03002      0.21681       0.3354
 29.1     44       2  0.25741 0.02988      0.20504       0.3232
 29.4     42       5  0.22677 0.02930      0.17604       0.2921
 29.5     37       3  0.20838 0.02878      0.15896       0.2732
 29.7     34       3  0.19000 0.02813      0.14214       0.2540
 29.8     31       2  0.17774 0.02762      0.13107       0.2410
 30.0     29       3  0.15935 0.02672      0.11471       0.2214
 30.3     17       1  0.14998 0.02675      0.10574       0.2127
 30.4     16       8  0.07499 0.02303      0.04108       0.1369
 30.6      8       2  0.05624 0.02074      0.02730       0.1159
 30.7      6       1  0.04687 0.01928      0.02092       0.1050
 31.0      5       2  0.02812 0.01547      0.00957       0.0827
 32.4      3       1  0.01875 0.01284      0.00490       0.0718
 32.6      2       1  0.00937 0.00923      0.00136       0.0646
 33.0      1       1  0.00000     NaN           NA           NA
fit1 %>%
ggsurvfit()+
  xlim(18, 30)
Warning: Removed 19 row(s) containing missing values (geom_path).

## Wave of 2010
fit2<-survfit(Surv(time = BAYR2, event = as.numeric(Bachelors19) )~his1,
           data = dat97) 

summary(fit2)
Call: survfit(formula = Surv(time = BAYR2, event = as.numeric(Bachelors19)) ~ 
    his1, data = dat97)

1226 observations deleted due to missingness 
                his1=Hispanic 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
 21.4    871       3  0.99656 0.00199     0.992672      1.00000
 22.0    868       3  0.99311 0.00280     0.987634      0.99862
 22.1    865       1  0.99196 0.00303     0.986051      0.99791
 22.3    864       2  0.98967 0.00343     0.982974      0.99641
 22.4    862      15  0.97245 0.00555     0.961635      0.98338
 22.5    847       4  0.96785 0.00598     0.956209      0.97964
 22.6    843       1  0.96670 0.00608     0.954864      0.97869
 23.0    842       3  0.96326 0.00637     0.950848      0.97584
 23.2    839       1  0.96211 0.00647     0.949516      0.97488
 23.3    838       2  0.95982 0.00665     0.946862      0.97295
 23.4    836      55  0.89667 0.01031     0.876682      0.91711
 23.5    781       6  0.88978 0.01061     0.869226      0.91082
 23.6    775       2  0.88749 0.01071     0.866746      0.90872
 23.7    773       8  0.87830 0.01108     0.856855      0.90028
 23.8    765       1  0.87715 0.01112     0.855621      0.89923
 24.0    764      24  0.84960 0.01211     0.826187      0.87367
 24.2    740       2  0.84730 0.01219     0.823748      0.87153
 24.3    738       7  0.83927 0.01245     0.815224      0.86401
 24.4    731      71  0.75775 0.01452     0.729824      0.78674
 24.5    660       2  0.75545 0.01456     0.727441      0.78454
 24.6    658       1  0.75431 0.01459     0.726251      0.78344
 24.7    657       6  0.74742 0.01472     0.719112      0.77684
 25.0    651      21  0.72331 0.01516     0.694199      0.75363
 25.1    630       3  0.71986 0.01522     0.690649      0.75031
 25.3    627       8  0.71068 0.01536     0.681193      0.74144
 25.4    619      69  0.63146 0.01635     0.600220      0.66432
 25.5    550       7  0.62342 0.01642     0.592060      0.65644
 25.6    543       2  0.62113 0.01644     0.589730      0.65419
 25.7    541      11  0.60850 0.01654     0.576930      0.64179
 26.0    530      29  0.57520 0.01675     0.543292      0.60898
 26.1    501       1  0.57405 0.01676     0.542135      0.60785
 26.2    500       1  0.57290 0.01676     0.540978      0.60672
 26.3    499       7  0.56487 0.01680     0.532884      0.59877
 26.4    492      85  0.46728 0.01691     0.435292      0.50162
 26.5    407      13  0.45235 0.01686     0.420478      0.48665
 26.6    394       2  0.45006 0.01686     0.418202      0.48434
 26.7    392      10  0.43858 0.01681     0.406830      0.47280
 26.8    382       3  0.43513 0.01680     0.403422      0.46933
 26.9    379       4  0.43054 0.01678     0.398881      0.46471
 27.0    375      41  0.38347 0.01648     0.352499      0.41716
 27.1    334       2  0.38117 0.01646     0.350244      0.41483
 27.3    332       7  0.37313 0.01639     0.342359      0.40668
 27.4    325      54  0.31114 0.01569     0.281861      0.34345
 27.5    271       6  0.30425 0.01559     0.275177      0.33639
 27.6    265       1  0.30310 0.01557     0.274064      0.33521
 27.7    264       5  0.29736 0.01549     0.268501      0.32932
 27.8    259       1  0.29621 0.01547     0.267389      0.32814
 27.9    258       2  0.29392 0.01544     0.265166      0.32578
 28.0    256      20  0.27095 0.01506     0.242987      0.30214
 28.1    236       1  0.26980 0.01504     0.241881      0.30095
 28.2    235       1  0.26866 0.01502     0.240775      0.29977
 28.2    234       1  0.26751 0.01500     0.239669      0.29858
 28.3    233       1  0.26636 0.01498     0.238563      0.29740
 28.4    232      25  0.23766 0.01442     0.211007      0.26768
 28.5    207       4  0.23307 0.01433     0.206613      0.26290
 28.7    203       3  0.22962 0.01425     0.203321      0.25932
 28.8    200       1  0.22847 0.01423     0.202225      0.25813
 29.0    199      14  0.21240 0.01386     0.186902      0.24138
 29.1    185       1  0.21125 0.01383     0.185810      0.24018
 29.3    184       1  0.21010 0.01380     0.184718      0.23898
 29.4    183      14  0.19403 0.01340     0.169467      0.22215
 29.5    169       1  0.19288 0.01337     0.168381      0.22095
 29.6    168       1  0.19173 0.01334     0.167294      0.21974
 29.7    167       3  0.18829 0.01325     0.164037      0.21613
 29.8    164       2  0.18599 0.01318     0.161867      0.21371
 29.8    162       2  0.18370 0.01312     0.159699      0.21130
 30.0    160       7  0.17566 0.01289     0.152122      0.20284
 30.4    153      10  0.16418 0.01255     0.141332      0.19072
 30.5    143       1  0.16303 0.01252     0.140256      0.18950
 30.7    142       4  0.15844 0.01237     0.135953      0.18464
 30.9    138       2  0.15614 0.01230     0.133805      0.18221
 31.0    136       8  0.14696 0.01200     0.125229      0.17246
 31.1    128       1  0.14581 0.01196     0.124159      0.17124
 31.3    127       1  0.14466 0.01192     0.123089      0.17001
 31.4    126       7  0.13662 0.01164     0.115618      0.16145
 31.5    119       2  0.13433 0.01155     0.113488      0.15900
 31.7    117       1  0.13318 0.01151     0.112424      0.15777
 31.8    116       1  0.13203 0.01147     0.111360      0.15654
 32.0    115       1  0.13088 0.01143     0.110297      0.15531
 32.1    114       1  0.12974 0.01139     0.109235      0.15408
 32.2    113       1  0.12859 0.01134     0.108173      0.15286
 32.4    112       3  0.12514 0.01121     0.104990      0.14916
 32.5    109       1  0.12400 0.01117     0.103931      0.14793
 32.6    108       1  0.12285 0.01112     0.102872      0.14670
 32.7    107       1  0.12170 0.01108     0.101814      0.14547
 32.9    106       2  0.11940 0.01099     0.099699      0.14300
 33.0    104       6  0.11251 0.01071     0.093370      0.13558
 33.1     98       2  0.11022 0.01061     0.091265      0.13311
 33.2     96       1  0.10907 0.01056     0.090214      0.13187
 33.4     95       3  0.10563 0.01041     0.087065      0.12814
 33.5     92       4  0.10103 0.01021     0.082877      0.12317
 33.6     88       1  0.09989 0.01016     0.081831      0.12192
 33.7     87       2  0.09759 0.01006     0.079744      0.11943
 34.0     85       5  0.09185 0.00979     0.074538      0.11318
 34.2     80       1  0.09070 0.00973     0.073500      0.11193
 34.3     79       1  0.08955 0.00968     0.072463      0.11067
 34.4     78       4  0.08496 0.00945     0.068322      0.10565
 34.5     74       2  0.08266 0.00933     0.066257      0.10313
 34.6     72       1  0.08152 0.00927     0.065227      0.10187
 34.8     71       3  0.07807 0.00909     0.062141      0.09809
 35.0     68       6  0.07118 0.00871     0.056000      0.09048
 35.4     62       3  0.06774 0.00851     0.052946      0.08666
 35.5     59       2  0.06544 0.00838     0.050917      0.08411
 35.7     57       1  0.06429 0.00831     0.049905      0.08283
 35.8     56       1  0.06315 0.00824     0.048894      0.08155
 36.0     55       2  0.06085 0.00810     0.046876      0.07899
 36.1     53       1  0.05970 0.00803     0.045869      0.07770
 36.2     52       1  0.05855 0.00796     0.044864      0.07642
 36.3     51       1  0.05741 0.00788     0.043861      0.07513
 36.4     50       4  0.05281 0.00758     0.039865      0.06997
 36.5     46       4  0.04822 0.00726     0.035900      0.06477
 36.6     42       1  0.04707 0.00718     0.034914      0.06347
 36.8     41       1  0.04592 0.00709     0.033930      0.06216
 36.9     40       1  0.04478 0.00701     0.032948      0.06085
 37.0     39       2  0.04248 0.00683     0.030992      0.05823
 37.1     37       1  0.04133 0.00674     0.030018      0.05691
 37.2     36       1  0.04018 0.00665     0.029046      0.05559
 37.4     35       6  0.03330 0.00608     0.023279      0.04762
 37.6     29       1  0.03215 0.00598     0.022330      0.04628
 37.8     28       1  0.03100 0.00587     0.021384      0.04494
 37.9     27       2  0.02870 0.00566     0.019505      0.04224
 38.0     25       4  0.02411 0.00520     0.015802      0.03679
 38.2     21       2  0.02181 0.00495     0.013983      0.03403
 38.4     19       3  0.01837 0.00455     0.011305      0.02985
 38.7     16       1  0.01722 0.00441     0.010428      0.02844
 38.8     15       1  0.01607 0.00426     0.009560      0.02703
 38.9     14       1  0.01493 0.00411     0.008702      0.02560
 39.0     13       4  0.01033 0.00343     0.005395      0.01979
 39.2      9       1  0.00918 0.00323     0.004608      0.01831
 39.4      8       2  0.00689 0.00280     0.003103      0.01529
 39.5      6       2  0.00459 0.00229     0.001728      0.01221
 39.6      4       1  0.00344 0.00199     0.001113      0.01066
 39.7      3       1  0.00230 0.00162     0.000575      0.00917
 40.0      2       1  0.00115 0.00115     0.000162      0.00814
 40.1      1       1  0.00000     NaN           NA           NA

                his1=Non Hispanic 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
 22.1    229       1  0.99563 0.00436      0.98713       1.0000
 22.4    228       1  0.99127 0.00615      0.97929       1.0000
 22.5    227       1  0.98690 0.00751      0.97228       1.0000
 22.6    226       1  0.98253 0.00866      0.96571       0.9996
 23.0    225       1  0.97817 0.00966      0.95942       0.9973
 23.1    224       1  0.97380 0.01056      0.95333       0.9947
 23.2    223       2  0.96507 0.01213      0.94157       0.9891
 23.2    221       1  0.96070 0.01284      0.93586       0.9862
 23.4    220       5  0.93886 0.01583      0.90834       0.9704
 23.6    215       1  0.93450 0.01635      0.90300       0.9671
 23.7    214       1  0.93013 0.01685      0.89769       0.9637
 23.9    213       1  0.92576 0.01732      0.89243       0.9603
 24.0    212       2  0.91703 0.01823      0.88199       0.9535
 24.3    210       2  0.90830 0.01907      0.87168       0.9465
 24.4    208       6  0.88210 0.02131      0.84130       0.9249
 24.5    202       1  0.87773 0.02165      0.83631       0.9212
 24.7    201       1  0.87336 0.02198      0.83133       0.9175
 25.0    200       3  0.86026 0.02291      0.81651       0.9064
 25.4    197      10  0.81659 0.02557      0.76798       0.8683
 25.5    187       3  0.80349 0.02626      0.75364       0.8566
 25.6    184       1  0.79913 0.02648      0.74888       0.8527
 25.7    183       1  0.79476 0.02669      0.74413       0.8488
 25.8    182       2  0.78603 0.02710      0.73466       0.8410
 26.0    180       9  0.74672 0.02874      0.69247       0.8052
 26.1    171       1  0.74236 0.02890      0.68782       0.8012
 26.3    170       1  0.73799 0.02906      0.68318       0.7972
 26.4    169      18  0.65939 0.03132      0.60078       0.7237
 26.5    151       2  0.65066 0.03151      0.59175       0.7154
 26.6    149       1  0.64629 0.03160      0.58724       0.7113
 26.7    148       1  0.64192 0.03168      0.58273       0.7071
 27.0    147       7  0.61135 0.03221      0.55137       0.6779
 27.3    140       1  0.60699 0.03228      0.54691       0.6737
 27.4    139       8  0.57205 0.03270      0.51143       0.6399
 27.5    131       2  0.56332 0.03277      0.50261       0.6314
 27.6    129       1  0.55895 0.03281      0.49821       0.6271
 27.7    128       1  0.55459 0.03284      0.49381       0.6228
 28.0    127       7  0.52402 0.03300      0.46317       0.5929
 28.1    120       2  0.51528 0.03303      0.45446       0.5843
 28.2    118       1  0.51092 0.03303      0.45011       0.5799
 28.4    117      10  0.46725 0.03297      0.40690       0.5366
 28.5    107       1  0.46288 0.03295      0.40260       0.5322
 28.6    106       1  0.45852 0.03293      0.39832       0.5278
 28.7    105       1  0.45415 0.03290      0.39403       0.5234
 29.0    104       6  0.42795 0.03270      0.36843       0.4971
 29.1     98       2  0.41921 0.03261      0.35994       0.4883
 29.4     96       3  0.40611 0.03245      0.34724       0.4750
 29.5     93       3  0.39301 0.03228      0.33458       0.4616
 29.7     90       2  0.38428 0.03214      0.32617       0.4527
 29.8     88       2  0.37555 0.03200      0.31778       0.4438
 30.0     86       4  0.35808 0.03168      0.30107       0.4259
 30.3     82       1  0.35371 0.03160      0.29690       0.4214
 30.4     81       8  0.31878 0.03079      0.26379       0.3852
 30.6     73       2  0.31004 0.03056      0.25557       0.3761
 31.0     71       2  0.30131 0.03032      0.24738       0.3670
 31.3     69       1  0.29694 0.03019      0.24329       0.3624
 31.4     68       2  0.28821 0.02993      0.23513       0.3533
 31.5     66       2  0.27948 0.02965      0.22700       0.3441
 31.9     64       2  0.27074 0.02936      0.21890       0.3349
 32.0     62       1  0.26638 0.02921      0.21486       0.3302
 32.3     61       2  0.25764 0.02890      0.20679       0.3210
 32.4     59       5  0.23581 0.02805      0.18677       0.2977
 32.5     54       1  0.23144 0.02787      0.18278       0.2931
 32.6     53       1  0.22707 0.02768      0.17881       0.2884
 32.8     52       1  0.22271 0.02749      0.17484       0.2837
 33.0     51       3  0.20961 0.02690      0.16300       0.2695
 33.2     48       1  0.20524 0.02669      0.15906       0.2648
 33.4     47       1  0.20087 0.02648      0.15514       0.2601
 33.5     46       1  0.19651 0.02626      0.15123       0.2553
 33.8     45       1  0.19214 0.02604      0.14733       0.2506
 33.9     44       1  0.18777 0.02581      0.14343       0.2458
 34.0     43       2  0.17904 0.02533      0.13567       0.2363
 34.4     41       4  0.16157 0.02432      0.12029       0.2170
 34.5     37       1  0.15721 0.02405      0.11647       0.2122
 35.0     36       2  0.14847 0.02350      0.10888       0.2025
 35.2     34       1  0.14410 0.02321      0.10510       0.1976
 35.4     33       3  0.13100 0.02230      0.09385       0.1829
 35.5     30       1  0.12664 0.02198      0.09013       0.1779
 35.7     29       1  0.12227 0.02165      0.08642       0.1730
 35.8     28       1  0.11790 0.02131      0.08273       0.1680
 36.0     27       3  0.10480 0.02024      0.07178       0.1530
 36.3     24       1  0.10044 0.01986      0.06816       0.1480
 36.4     23       2  0.09170 0.01907      0.06100       0.1379
 36.8     21       1  0.08734 0.01866      0.05746       0.1327
 37.0     20       1  0.08297 0.01823      0.05394       0.1276
 37.4     19       2  0.07424 0.01732      0.04699       0.1173
 37.7     17       1  0.06987 0.01685      0.04356       0.1121
 38.0     16       3  0.05677 0.01529      0.03348       0.0962
 38.4     13       3  0.04367 0.01350      0.02382       0.0801
 38.6     10       1  0.03930 0.01284      0.02072       0.0746
 39.0      9       1  0.03493 0.01213      0.01769       0.0690
 39.4      8       2  0.02620 0.01056      0.01190       0.0577
 39.5      6       1  0.02183 0.00966      0.00918       0.0520
 39.6      5       1  0.01747 0.00866      0.00661       0.0461
 39.7      4       1  0.01310 0.00751      0.00426       0.0403
 39.8      3       1  0.00873 0.00615      0.00220       0.0347
 40.0      2       2  0.00000     NaN           NA           NA
fit2 %>%
ggsurvfit()+
  xlim(18, 45)
Warning: Removed 2 row(s) containing missing values (geom_path).

## Wave of 2019
survdiff(Surv(dat97$BAYR, as.numeric(dat97$Bachelors04))~dat97$his1,
         data=dat97) ##Outcomes 2004
Call:
survdiff(formula = Surv(dat97$BAYR, as.numeric(dat97$Bachelors04)) ~ 
    dat97$his1, data = dat97)

n=1583, 743 observations deleted due to missingness.

                           N Observed Expected (O-E)^2/E (O-E)^2/V
dat97$his1=Hispanic     1311      399    392.9    0.0953       1.1
dat97$his1=Non Hispanic  272       48     54.1    0.6916       1.1

 Chisq= 1.1  on 1 degrees of freedom, p= 0.3 
survdiff(Surv(dat97$BAYR1, as.numeric(dat97$Bachelors10))~dat97$his1,
         data=dat97) ##Outcomes 2010
Call:
survdiff(formula = Surv(dat97$BAYR1, as.numeric(dat97$Bachelors10)) ~ 
    dat97$his1, data = dat97)

n=1352, 974 observations deleted due to missingness.

                           N Observed Expected (O-E)^2/E (O-E)^2/V
dat97$his1=Hispanic     1096     1005      911      9.81      45.2
dat97$his1=Non Hispanic  256      206      300     29.72      45.2

 Chisq= 45.2  on 1 degrees of freedom, p= 2e-11 
survdiff(Surv(dat97$BAYR2, as.numeric(dat97$Bachelors19))~dat97$his1,
         data=dat97) ##Outcomes 2010
Call:
survdiff(formula = Surv(dat97$BAYR2, as.numeric(dat97$Bachelors19)) ~ 
    dat97$his1, data = dat97)

n=1100, 1226 observations deleted due to missingness.

                          N Observed Expected (O-E)^2/E (O-E)^2/V
dat97$his1=Hispanic     871      871      788      8.75      33.7
dat97$his1=Non Hispanic 229      229      312     22.09      33.7

 Chisq= 33.7  on 1 degrees of freedom, p= 6e-09 
#create the design: ids == PSU, strata==strata, weights==weights.
options(survey.lonely.psu = "adjust")

des<-svydesign(ids= ~VPSU,
strata = ~VSTRAT,
weights=~samplingweight,
data=dat97,
nest=TRUE)
fit.s<-svykm(Surv(BAYR, as.numeric(Bachelors04))~his1,
             design = des, se=T)
plot(fit.s[[2]], ylim=c(0,1), xlim=c(18,25),col=1, ci=F )
lines(fit.s[[1]], col=2)
title(main="Survival Function for Obtaining a Bachelors Between Hispanics and Non Hispanic Whites 2004",
sub="Hispanics vs Non-Hispanic Whites")
legend("topright",
legend = c("Hispanics","Non-Hispanic Whites" ),
col=c(1,2), lty=1)

fit.s1<-svykm(Surv(BAYR1, as.numeric(Bachelors10))~his1,
             design = des, se=T)
plot(fit.s1[[2]], ylim=c(0,1), xlim=c(18,35),col=1, ci=F )
lines(fit.s1[[1]], col=2)
title(main="Survival Function for Obtaining a Bachelors Between Hispanics and Non Hispanic Whites 2010",
sub="Hispanics vs Non-Hispanic Whites")
legend("topright",
legend = c("Hispanics","Non-Hispanic Whites" ),
col=c(1,2), lty=1)

fit.s2<-svykm(Surv(BAYR2, as.numeric(Bachelors19))~his1,
             design = des, se=T)
plot(fit.s2[[2]], ylim=c(0,1), xlim=c(18,45),col=1, ci=F )
lines(fit.s2[[1]], col=2)
title(main="Survival Function for Obtaining a Bachelors Between Hispanics and Non Hispanic Whites 2010",
sub="Hispanics vs Non-Hispanic Whites")
legend("topright",
legend = c("Hispanics","Non-Hispanic Whites" ),
col=c(1,2), lty=1)