Kinship

Author

Coda

Children in Kinship Care in Texas Estimates

Data for this analysis from the 2023 Annual Social and Economic Supplement (ASEC) of the Current Population Survey (CPS).

Import Data

I filtered before downloading the data from IPUMS for TX (Fips 48)

Defining Kinship

To define kinship, I have to link using the RELATE variable and then specify no mother or father in household using the MOMLOC and POPLOC variables. There is no readily available variable to do this, so this is a work around.

AECF defines kinship in the following manner:

To define children in kinship care we use data on whether there is a parent in the household (PARENT) and the relationship of the child to the reference person (PERRP).

Specifically, children are in kinship care if there is no parent present in the household and the relationship between the child and the reference person is:

- Grandchild

- Brother/sister

- Other rel. of ref. person

- Nonrel. of ref. person w/rels.

- Nonrel. of ref. person w/o rels.

- Housemate/roommate w/rels.

- Roomer/boarder w/rels.

Note that the above definition is only relevant if using Census files from here: https://www.census.gov/data/datasets/time-series/demo/cps/cps-asec.html

However, for this analysis, I am using microdata from IPUMS. So, given the description of the RELATE variable, I included the following in my classification of kinship:

The definition on the AECF Kids Count Dashboard seems inconsistent with the one on the in the email from Alicia. Which is it??

#Here I am filtering to get children under 18
kinchildren <- kin|>
  filter( AGE < 18, YEAR== 2023)


kinchildren <- kinchildren|>
  filter(!is.na(ASECWT))

#Defining what classifies as kinship per Alicia VN's definition. 
kinchildren2 <- kinchildren |>
    filter(
    MOMLOC == 0 & POPLOC == 0 & 
    RELATE %in% c(0901, 0701, 1001, 1260)
  )

kinchildren2 <- kinchildren2 |>
  mutate(
    RaceEthnicity = case_when(
      HISPAN != 0 ~ "Hispanic",
      RACE == 100 & HISPAN == 0 ~ "White",
      RACE == 200 & HISPAN == 0 ~ "African-American",
      RACE != 100 & RACE != 200 & HISPAN == 0 ~ "Non-Hispanic Other"
    )
  )


# kinchildren3 <- kinchildren2|>
#   mutate(ASEC_adjusted = ASECWT / 10000)            <--Leaving this as a reminder to myself that we don't need to divide because this is automatically done for us via variable definition here: https://cps.ipums.org/cps-action/variables/ASECWT#codes_section


#create survey design 
des <- svydesign(
  ids = ~1,  
  weights = ~ASECWT,  
  data = kinchildren2
)



#calculations -- using a binary indicator 

total_kinship_care <- svytotal(~I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(0901, 0701, 1001, 1260)), 
                               des, 
                               na.rm = TRUE)
print(total_kinship_care)
                                                                         total
I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))FALSE      0
I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))TRUE  263013
                                                                           SE
I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))FALSE     0
I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))TRUE  10096
total_by_race <- svyby(~I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(0901, 0701, 1001, 1260)), 
                       ~RaceEthnicity, 
                       des, 
                       svytotal, 
                       na.rm = TRUE)
print(total_by_race)
                        RaceEthnicity
African-American     African-American
Hispanic                     Hispanic
Non-Hispanic Other Non-Hispanic Other
White                           White
                   I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))FALSE
African-American                                                                         0
Hispanic                                                                                 0
Non-Hispanic Other                                                                       0
White                                                                                    0
                   I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))TRUE
African-American                                                                 46678.65
Hispanic                                                                        115611.74
Non-Hispanic Other                                                               11729.48
White                                                                            88993.49
                   se.I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))FALSE
African-American                                                                            0
Hispanic                                                                                    0
Non-Hispanic Other                                                                          0
White                                                                                       0
                   se.I(MOMLOC == 0 & POPLOC == 0 & RELATE %in% c(901, 701, 1001, 1260))TRUE
African-American                                                                   12578.588
Hispanic                                                                           13512.907
Non-Hispanic Other                                                                  8952.891
White                                                                              14949.567
total_weighted_population <- svytotal(~RELATE, des)
print(total_weighted_population)
           total       SE
RELATE 261960728 10819300
total_weight <- sum(kinchildren2$ASECWT, na.rm = TRUE)
print(total_weight)
[1] 263013.4

Method #2 – Cross Validating Results

#Cross validating
# Create a binary indicator for being in kinship care
kinchildren3 <- kinchildren2 %>%
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 & 
      RELATE %in% c(0901, 0701, 1001, 1260), 
      1, 0
    )
  )

# Create survey design
des2 <- svydesign(
  ids = ~1,  
  weights = ~ASECWT,  
  data = kinchildren3
)

# Calculate the total number of children in kinship care by RaceEthnicity
kin_totals <- svyby(
  ~in_kinship,  
  ~RaceEthnicity,  
  des2,
  svytotal,
  na.rm = TRUE
)

# Print the results
print(kin_totals)
                        RaceEthnicity in_kinship        se
African-American     African-American   46678.65 12578.588
Hispanic                     Hispanic  115611.74 13512.907
Non-Hispanic Other Non-Hispanic Other   11729.48  8952.891
White                           White   88993.49 14949.567
# Cross-validate by calculating the overall total and by group
overall_total <- svytotal(~in_kinship, des2)
print(overall_total)
            total    SE
