This function performs a series of data cleaning and preprocessing steps to ensure the data is suitable for analysis.

CleanData(
  data,
  y,
  d,
  z,
  x_ymodel = NULL,
  x_smodel = NULL,
  ER = ER,
  side = side
)

Arguments

data

A data.frame containing the data to be cleaned.

y

Name of the dependent variable (character; numeric).

d

Name of the treatment received variable (character; numeric 0 or 1).

z

Name of the treatment assigned variable (character; numeric 0 or 1).

x_ymodel

Names of the covariates to include in the Y-model (character vector, optional).

x_smodel

Names of the covariates to include in the S-model (character vector, optional).

Value

A list containing the cleaned dataset and relevant metadata:

  • N: The number of observations after cleaning.

  • P_ymodel The number of covariates in the Y-model after cleaning.

  • P_smodel The number of covariates in the S-model after cleaning.

  • Z The treatment assigned vector (instrument variable).

  • D The treatment received vector (treatment variable).

  • Y The dependent variable vector (outcome variable).

  • X_ymodel The cleaned covariate matrix in the Y-model (including intercept).

  • X_smodel The cleaned covariate matrix in the S-model (including intercept).