identify_inconsistent: Identify participants who provided inconsistent answers in...

View source: R/identify_inconsistent.r

identify_inconsistentR Documentation

Identify participants who provided inconsistent answers in panel studies

Description

When conducting a panel study, we often want to know whether the same person has answered at all waves. One way of investigating this is to check whether people provided consistent birthdates or gender across several waves. This function allows to check the consistency in answers between up to three variables. It returns a vector with the consistent values. Participants with inconsistent answers receive the number -99 which can in turn be used to subset the overall data set.

Usage

identify_inconsistent(..., na.rm = FALSE)

Arguments

...

The variables that should be evaluated (up to three).

na.rm

Should people with missings in one of the variables be excluded (i.e., receive the value "-99")? If not (the default), the remaining variables will be checked for consistency.

Value

A vector in which participants with consistent answers receive the matching value and participants with inconsistent answers recevied a "-99".

Examples

# Create example data
(data <- data.frame(x1 = c(1,2,NA), x2 = c(1,2,3)))

# Create new variable with consistent answers
data$x <- identify_inconsistent(x1, x2, na.rm = T)

# Check
data

# Subset data based on function's output
subset(data, x != -99)

masurp/pmmisc documentation built on May 3, 2024, 7:13 p.m.