in_kinship 263013 10096
# Validate by summing up individual totals
grouped_totals <- kin_totals %>%
  summarise(Total_Kinship = sum(in_kinship))
print(grouped_totals)
  Total_Kinship
1      263013.4

Method #3 – Cross Validating Results (Tidyverse language)

kinchildren4 <- kinchildren2|>
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 & 
      RELATE %in% c(0901, 0701, 1001, 1260), 
      1, 0
    )
  )

kin_totals_tidy <- kinchildren4|>
  group_by(RaceEthnicity) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE),
    .groups = 'drop'
  ) |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100
  )

print(kin_totals_tidy)
# A tibble: 4 × 3
  RaceEthnicity      Total_Kinship Percentage
  <chr>                      <dbl>      <dbl>
1 African-American          46679.      17.7 
2 Hispanic                 115612.      44.0 
3 Non-Hispanic Other        11729.       4.46
4 White                     88993.      33.8 
#----------------USING A SCALING FACTOR----------Didn't end up using, but useful in other situations, possibly. Messed around with this option because I had an estimate from the AECF/PRB 3-year estimate of 272,000 from KC data dashboard. Wanted to see what it looked like

# total_weighted <- sum(kinchildren2$WTFINL, na.rm = TRUE)
# 
# scaling_factor <- 272000 / total_weighted
# 
# kinchildren2 <- kinchildren2|>
#   mutate(
#     ScaledWTFINL = WTFINL * scaling_factor
#   )
# 
# kinship_summary <- kinchildren2|>
#   group_by(RaceEthnicity) |>
#   summarize(
#     WeightedNumber = sum(ScaledWTFINL, na.rm = TRUE)
#   ) %>%
#   mutate(
#     Percentage = (WeightedNumber / sum(WeightedNumber)) * 100,
#     WeightedNumber = comma(WeightedNumber, accuracy = 1),
#     Percentage = round(Percentage, 1)
#   )
# print(kinship_summary)

Poverty Try #1

Now, I want to recreate the estimate of children in kinship care living in households below 150% of poverty.

#  binary indicator for kinship care and for poverty status
kinpov<- kinchildren2 |>
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 & 
      RELATE %in% c(0901, 0701, 1001, 1260), 
      1, 0
    ),
    below_150_poverty = ifelse(POVERTY %in% c(10, 21, 22), 1, 0)  # 1 if below 150% poverty, 0 otherwise
  )

# Filter to keep only those below 150% of poverty
kinpov2 <- kinpov |>
  filter(below_150_poverty == 1, in_kinship == 1)


kinpov_summary <- kinpov2 |>
  group_by(RaceEthnicity) |>
  summarise(
    Total_Kinship_Below_150 = sum(ASECWT, na.rm = TRUE),  # No need to multiply by in_kinship since we already filtered for it
    .groups = 'drop'
  ) |>
  mutate(
    Percentage = Total_Kinship_Below_150 / sum(Total_Kinship_Below_150) * 100
  )


# Print the results for children in kinship care below 150% of poverty
print(kinpov_summary)
# A tibble: 3 × 3
  RaceEthnicity    Total_Kinship_Below_150 Percentage
  <chr>                              <dbl>      <dbl>
1 African-American                  17850.       23.0
2 Hispanic                          35246.       45.5
3 White                             24395.       31.5
# Calculate overall total below 150% poverty
overall_total_poverty1 <- kinpov_summary |>
  summarise(
    Overall_Kinship_Below_150 = sum(Total_Kinship_Below_150)
  )

print(overall_total_poverty1)
# A tibble: 1 × 1
  Overall_Kinship_Below_150
                      <dbl>
1                    77490.

3 and 1 Year Estimates

Because AECF produces 3-year averages, I went ahead and also ran the numbers. Lower than 1 year estimate.

Overall totals

library(tidyverse)
library(ipumsr)
library(survey)

ddi <- read_ipums_ddi("cps_00065.xml")
kin2 <- read_ipums_micro(ddi)
Use of data from IPUMS CPS is subject to conditions including that users should cite the data appropriately. Use command `ipums_conditions()` for more details.
kinchildren_all_years <- kin2 |>
  filter(AGE < 18)

kin_allyears2 <- kinchildren_all_years |>
  filter(
    MOMLOC == 0 & POPLOC == 0 &
    RELATE %in% c(0901, 0701, 1001, 1260)
  ) |>
  mutate(
    RaceEthnicity = case_when(
      HISPAN != 0 ~ "Hispanic",
      RACE == 100 & HISPAN == 0 ~ "White",
      RACE == 200 & HISPAN == 0 ~ "African-American",
      RACE != 100 & RACE != 200 & HISPAN == 0 ~ "Non-Hispanic Other"
    )
  )

kin_allyears2 <- kin_allyears2 |>
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 &
      RELATE %in% c(0901, 0701, 1001, 1260),
      1, 0
    )
  )

kin_totals_years <- kin_allyears2 |>
  group_by(RaceEthnicity) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE) / 3,
    .groups = 'drop'
  ) |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100
  )

print(kin_totals_years)
# A tibble: 4 × 3
  RaceEthnicity      Total_Kinship Percentage
  <chr>                      <dbl>      <dbl>
1 African-American          46064.      18.9 
2 Hispanic                 113759.      46.6 
3 Non-Hispanic Other        10194.       4.17
4 White                     74302.      30.4 
overall_total <- kin_allyears2 |>
  summarise(
    Overall_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE) / 3)

