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]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to