create_lagged_cov: Create lagged choice covariates

View source: R/data_management.R

create_lagged_covR Documentation

Create lagged choice covariates

Description

This function creates lagged choice covariates from the data.frame choice_data, which is assumed to be sorted by the choice occasions.

Usage

create_lagged_cov(choice_data, column, k = 1, id = "id")

Arguments

choice_data

A data.frame of choice data in wide format, i.e. each row represents one choice occasion.

column

A character, the column name in choice_data, i.e. the covariate name. Can be a vector.

k

A positive number, the number of lags (in units of observations), see the details. Can be a vector. The default is k = 1.

id

A character, the name of the column in choice_data that contains unique identifier for each decision maker. The default is "id".

Details

Say that choice_data contains the column column. Then, the function call

create_lagged_cov(choice_data, column, k, id)

returns the input choice_data which includes a new column named column.k. This column contains for each decider (based on id) and each choice occasion the covariate faced before k choice occasions. If this data point is not available, it is set to NA. In particular, the first k values of column.k will be NA (initial condition problem).

Value

The input choice_data with the additional columns named column.k for each element column and each number k containing the lagged covariates.


RprobitB documentation built on May 29, 2024, 7:59 a.m.