print(overall_total)
# A tibble: 1 × 1
  Overall_Kinship
            <dbl>
1         244319.
#####################Yearly totals##################Use this in data brief 
# Group by Year and RaceEthnicity to calculate totals for each year
kin_totals_by_year <- kin_allyears2 |>
  group_by(YEAR, RaceEthnicity) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE),
    .groups = 'drop'
  ) |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100
  )

print(kin_totals_by_year)
# A tibble: 12 × 4
    YEAR RaceEthnicity      Total_Kinship Percentage
   <dbl> <chr>                      <dbl>      <dbl>
 1  2021 African-American          46575.      6.35 
 2  2021 Hispanic                 118390.     16.2  
 3  2021 Non-Hispanic Other        14861.      2.03 
 4  2021 White                     79065.     10.8  
 5  2022 African-American          44938.      6.13 
 6  2022 Hispanic                 107275.     14.6  
 7  2022 Non-Hispanic Other         3990.      0.544
 8  2022 White                     54848.      7.48 
 9  2023 African-American          46679.      6.37 
10  2023 Hispanic                 115612.     15.8  
11  2023 Non-Hispanic Other        11729.      1.60 
12  2023 White                     88993.     12.1  
# Calculate the overall total kinship care estimates by year
overall_totals_by_year <- kin_allyears2 |>
  group_by(YEAR) |>
  summarise(
    Overall_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE)
  )

print(overall_totals_by_year)
# A tibble: 3 × 2
   YEAR Overall_Kinship
  <dbl>           <dbl>
1  2021         258891.
2  2022         211051.
3  2023         263013.

By Age & Sex (3 and 1 year)

# Function to calculate CI and reliability flag
calculate_ci_rse_flag <- function(data) {
  data <- data %>%
    mutate(
      RSE = se / in_kinship * 100,
      CI_lower = in_kinship - 1.96 * se,
      CI_upper = in_kinship + 1.96 * se,
      Flag_Unreliable = RSE > 30  # Flag unreliable if RSE > 30%
    )
  return(data)
}


# Survey design specification
des3 <- svydesign(
  ids = ~1,  
  weights = ~ASECWT,  
  data = kin_allyears2
)

# Group by Age categories for all three years - need to divide by three to get average
kin_age_totals <- svyby(
  ~in_kinship,  
  ~cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17")),
  des3, 
  svytotal,
  na.rm = TRUE
)
print(kin_age_totals)
      cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17"))
0-5                                                                      0-5
6-12                                                                    6-12
13-17                                                                  13-17
      in_kinship       se
0-5     116382.5 19574.52
6-12    279853.8 24742.77
13-17   308979.2 25262.96
############################################################all reliable
kin_age_totals <- calculate_ci_rse_flag(kin_age_totals)
print(kin_age_totals)
      cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17"))
0-5                                                                      0-5
6-12                                                                    6-12
13-17                                                                  13-17
      in_kinship       se       RSE CI_lower CI_upper Flag_Unreliable
