reshape_sib_data: Convert respondent-level sibling history data to one row per...

Description Usage Arguments Examples

View source: R/adult-mortality.R

Description

Convert respondent-level sibling history data to one row per sibling

Usage

1
2
3
4
5
6
7
8
9
reshape_sib_data(
  data,
  widevars = grep("^v", names(data), value = TRUE),
  longvars = grep(sibvar_regex, names(data), value = TRUE),
  idvar = "caseid",
  sib_vars = sub("(.*)_.*", "\\1", longvars),
  sib_idvar = "mmidx",
  sibvar_regex = "^mm[idx0-9]"
)

Arguments

data

A dataset as data.frame.

widevars

Character vector of respondent-level variable names to include.

longvars

Character vector of variables corresponding to each sibling.

idvar

Vector of variable names uniquely identifying each respondent.

sib_vars

Vector of same length as longvars giving variable names in long dataset.

sib_idvar

Variable name uniquely identifying each sibling record. Should appear amongst sib_vars.

sibvar_regex

Optionally, a regular expression to identify variable names for longvars from names of data.

Examples

1
2
3
4
5
6
data(zzir)

zzsib <- reshape_sib_data(zzir)
zzsib$death <- factor(zzsib$mm2, c("dead", "alive")) == "dead"
zzsib$sex <- factor(zzsib$mm1, c("female", "male"))  # drop mm2 = 3: "missing"
calc_nqx(zzsib, by=~sex, agegr=seq(15, 50, 5), tips=c(0, 7), dob="mm4", dod="mm8")

mrc-ide/demogsurv documentation built on Nov. 21, 2021, 2:05 p.m.