Skip to contents

This function converts ISCO codes of any digit level to a specified target digit format by appending trailing zeros. This is useful for preparing codes for functions that expect specific digit lengths, such as isco*_to_oep() which expects 4-digit input.

Usage

isco_fill(x, digits = 4, isco_type = NULL)

Arguments

x

A character or numeric vector of ISCO codes

digits

Target number of digits (1, 2, 3, or 4). Default is 4.

isco_type

Optional. Specify "isco08", "isco88", or "isco68" for validation

Value

A character vector of ISCO codes at the specified digit level

Details

The function automatically detects the digit level of input codes and fills them to the target format by appending trailing zeros:

  • 1-digit codes (e.g., "6") become "6000" (for digits=4)

  • 2-digit codes (e.g., "61") become "6100" (for digits=4)

  • 3-digit codes (e.g., "611") become "6110" (for digits=4)

  • Codes already at target length remain unchanged

This follows the same logic as CROSSWALK/ISCOGEN in Stata. Note that this function only expands codes (adds zeros) - to reduce digit levels, use isco*_swap() instead.

See also

repair_isco() for fixing malformed ISCO codes, isco08_swap() for converting between digit levels

Examples

# Fill 1-digit codes to 4-digit (default)
isco_fill(c("1", "2", "6"))  # Returns: c("1000", "2000", "6000")
#>  Filled 1-digit ISCO codes to 4-digit format
#> [1] "1000" "2000" "6000"

# Fill 2-digit codes to 4-digit  
isco_fill(c("11", "21", "61"))  # Returns: c("1100", "2100", "6100")
#>  Filled 2-digit ISCO codes to 4-digit format
#> [1] "1100" "2100" "6100"

# Fill 1-digit codes to 3-digit
isco_fill(c("1", "2", "6"), digits = 3)  # Returns: c("100", "200", "600")
#>  Filled 1-digit ISCO codes to 3-digit format
#> [1] "100" "200" "600"

# Fill 2-digit codes to 3-digit
isco_fill(c("11", "21", "61"), digits = 3)  # Returns: c("110", "210", "610")
#>  Filled 2-digit ISCO codes to 3-digit format
#> [1] "110" "210" "610"

# 4-digit codes unchanged when digits=4
isco_fill(c("1111", "2111", "6111"))  # Returns: unchanged
#> [1] "1111" "2111" "6111"

# Typical workflow for OEP calculation
if (FALSE) { # \dontrun{
library(dplyr)
your_data %>%
  mutate(
    isco08_4digit = isco_fill(isco08_2digit),  # Fill to 4-digit
    oep = isco08_to_oep(isco08_4digit)
  )
} # }