0-5     116382.5 19574.52 16.819135  78016.4 154748.5           FALSE
6-12    279853.8 24742.77  8.841318 231358.0 328349.6           FALSE
13-17   308979.2 25262.96  8.176267 259463.8 358494.6           FALSE
# Group by Year and Age categories to get yearly estimates
kin_age_totals_by_year <- svyby(
  ~in_kinship,  
  ~interaction(YEAR, cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17"))),
  des3, 
  svytotal,
  na.rm = TRUE
)
print(kin_age_totals_by_year)
           interaction(YEAR, cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17")))
2021.0-5                                                                                    2021.0-5
2022.0-5                                                                                    2022.0-5
2023.0-5                                                                                    2023.0-5
2021.6-12                                                                                  2021.6-12
2022.6-12                                                                                  2022.6-12
2023.6-12                                                                                  2023.6-12
2021.13-17                                                                                2021.13-17
2022.13-17                                                                                2022.13-17
2023.13-17                                                                                2023.13-17
           in_kinship       se
2021.0-5     53227.34 12616.64
2022.0-5     26456.96 10575.21
2023.0-5     36698.16 12169.71
2021.6-12   128449.12 19196.60
2022.6-12    75131.92 14521.90
2023.6-12    76272.78 15548.57
2021.13-17   69857.16 12514.26
2022.13-17  103313.69 19132.31
2023.13-17  135808.35 19251.74
kin_age_totals_by_year <- calculate_ci_rse_flag(kin_age_totals_by_year)
print(kin_age_totals_by_year)
           interaction(YEAR, cut(AGE, breaks = c(0, 5, 12, 18), labels = c("0-5", "6-12", "13-17")))
2021.0-5                                                                                    2021.0-5
2022.0-5                                                                                    2022.0-5
2023.0-5                                                                                    2023.0-5
2021.6-12                                                                                  2021.6-12
2022.6-12                                                                                  2022.6-12
2023.6-12                                                                                  2023.6-12
2021.13-17                                                                                2021.13-17
2022.13-17                                                                                2022.13-17
2023.13-17                                                                                2023.13-17
           in_kinship       se      RSE  CI_lower  CI_upper Flag_Unreliable
2021.0-5     53227.34 12616.64 23.70330 28498.736  77955.95           FALSE
2022.0-5     26456.96 10575.21 39.97138  5729.546  47184.37            TRUE
2023.0-5     36698.16 12169.71 33.16162 12845.537  60550.78            TRUE
2021.6-12   128449.12 19196.60 14.94491 90823.774 166074.46           FALSE
2022.6-12    75131.92 14521.90 19.32854 46668.992 103594.85           FALSE
2023.6-12    76272.78 15548.57 20.38547 45797.587 106747.97           FALSE
2021.13-17   69857.16 12514.26 17.91407 45329.212  94385.12           FALSE
2022.13-17  103313.69 19132.31 18.51866 65814.357 140813.02           FALSE
2023.13-17  135808.35 19251.74 14.17567 98074.939 173541.76           FALSE
# Group by Gender --- 3 year average
kin_gender_totals <- svyby(
  ~in_kinship,  
  ~SEX,  
  des3,
  svytotal,
  na.rm = TRUE
)
print(kin_gender_totals)
  SEX in_kinship       se
1   1   376645.4 27851.04
2   2   356310.2 24898.91
kin_gender_totals <- calculate_ci_rse_flag(kin_gender_totals)
print(kin_gender_totals)
  SEX in_kinship       se      RSE CI_lower CI_upper Flag_Unreliable
1   1   376645.4 27851.04 7.394500 322057.3 431233.4           FALSE
2   2   356310.2 24898.91 6.987986 307508.3 405112.1           FALSE
kin_gender_totals_by_year <- svyby(
  ~in_kinship,  
  ~interaction(YEAR, SEX),  # Grouping by both YEAR and SEX
  des3,
  svytotal,
  na.rm = TRUE
)
print(kin_gender_totals_by_year)
       interaction(YEAR, SEX) in_kinship       se
2021.1                 2021.1   127664.6 17691.07
2022.1                 2022.1   108100.5 19603.94
2023.1                 2023.1   140880.3 21646.26
2021.2                 2021.2   131226.8 18971.82
2022.2                 2022.2   102950.3 17434.11
2023.2                 2023.2   122133.1 17479.79
###############################################################all reliable
kin_gender_totals_by_year <- calculate_ci_rse_flag(kin_gender_totals_by_year)
print(kin_gender_totals_by_year)
       interaction(YEAR, SEX) in_kinship       se      RSE CI_lower CI_upper
2021.1                 2021.1   127664.6 17691.07 13.85746 92990.09 162339.1
2022.1                 2022.1   108100.5 19603.94 18.13492 69676.76 146524.2
2023.1                 2023.1   140880.3 21646.26 15.36500 98453.64 183307.0
2021.2                 2021.2   131226.8 18971.82 14.45727 94042.04 168411.6
2022.2                 2022.2   102950.3 17434.11 16.93449 68779.48 137121.2
2023.2                 2023.2   122133.1 17479.79 14.31209 87872.66 156393.5
       Flag_Unreliable
2021.1           FALSE
2022.1           FALSE
2023.1           FALSE
2021.2           FALSE
2022.2           FALSE
2023.2           FALSE

Poverty

kinpov3 <- kin_allyears2 |>
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 & 
      RELATE %in% c(0901, 0701, 1001, 1260), 
      1, 0
    ),
    below_150_poverty = ifelse(POVERTY %in% c(10, 21, 22), 1, 0)  # 1 if below 150% poverty, 0 otherwise
  )

des_pov <- svydesign(
  ids = ~1,  
  weights = ~ASECWT,  
  data = kinpov3
)

#total number of children in kinship care below 150% of poverty by year
kinpov_totals_by_year <- svyby(
  ~in_kinship,  
  ~interaction(YEAR, below_150_poverty),  # Grouping by YEAR and poverty status (below 150%)
  des_pov,
  svytotal,
  na.rm = TRUE
)
print(kinpov_totals_by_year)
       interaction(YEAR, below_150_poverty) in_kinship       se
2021.0                               2021.0  149544.16 19217.35
2022.0                               2022.0  129312.48 20247.03
2023.0                               2023.0  185522.89 22108.10
2021.1                               2021.1  109347.22 17328.34
2022.1                               2022.1   81738.34 16543.27
2023.1                               2023.1   77490.47 16181.80
###############################################################all reliable
kinpov_totals_by_year11 <- calculate_ci_rse_flag(kinpov_totals_by_year)
print(kinpov_totals_by_year11)
       interaction(YEAR, below_150_poverty) in_kinship       se      RSE
2021.0                               2021.0  149544.16 19217.35 12.85062
2022.0                               2022.0  129312.48 20247.03 15.65745
2023.0                               2023.0  185522.89 22108.10 11.91664
2021.1                               2021.1  109347.22 17328.34 15.84707
2022.1                               2022.1   81738.34 16543.27 20.23930
2023.1                               2023.1   77490.47 16181.80 20.88232
        CI_lower CI_upper Flag_Unreliable
2021.0 111878.16 187210.2           FALSE
2022.0  89628.29 168996.7           FALSE
2023.0 142191.01 228854.8           FALSE
2021.1  75383.68 143310.8           FALSE
2022.1  49313.54 114163.1           FALSE
2023.1  45774.13 109206.8           FALSE
#three-year average of children in kinship care below 150% of poverty
kinpov_totals_average <- svyby(
  ~in_kinship,  
  ~below_150_poverty,  # Grouping only by poverty status for three-year average
  des_pov,
  svytotal,
  na.rm = TRUE
)

