tt_make: Create a translation table from a config file or existing...

Description Usage Arguments Details Note Author(s) Examples

View source: R/tt_make.R

Description

This function is designed to facilitate batch processing of translation tables. It takes as input either a new_mnemonic type config file, or a translation table skeleton in the user's working directory.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
tt_make(
  config,
  new_variable,
  merge = F,
  unit,
  trackingSheet,
  univ_cases,
  dds,
  write = T,
  open_on_write = F
)

Arguments

config

Optional: A tibble object created by config_make or imported from CSV. If no config file is provided and merge == F, the function will search for a skeleton Translation Table in the user's working directory. An error will result if no config file is provided and merge == T.

new_variable

Character: An integrated variable name.

merge

Logical: Defaults FALSE. If TRUE, new mnemonic will be merged into an existing Translation Table with the variable name stored in the "new_variable" column of the config file. An error will result if no such Translation Table can be found.

unit

Optional character: If "hhf" or "sdp" are provided, output codes and labels specific to these units of analysis will be generated. If not provided, the input values (usually -6) with the label "FILL IN LABEL" will be generated as a placeholder for manual input.

trackingSheet

Optional: a tibble object created by tracking_get. If provided, the variable name and label will be imported and used in the new translation table. If univ_cases is not provided, any universe information in trackingSheet will also be imported.

univ_cases

Optional: An expression using the function "case_when" or "if_else" specifying the universe logic for new samples (see article).

write

Logical: defaults TRUE. If FALSE, the translation table will be returned as a tibble and not written.

open_on_write

Logical: defaults FALSE. If TRUE, the new translation table will be opened in Excel.

dds_list

Optional: a list of Data Dictionary objects creeated by dds_list(). If not provided, dds_list will be run automatically.

Details

If using a new_mnemonic type config file, the user may also use the function to update an existing translation table with a new sample; note, however, that this function is not to be used with a new_sample_updates type config file (see tt_update).This functionality is intended for the special case in which one or more variables for a new sample were identified as "new" (by config_make or a similar function), and were later discovered to contain information matching an existing integrated variable (e.g. the new sample incorporated a new name for a variable that had appeared in older samples). In this case, the user may set the argument "merge = TRUE"; a copy of the existing translation table will be written as output with the new sample appended.

Note

Users should note that additional functions for translation tables can be accessed via py$TranslationTable() (see py). Consult ipums-metadata library documentation for a complete list of available functions.

Author(s)

Matt Gunther

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
## Not run: 
# Fill a skeleton with frequencies from new sample data dictionaries
tt_make(
  config = read_csv("Z:/pma/variables/tt_work/Matt/in_progress/et2019a_hh_Matt.csv"),
  new_variable = "aborev",
  unit = "hhf"
)

# Fill a skeleton with frequences and metadata from tracking sheet
tracking <- tracking_get("hhf", "new")
tt_make(
  config = read_csv("Z:/pma/variables/tt_work/Matt/in_progress/et2019a_hh_Matt.csv"),
  new_variable = "aborev",
  unit = "hhf",
  trackingSheet = tracking
)

# Fill frequencies, use tracking sheet, and write universe logic
tracking <- tracking_get("hhf", "new")
tt_make(
  config = read_csv("Z:/pma/variables/tt_work/Matt/in_progress/et2019a_hh_Matt.csv"),
  new_variable = "aborev",
  unit = "hhf",
  trackingSheet = tracking,
  univ_cases = case_when(sample == "et2018a_hh" ~ "Women aged 15-49")
)

# Fill frequencies, use tracking sheet, write universe, and merge to an old TT
# Note: If the provided universe matches an existing sample's, they will be merged
tracking <- tracking_get("hhf", "new")
tt_make(
  config = read_csv("Z:/pma/variables/tt_work/Matt/in_progress/et2019a_hh_Matt.csv"),
  new_variable = "aborev",
  unit = "hhf",
  trackingSheet = tracking,
  univ_cases = case_when(sample == "et2018a_hh" ~ "Women aged 15-49"),
  merge = TRUE
)

## End(Not run)

mgunther87/ipumsPMA documentation built on Aug. 1, 2020, 12:22 a.m.