[R] Creating unique code

Hannah Van Impe h@nn@hv@n|mpe @end|ng |rom out|ook@com
Tue Oct 27 13:57:46 CET 2020


Hello,

I need some help in creating a new variable. I need to create a 'couple identifier', which gives a unique code for every couple/triple/... in a household. So, I can identify couples. To do this, I should use 4 variables:

  *   SERIAL = a unique numeric code for each household
  *   PERNUM = a unique numeric code for each person
  *   SPLOC = the numeric code of the spouse in the household, it is equal to the PERNUM code of the spouse
  *   SPRULE = rules for linking a spouse, numeric code from 00 to 06


To create the couple identifier, I need these conditions:

  *   SERIAL needs to be equal for these persons in the couples
  *   SPLOC > 0
  *   SPLOC = PERNUM
  *   SPRULE = 01 or 02

What I already did is this:

attach(ipumsi_00008_dta)
library(tinytex)
library(dplyr)
library(ggplot2)
library(tidyr)
library(knitr)
library(forcats)
library(mice)
library(pander)
library(ggcorrplot)
library(lubridate)
# true/false code when sploc is greater than zero
ipumsi_00008_dta <- mutate(ipumsi_00008_dta, sploc_greater_than_zero = sploc>0)
# true/false code when sploc is greater then zero and sprule is equal to 1 or 2
ipumsi_00008_dta <- mutate(ipumsi_00008_dta, rule_union = sploc>0 & sprule==1 | sprule==2)

=> Now I want to create a numeric code for true values of rule_union when serials are equal, so when they are persons of the same household.
What method should I use to do this?

Thank you very much!!

	[[alternative HTML version deleted]]



More information about the R-help mailing list