# Divide by 3 to get the three-year average
kinpov_totals_average <- kinpov_totals_average |>
  mutate(Average_Three_Years = in_kinship / 3)

print(kinpov_totals_average)
  below_150_poverty in_kinship       se Average_Three_Years
0                 0   464379.5 26042.39           154793.18
1                 1   268576.0 25273.43            89525.34

Poverty and Race/Eth

#total number of children in kinship care below 150% of poverty by race/ethnicity and year
kinpov_totals_by_year_race <- svyby(
  ~in_kinship,  
  ~interaction(YEAR, below_150_poverty, RaceEthnicity),  # Grouping by YEAR, poverty status, and race/ethnicity
  des_pov,
  svytotal,
  na.rm = TRUE
)
print(kinpov_totals_by_year_race)
                          interaction(YEAR, below_150_poverty, RaceEthnicity)
2021.0.African-American                               2021.0.African-American
2022.0.African-American                               2022.0.African-American
2023.0.African-American                               2023.0.African-American
2021.1.African-American                               2021.1.African-American
2022.1.African-American                               2022.1.African-American
2023.1.African-American                               2023.1.African-American
2021.0.Hispanic                                               2021.0.Hispanic
2022.0.Hispanic                                               2022.0.Hispanic
2023.0.Hispanic                                               2023.0.Hispanic
2021.1.Hispanic                                               2021.1.Hispanic
2022.1.Hispanic                                               2022.1.Hispanic
2023.1.Hispanic                                               2023.1.Hispanic
2021.0.Non-Hispanic Other                           2021.0.Non-Hispanic Other
2023.0.Non-Hispanic Other                           2023.0.Non-Hispanic Other
2021.1.Non-Hispanic Other                           2021.1.Non-Hispanic Other
2022.1.Non-Hispanic Other                           2022.1.Non-Hispanic Other
2021.0.White                                                     2021.0.White
2022.0.White                                                     2022.0.White
2023.0.White                                                     2023.0.White
2021.1.White                                                     2021.1.White
2022.1.White                                                     2022.1.White
2023.1.White                                                     2023.1.White
                          in_kinship        se
2021.0.African-American    26737.374  9990.735
2022.0.African-American    41799.550 13273.137
2023.0.African-American    28828.660  9572.632
2021.1.African-American    19837.919  8910.907
2022.1.African-American     3138.620  3138.620
2023.1.African-American    17849.990  9292.084
2021.0.Hispanic            51220.804 12272.252
2022.0.Hispanic            53297.770 12653.187
2023.0.Hispanic            80365.820 13784.132
2021.1.Hispanic            67169.114 13662.670
2022.1.Hispanic            53976.770 14116.590
2023.1.Hispanic            35245.920 10823.270
2021.0.Non-Hispanic Other   8423.981  5001.376
2023.0.Non-Hispanic Other  11729.480  8977.438
2021.1.Non-Hispanic Other   6436.955  4542.161
2022.1.Non-Hispanic Other   3990.500  3990.500
2021.0.White               63162.005 12488.538
2022.0.White               34215.160 10915.743
2023.0.White               64598.930 14873.411
2021.1.White               15903.235  6450.233
2022.1.White               20632.450  7898.523
2023.1.White               24394.560  8621.766
# Calculate Relative Standard Error (RSE) and Confidence Intervals
kinpov_totals_by_year_race <- kinpov_totals_by_year_race %>%
  mutate(
    RSE = (se / in_kinship) * 100,  # Relative Standard Error as a percentage
    CI_lower = in_kinship - 1.96 * se,  # 95% Confidence Interval lower bound
    CI_upper = in_kinship + 1.96 * se,  # 95% Confidence Interval upper bound
    Flag_Unreliable = ifelse(RSE > 30, TRUE, FALSE)  # Flag if RSE > 30%
  )

print(kinpov_totals_by_year_race)
                          interaction(YEAR, below_150_poverty, RaceEthnicity)
2021.0.African-American                               2021.0.African-American
2022.0.African-American                               2022.0.African-American
2023.0.African-American                               2023.0.African-American
2021.1.African-American                               2021.1.African-American
2022.1.African-American                               2022.1.African-American
2023.1.African-American                               2023.1.African-American
2021.0.Hispanic                                               2021.0.Hispanic
2022.0.Hispanic                                               2022.0.Hispanic
2023.0.Hispanic                                               2023.0.Hispanic
2021.1.Hispanic                                               2021.1.Hispanic
2022.1.Hispanic                                               2022.1.Hispanic
2023.1.Hispanic                                               2023.1.Hispanic
2021.0.Non-Hispanic Other                           2021.0.Non-Hispanic Other
2023.0.Non-Hispanic Other                           2023.0.Non-Hispanic Other
2021.1.Non-Hispanic Other                           2021.1.Non-Hispanic Other
2022.1.Non-Hispanic Other                           2022.1.Non-Hispanic Other
2021.0.White                                                     2021.0.White
2022.0.White                                                     2022.0.White
2023.0.White                                                     2023.0.White
2021.1.White                                                     2021.1.White
2022.1.White                                                     2022.1.White
2023.1.White                                                     2023.1.White
                          in_kinship        se       RSE   CI_lower   CI_upper
