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.
#create dataframe with just household ID and multigen taglinking21<-select(multigen21, HRHHID, HRHHID2.x, HRHHID2.y, CPSID, FAMREL, FAMUNIT, ASECWTH, HSEQ, multigen)linking21<-rename(linking21, HRHHID2= HRHHID2.x)#merge with original dataframe to get this at the individual levelall2021<-merge(linking21, cpsfull21, by="HRHHID")
Warning in merge.data.frame(linking21, cpsfull21, by = "HRHHID"): column name
'HRHHID2.y' is duplicated in the result
#recode household dataframe #relationship to household head#create a variable for adult childrenmultigen23<-multigen23%>% dplyr::mutate(adultchild =case_when(relationship_2=='child'& AGE_2>=25~1, relationship_2=='grandchild'& AGE_2>=25~1, relationship_3=='child'& AGE_3>=25~1, relationship_3=='grandchild'& AGE_3>=25~1, relationship_4=='child'& AGE_4>=25~1, relationship_4=='grandchild'& AGE_4>=25~1, relationship_5=='child'& AGE_5>=25~1, relationship_5=='grandchild'& AGE_5>=25~1, relationship_6=='child'& AGE_6>=25~1, relationship_6=='grandchild'& AGE_6>=25~1, relationship_7=='child'& AGE_7>=25~1, relationship_7=='grandchild'& AGE_7>=25~1, relationship_8=='child'& AGE_8>=25~1, relationship_8=='grandchild'& AGE_8>=25~1, relationship_9=='child'& AGE_9>=25~1, relationship_9=='grandchild'& AGE_9>=25~1, relationship_10=='child'& AGE_10>=25~1, relationship_10=='grandchild'& AGE_10>=25~1, relationship_11=='child'& AGE_11>=25~1, relationship_11=='grandchild'& AGE_11>=25~1, relationship_12=='child'& AGE_12>=25~1, relationship_12=='grandchild'& AGE_12>=25~1, relationship_13=='child'& AGE_13>=25~1, relationship_13=='grandchild'& AGE_13>=25~1, relationship_14=='child'& AGE_14>=25~1, relationship_14=='grandchild'& AGE_14>=25~1, relationship_15=='child'& AGE_15>=25~1, relationship_15=='grandchild'& AGE_15>=25~1,TRUE~0))#create a variable for other relatives living in householdmultigen23<-multigen23%>% dplyr::mutate(adultrelatives =case_when(relationship_2=='other relatives'& AGE_2>=25~1, relationship_2=='other relatives'& AGE_2>=25~1, relationship_3=='other relatives'& AGE_3>=25~1, relationship_3=='other relatives'& AGE_3>=25~1, relationship_4=='other relatives'& AGE_4>=25~1, relationship_4=='other relatives'& AGE_4>=25~1, relationship_5=='other relatives'& AGE_5>=25~1, relationship_5=='other relatives'& AGE_5>=25~1, relationship_6=='other relatives'& AGE_6>=25~1, relationship_6=='other relatives'& AGE_6>=25~1, relationship_7=='other relatives'& AGE_7>=25~1, relationship_7=='other relatives'& AGE_7>=25~1, relationship_8=='other relatives'& AGE_8>=25~1, relationship_8=='other relatives'& AGE_8>=25~1, relationship_9=='other relatives'& AGE_9>=25~1, relationship_9=='other relatives'& AGE_9>=25~1, relationship_10=='other relatives'& AGE_10>=25~1, relationship_10=='other relatives'& AGE_10>=25~1, relationship_11=='other relatives'& AGE_11>=25~1, relationship_11=='other relatives'& AGE_11>=25~1, relationship_12=='other relatives'& AGE_12>=25~1, relationship_12=='other relatives'& AGE_12>=25~1, relationship_13=='other relatives'& AGE_13>=25~1, relationship_13=='other relatives'& AGE_13>=25~1, relationship_14=='other relatives'& AGE_14>=25~1, relationship_14=='other relatives'& AGE_14>=25~1, relationship_15=='other relatives'& AGE_15>=25~1, relationship_15=='other relatives'& AGE_15>=25~1, TRUE~0))#create a variable for whether there is a grandchild in the household regardless if they are an adult or notmultigen23<-multigen23%>% dplyr::mutate(grandchildpresent=case_when( relationship_2=='grandchild'~1, relationship_3=='grandchild'~1, relationship_4=='grandchild'~1, relationship_5=='grandchild'~1, relationship_6=='grandchild'~1, relationship_7=='grandchild'~1, relationship_8=='grandchild'~1, relationship_9=='grandchild'~1, relationship_10=='grandchild'~1, relationship_11=='grandchild'~1, relationship_12=='grandchild'~1, relationship_13=='grandchild'~1, relationship_14=='grandchild'~1, relationship_15=='grandchild'~1,TRUE~0))#create a variable for child present in generalmultigen23<-multigen23%>% dplyr::mutate(childpresent=case_when( relationship_2=='child'~1, relationship_3=='child'~1, relationship_4=='child'~1, relationship_5=='child'~1, relationship_6=='child'~1, relationship_7=='child'~1, relationship_8=='child'~1, relationship_9=='child'~1, relationship_10=='child'~1, relationship_11=='child'~1, relationship_12=='child'~1, relationship_13=='child'~1, relationship_14=='child'~1, relationship_15=='child'~1,TRUE~0))#create a variable for multigenerational householdmultigen23<-multigen23%>% dplyr::mutate(multigen =case_when(adultchild==1~1, POPLOC!=0~1, MOMLOC!=0~1, POPLOC2!=0~1, MOMLOC2!=0~1, adultrelatives==1~1, grandchildpresent==1~1,TRUE~0))#create dichotomous variable for whether a parent, their child and their grandchild live in the same householdmultigen23<-multigen23%>% dplyr::mutate(threegen =case_when(grandchildpresent==1& childpresent==1~1,TRUE~0))
#count of all multigenerational households multigenfilter23<-multigen23%>%filter(multigen==1)agg23<-aggregate(multigenfilter23$ASECWTH, by=list(multigenfilter23$YEAR), FUN=sum)agg23
Group.1 x
1 2023 16767091
16767091/127950630
[1] 0.1310434
#create dataframe with just household ID and multigen taglinking23<-select(multigen23, HRHHID, HRHHID2.x, HRHHID2.y, CPSID, FAMREL, FAMUNIT, ASECWTH, HSEQ, multigen)linking23<-rename(linking23, HRHHID2= HRHHID2.x)#merge with original dataframe to get this at the individual levelall2023<-merge(linking23, cpsfull23, by="HRHHID")
Warning in merge.data.frame(linking23, cpsfull23, by = "HRHHID"): column name
'HRHHID2.y' is duplicated in the result
linking2<-select(multigen23, HRHHID, threegen, multigen)#merge with original dataframe to get this at the individual levellinked<-merge(cpsfull23, linking2, by="HRHHID")#get agg countsthreegen23<-aggregate(linked$ASECWT, by=list(linked$threegen), FUN=sum)threegen23
Group.1 x
1 0 311310551
2 1 11736604
(11736604/(11736604+311310551))
[1] 0.03633093
#create variables for stratified characteristics#AGE: 0-17, 18-24, 25-39, 40-54, 55-64, 65-84, 85+linked<-linked%>%mutate(agegroups =case_when( AGE>=0& AGE <=17~"0-17", AGE>=18& AGE <=24~"18-24", AGE>=25& AGE <=39~"25-39", AGE >=40& AGE <=54~"40-54", AGE >=55& AGE <=64~"55-64,", AGE >=65& AGE <=84~"65-84", AGE >=85~"85+"))#gender: male vs. female#race: non-hispanic white, non-hispanic black, asian non-hispanic, Native American/ Pacific Islanderlinked<-linked%>%mutate(racethnicity =case_when( RACE==100& HISPAN ==000~"Non-Hispanic White", RACE==200& HISPAN ==000~"Non-Hispanic Black", HISPAN>0~"Hispanic", RACE ==651& HISPAN ==000~"Asian", RACE ==652& HISPAN ==000~"American Indian/ Pacific Islander/ Native Hawaiian/ Native Alaskan", RACE ==300& HISPAN ==000~"American Indian/ Pacific Islander/ Native Hawaiian/ Native Alaskan", RACE>=801& RACE<=830~"Multiracial"))#native born vs. foreign bornlinked<-linked %>%mutate(foreignbornstatus=case_when( NATIVITY>1& NATIVITY<=4~"Native born", NATIVITY==5~"Foreign born"))
#generate aggregate counts for individuals living in a household with a parent, child and grandchild presentagegroups23<-aggregate(linked$ASECWT, by=list(linked$threegen, linked$agegroups), FUN=sum)agegroups23
#create dichotomous variable for whether a parent, their child and their grandchild live in the same householdmultigen24<-multigen24%>% dplyr::mutate(threegen =case_when(grandchildpresent==1& childpresent==1~1,TRUE~0))16349808/129008033
[1] 0.1267348
#create dataframe with just household ID and multigen taglinking24<-select(multigen24, HRHHID, HRHHID2.x, HRHHID2.y, CPSID, FAMREL, FAMUNIT, ASECWTH, HSEQ, multigen)linking24<-rename(linking24, HRHHID2= HRHHID2.x)#merge with original dataframe to get this at the individual levelall2024<-merge(linking24, cpsfull24, by="HRHHID")
Warning in merge.data.frame(linking24, cpsfull24, by = "HRHHID"): column name
'HRHHID2.y' is duplicated in the result
#get counts of three genlinking24<-select(multigen24, HRHHID, threegen, multigen)#merge with original dataframe to get this at the individual levellinked24<-merge(cpsfull24, linking24, by="HRHHID")#get agg countsthreegen24<-aggregate(linked24$ASECWT, by=list(linked24$threegen), FUN=sum)threegen24