Make session IDs and, optionally, group IDs and participant IDs that span across all data frames created by import_otree(). Information for these IDs is taken from all_apps_wide but can be defined otherwise.

Note: Older versions of oTree may already contain a variable called session_id in their Time data frames. This variable is overwritten by this function!

Important: Combine duplicate data before running this function!

make_ids(
  oTree,
  gmake = FALSE,
  pmake = TRUE,
  from_app = "all_apps_wide",
  from_var = NULL,
  sstart = 1,
  gstart = 1,
  pstart = 1,
  emptyrows = NULL,
  icw = FALSE
)

Arguments

oTree

A list of data frames that were created by import_otree().

gmake

Logical. TRUE if a variable called group_id should be made. If from_var is not NULL, gmake is automatically set to TRUE.

pmake

Logical. TRUE if a variable called participant_id should be made.

from_app

Character. Name of the data frame from which the session, group, and participant information should be taken. All normal app data frames and all_apps_wide are allowed.

from_var

Character. Name of the variable from which the group information should be taken. This argument is only relevant when all_apps_wide is used as from_app and has group information that contradicts each other.

sstart

Integer. The number that serves as a starting point for session IDs.

gstart

Integer. The number that serves as a starting point for group IDs.

pstart

Integer. The number that serves as a starting point for participant IDs.

emptyrows

Character. "no" if the function should stop if there are empty rows in from_app. "yes" if the function should continue to make IDs.

icw

Logical. TRUE if the warning message should be ignored that states that IDs cannot be made because of an oTree bug.

Value

ID variables are made in all_apps_wide, all app data frames, the Time data frame, and the Chats data frame. See list of the additional ID variables in $info$additional_variables.

Examples

# Use package-internal list of oTree data frames
oTree <- gmoTree::oTree

# Make session IDs only
oTree2 <- make_ids(oTree)

# Show new variables
oTree2$all_apps_wide$session_id
#>  [1] 1 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 6

# Make session IDs and group IDs
# Not working with this data set because group ID is not the same in all apps
if (FALSE) {
      oTree2 <- make_ids(oTree, gmake = TRUE)

      # Show new variables
      oTree2$all_apps_wide$session_id
      oTree2$all_apps_wide$group_id
}

# Get IDs from variable "dictator.1.group.id_in_subsession"
# in the data frame "all_apps_wide"
oTree2 <- make_ids(oTree,
                   gmake = TRUE,
                   from_var = "dictator.1.group.id_in_subsession")

# Show new variables
oTree2$all_apps_wide$session_id
#>  [1] 1 1 1 1 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 6
oTree2$all_apps_wide$group_id
#>  [1]  1  1  2  2  3  3  4  4  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13 13
#> [26] 14 14 15 15

# Get IDs from another app than all_apps_wide
oTree2 <- make_ids(oTree, gmake = TRUE, from_app = "dictator")
#> Warning: Data frame "all_apps_wide" has more participants than dictator: 6cim3a5i, 1mn1kzs7, zdki96d6, byxco6zo

# Show new variables
oTree2$all_apps_wide$session_id
#>  [1]  1  1  1  1  1  1  1  1  1  2  2  2  2  3  3  3  3  3  3  4  4  4  4  5  5
#> [26] NA NA NA NA
oTree2$all_apps_wide$group_id
#>  [1]  1  1  2  2  3  3  4  4  5  6  6  7  7  8  8  9  9 10 10 11 11 12 12 13 13
#> [26] NA NA NA NA