2021.0.African-American    26737.374  9990.735  37.36618  7155.5344  46319.214
2022.0.African-American    41799.550 13273.137  31.75426 15784.2012  67814.899
2023.0.African-American    28828.660  9572.632  33.20526 10066.3016  47591.018
2021.1.African-American    19837.919  8910.907  44.91856  2372.5409  37303.297
2022.1.African-American     3138.620  3138.620 100.00000 -3013.0752   9290.315
2023.1.African-American    17849.990  9292.084  52.05652  -362.4943  36062.474
2021.0.Hispanic            51220.804 12272.252  23.95951 27167.1903  75274.419
2022.0.Hispanic            53297.770 12653.187  23.74056 28497.5232  78098.017
2023.0.Hispanic            80365.820 13784.132  17.15173 53348.9205 107382.720
2021.1.Hispanic            67169.114 13662.670  20.34070 40390.2811  93947.946
2022.1.Hispanic            53976.770 14116.590  26.15308 26308.2529  81645.287
2023.1.Hispanic            35245.920 10823.270  30.70787 14032.3099  56459.530
2021.0.Non-Hispanic Other   8423.981  5001.376  59.37070 -1378.7168  18226.679
2023.0.Non-Hispanic Other  11729.480  8977.438  76.53739 -5866.2982  29325.258
2021.1.Non-Hispanic Other   6436.955  4542.161  70.56382 -2465.6815  15339.591
2022.1.Non-Hispanic Other   3990.500  3990.500 100.00000 -3830.8800  11811.880
2021.0.White               63162.005 12488.538  19.77223 38684.4699  87639.539
2022.0.White               34215.160 10915.743  31.90323 12820.3042  55610.016
2023.0.White               64598.930 14873.411  23.02424 35447.0452  93750.815
2021.1.White               15903.235  6450.233  40.55925  3260.7782  28545.692
2022.1.White               20632.450  7898.523  38.28204  5151.3451  36113.555
2023.1.White               24394.560  8621.766  35.34299  7495.8985  41293.221
                          Flag_Unreliable
2021.0.African-American              TRUE
2022.0.African-American              TRUE
2023.0.African-American              TRUE
2021.1.African-American              TRUE
2022.1.African-American              TRUE
2023.1.African-American              TRUE
2021.0.Hispanic                     FALSE
2022.0.Hispanic                     FALSE
2023.0.Hispanic                     FALSE
2021.1.Hispanic                     FALSE
2022.1.Hispanic                     FALSE
2023.1.Hispanic                      TRUE
2021.0.Non-Hispanic Other            TRUE
2023.0.Non-Hispanic Other            TRUE
2021.1.Non-Hispanic Other            TRUE
2022.1.Non-Hispanic Other            TRUE
2021.0.White                        FALSE
2022.0.White                         TRUE
2023.0.White                        FALSE
2021.1.White                         TRUE
2022.1.White                         TRUE
2023.1.White                         TRUE
#three-year average of children in kinship care below 150% of poverty by race/ethnicity
kinpov_totals_average_race <- svyby(
  ~in_kinship,  
  ~interaction(below_150_poverty, RaceEthnicity),  # Grouping by poverty status and race/ethnicity for three-year average
  des_pov,
  svytotal,
  na.rm = TRUE
)

kinpov_totals_average_race <- kinpov_totals_average_race |>
  mutate(Average_Three_Years = in_kinship / 3)

print(kinpov_totals_average_race)
                     interaction(below_150_poverty, RaceEthnicity) in_kinship
0.African-American                              0.African-American   97365.58
1.African-American                              1.African-American   40826.53
0.Hispanic                                              0.Hispanic  184884.39
1.Hispanic                                              1.Hispanic  156391.80
0.Non-Hispanic Other                          0.Non-Hispanic Other   20153.46
1.Non-Hispanic Other                          1.Non-Hispanic Other   10427.45
0.White                                                    0.White  161976.09
1.White                                                    1.White   60930.25
                            se Average_Three_Years
0.African-American   18492.013           32455.195
1.African-American   13102.585           13608.843
0.Hispanic           20207.701           61628.131
1.Hispanic           20918.109           52130.601
0.Non-Hispanic Other 10236.609            6717.820
1.Non-Hispanic Other  6028.445            3475.818
0.White              20644.562           53992.032
1.White              12969.486           20310.082
kinpov_totals_average_race1 <- svyby(
  ~in_kinship,  
  ~interaction(below_150_poverty, RaceEthnicity),  # Grouping by poverty status and race/ethnicity for three-year average
  des_pov,
  svytotal,
  na.rm = TRUE
)
kinpov_totals_average_race1 <- kinpov_totals_average_race1 %>%
  mutate(
    Average_Three_Years = in_kinship / 3,
    RSE = (se / in_kinship) * 100,  # Relative Standard Error as a percentage
    CI_lower = in_kinship - 1.96 * se,  # 95% Confidence Interval lower bound
    CI_upper = in_kinship + 1.96 * se,  # 95% Confidence Interval upper bound
    Flag_Unreliable = ifelse(RSE > 30, TRUE, FALSE)  # Flag if RSE > 30%
  )

print(kinpov_totals_average_race1)
                     interaction(below_150_poverty, RaceEthnicity) in_kinship
0.African-American                              0.African-American   97365.58
1.African-American                              1.African-American   40826.53
0.Hispanic                                              0.Hispanic  184884.39
1.Hispanic                                              1.Hispanic  156391.80
0.Non-Hispanic Other                          0.Non-Hispanic Other   20153.46
1.Non-Hispanic Other                          1.Non-Hispanic Other   10427.45
0.White                                                    0.White  161976.09
1.White                                                    1.White   60930.25
                            se Average_Three_Years      RSE     CI_lower
0.African-American   18492.013           32455.195 18.99235  61121.23870
1.African-American   13102.585           13608.843 32.09331  15145.46202
0.Hispanic           20207.701           61628.131 10.92991 145277.30103
1.Hispanic           20918.109           52130.601 13.37545 115392.31027
0.Non-Hispanic Other 10236.609            6717.820 50.79331     89.70719
1.Non-Hispanic Other  6028.445            3475.818 57.81320  -1388.29803
0.White              20644.562           53992.032 12.74544 121512.75258
1.White              12969.486           20310.082 21.28579  35510.05274
                      CI_upper Flag_Unreliable
0.African-American   133609.93           FALSE
1.African-American    66507.60            TRUE
0.Hispanic           224491.49           FALSE
1.Hispanic           197391.30           FALSE
0.Non-Hispanic Other  40217.21            TRUE
1.Non-Hispanic Other  22243.21            TRUE
0.White              202439.44           FALSE
1.White               86350.44           FALSE

3 Yearh Average Kinship by Poverty and Relationship

# Step 2: Group by RELATE to match the categories from the provided table
kin_tot_relate <- kinpov3 |>
  group_by(RELATE) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE),
    Total_Poverty_Kinship = sum(ASECWT * in_kinship * below_150_poverty, na.rm = TRUE),
    .groups = 'drop'
  )

# Calculate the percentages and overall totals for all relationships
kin_tot_relate <- kin_tot_relate |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100,
    Poverty_Percentage = Total_Poverty_Kinship / sum(Total_Poverty_Kinship) * 100
  )

print(kin_tot_relate)
# A tibble: 4 × 5
  RELATE       Total_Kinship Total_Poverty_Kinship Percentage Poverty_Percentage
  <int+lbl>            <dbl>                 <dbl>      <dbl>              <dbl>
1  701 [Sibli…        54621.                29032.       7.45               10.8
2  901 [Grand…       325018.                97185.      44.3                36.2
3 1001 [Other…       176363.                69157.      24.1                25.7
4 1260 [Other…       176954.                73202.      24.1                27.3
# Step 3: Mapping `RELATE` codes to labels for clarity
kin_tot_relate <- kin_tot_relate |>
  mutate(
    Relationship = case_when(
      RELATE == 0901 ~ "Grandchild",
      RELATE == 0701 ~ "Brother/sister",
      RELATE == 1001 ~ "Other relative",
      RELATE == 1260 ~ "Nonrelative without relatives",
      TRUE ~ "Other"
    )
  )

# Print the table with labels
print(kin_tot_relate)
# A tibble: 4 × 6
  RELATE       Total_Kinship Total_Poverty_Kinship Percentage Poverty_Percentage
  <int+lbl>            <dbl>                 <dbl>      <dbl>              <dbl>
1  701 [Sibli…        54621.                29032.       7.45               10.8
2  901 [Grand…       325018.                97185.      44.3                36.2
3 1001 [Other…       176363.                69157.      24.1                25.7
4 1260 [Other…       176954.                73202.      24.1                27.3
# ℹ 1 more variable: Relationship <chr>
# Step 4: Summarize overall totals and percentages for kinship care and poverty status
overall_totals_relate <- kin_tot_relate |>
  summarise(
    Total_Kinship = sum(Total_Kinship),
    Total_Poverty_Kinship = sum(Total_Poverty_Kinship),
    Percentage = sum(Total_Kinship) / sum(Total_Kinship) * 100,
    Poverty_Percentage = sum(Total_Poverty_Kinship) / sum(Total_Poverty_Kinship) * 100
  )

print(overall_totals_relate)
# A tibble: 1 × 4
  Total_Kinship Total_Poverty_Kinship Percentage Poverty_Percentage
          <dbl>                 <dbl>      <dbl>              <dbl>
1       732956.               268576.        100                100
# Step 1: Create a new column for relationship categories based on RELATE
kinpov3 <- kinpov3 |>
  mutate(
    Relationship = case_when(
      RELATE == 0901 ~ "Grandchild",
      RELATE == 0701 ~ "Brother/sister",
      RELATE == 1001 ~ "Other relative",
      RELATE %in% c(1113, 1114, 1115, 1241, 1242) & (MOMLOC != 0 | POPLOC != 0) ~ "Nonrelative with relatives",
      RELATE == 1260 | (RELATE %in% c(1113, 1114, 1115, 1241, 1242) & MOMLOC == 0 & POPLOC == 0) ~ "Nonrelative without relatives",
      TRUE ~ "Other"
    )
  )

# Step 2: Group by YEAR and Relationship to get totals for each year
kin_tot_relate_by_year <- kinpov3 |>
  group_by(YEAR, Relationship) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE),
    Total_Poverty_Kinship = sum(ASECWT * in_kinship * below_150_poverty, na.rm = TRUE),
    .groups = 'drop'
  )

# Calculate the percentages and overall totals for each relationship by year
kin_tot_relate_by_year <- kin_tot_relate_by_year |>
  group_by(YEAR) |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100,
    Poverty_Percentage = Total_Poverty_Kinship / sum(Total_Poverty_Kinship) * 100
  )

# Step 3: Filter the data to include only 2023 for totals by relationship category
kin_tot_relate_2023 <- kin_tot_relate_by_year |>
  filter(YEAR == 2023)

# Print the results for 2023
print(kin_tot_relate_2023)
# A tibble: 4 × 6
# Groups:   YEAR [1]
   YEAR Relationship              Total_Kinship Total_Poverty_Kinship Percentage
  <dbl> <chr>                             <dbl>                 <dbl>      <dbl>
1  2023 Brother/sister                   27579.                20577.       10.5
2  2023 Grandchild                      103832.                26499.       39.5
3  2023 Nonrelative without rela…        66955.                15905.       25.5
4  2023 Other relative                   64647.                14510.       24.6
# ℹ 1 more variable: Poverty_Percentage <dbl>
# Optional: Summarize overall totals and percentages for 2023
overall_totals_relate_2023 <- kin_tot_relate_2023 |>
  summarise(
    Total_Kinship = sum(Total_Kinship),
    Total_Poverty_Kinship = sum(Total_Poverty_Kinship),
    Percentage = sum(Total_Kinship) / sum(Total_Kinship) * 100,
    Poverty_Percentage = sum(Total_Poverty_Kinship) / sum(Total_Poverty_Kinship) * 100
  )

print(overall_totals_relate_2023)
# A tibble: 1 × 5
   YEAR Total_Kinship Total_Poverty_Kinship Percentage Poverty_Percentage
  <dbl>         <dbl>                 <dbl>      <dbl>              <dbl>
1  2023       263013.                77490.        100                100

Redo with the Official poverty variable

library(tidyverse)
library(ipumsr)
library(survey)

ddi6 <- read_ipums_ddi("cps_00066.xml")
kin_o <- read_ipums_micro(ddi6)
Use of data from IPUMS CPS is subject to conditions including that users should cite the data appropriately. Use command `ipums_conditions()` for more details.
kin_offpov <- kin_o |>
  filter(AGE < 18)

kin_offpov2 <- kin_offpov |>
  filter(
    MOMLOC == 0 & POPLOC == 0 &
    RELATE %in% c(0901, 0701, 1001, 1260)
  ) |>
  mutate(
    RaceEthnicity = case_when(
      HISPAN != 0 ~ "Hispanic",
      RACE == 100 & HISPAN == 0 ~ "White",
      RACE == 200 & HISPAN == 0 ~ "African-American",
      RACE != 100 & RACE != 200 & HISPAN == 0 ~ "Non-Hispanic Other"
    )
  )


kin_offpov3 <- kin_offpov2 |>
  mutate(
    in_kinship = ifelse(
      MOMLOC == 0 & POPLOC == 0 & 
      RELATE %in% c(0901, 0701, 1001, 1260), 
      1, 0
    ),
        poverty_status = ifelse(OFFPOV == 1, 1, 0)  # 1 if below poverty line, 0 if above
  )

 
# Step 1: Create a new column for relationship categories based on RELATE
kin_offpov3 <- kin_offpov3 |>
  mutate(
    Relationship = case_when(
      RELATE == 0901 ~ "Grandchild",
      RELATE == 0701 ~ "Brother/sister",
      RELATE == 1001 ~ "Other relative",
      RELATE %in% c(1113, 1114, 1115, 1241, 1242) & (MOMLOC != 0 | POPLOC != 0) ~ "Nonrelative with relatives",
      RELATE == 1260 | (RELATE %in% c(1113, 1114, 1115, 1241, 1242) & MOMLOC == 0 & POPLOC == 0) ~ "Nonrelative without relatives",
      TRUE ~ "Other"
    )
  )

# Step 2: Filter for the year 2023
kin_offpov_2023 <- kin_offpov3 |>
  filter(YEAR == 2023)

# Step 4: Group by Relationship and summarize the totals for children in kinship care by poverty status
kin_tot_relate_2023 <- kin_offpov_2023 |>
  group_by(Relationship) |>
  summarise(
    Total_Kinship = sum(ASECWT * in_kinship, na.rm = TRUE),  # Total children in kinship care
    Below_Poverty_Kinship = sum(ASECWT * in_kinship * poverty_status, na.rm = TRUE),  # Total below poverty
    .groups = 'drop'
  ) |>
  mutate(
    Above_Poverty_Kinship = Total_Kinship - Below_Poverty_Kinship  # Total above poverty
  )

# Step 5: Calculate percentages for each relationship type
kin_tot_relate_2023 <- kin_tot_relate_2023 |>
  mutate(
    Percentage = Total_Kinship / sum(Total_Kinship) * 100,  # Percentage of total kinship care children
    Poverty_Percentage = Below_Poverty_Kinship / Total_Kinship * 100  # Percentage of kinship children below poverty
  )

# Print the results
print(kin_tot_relate_2023)
# A tibble: 4 × 6
  Relationship         Total_Kinship Below_Poverty_Kinship Above_Poverty_Kinship
  <chr>                        <dbl>                 <dbl>                 <dbl>
1 Brother/sister              27579.                16615.                10964.
2 Grandchild                 103832.                 9038.                94794.
3 Nonrelative without…        66955.                15905.                51050.
4 Other relative              64647.                11949.                52699.
# ℹ 2 more variables: Percentage <dbl>, Poverty_Percentage <dbl>