How to analyze logical variables?

Hello guys,
In my psychology survey I had a demographic question about the employment status of my participants. The items were encoded in SoSciServey as 8 logical variables. My question is if there's any command that I can use to make them in one scale.
Highly appreciate your help!
If any question let me know :slight_smile:

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers.

Looks like employment status is a categorical variable with either numeric or character encoding. As a general rule of thumb, when dealing with that kind of variable, you make "dummy" binary variables with values of 1 or 0 when there are 12 or fewer categories and treat them as continuous when not. But that's not set in concrete, so cum grano salis

Somewhere there's a package with a function to do it, but it's easily done with dplyr.

So, let's assume we have Actor, Baker, Carpenter, Dealer, Electrician, Fabulist, Googler, Iridentist and Hogwarder as the occupations, which we have encloded as A ... H.

suppressPackageStartupMessages(library(dplyr))
dat <- structure(list(jobs = structure(c(7L, 6L, 6L, 7L, 3L, 3L, 5L, 1L, 3L, 4L, 2L, 5L, 3L, 6L, 3L, 7L, 8L, 5L, 6L, 7L, 5L, 7L, 2L, 8L, 3L, 5L, 5L, 1L, 2L, 3L, 7L, 7L, 6L, 4L, 7L, 7L, 3L, 7L, 8L, 6L, 5L, 3L, 4L, 8L, 2L, 5L, 8L, 6L, 2L, 5L, 7L, 7L, 5L, 6L, 4L, 8L, 1L, 2L, 8L, 4L, 6L, 3L, 4L, 1L, 1L, 6L, 3L, 8L, 7L, 2L, 2L, 4L, 1L, 4L, 8L, 7L, 1L, 8L, 2L, 6L, 3L, 7L, 7L, 3L, 6L, 2L, 4L, 3L, 1L, 5L, 2L, 5L, 5L, 8L, 6L, 6L, 8L, 1L, 3L, 4L), .Label = c("A", "B", "C", "D", "E", "F", "G", "H"), class = "factor")), row.names = c(NA, -100L), class = "data.frame")

dat %>%  mutate(A = ifelse(jobs == "A", 1, 0)) %>%
         mutate(B = ifelse(jobs == "B", 1, 0)) %>%
         mutate(C = ifelse(jobs == "C", 1, 0)) %>%
         mutate(D = ifelse(jobs == "D", 1, 0)) %>%
         mutate(E = ifelse(jobs == "E", 1, 0)) %>%
         mutate(F = ifelse(jobs == "F", 1, 0)) %>%
         mutate(G = ifelse(jobs == "G", 1, 0)) %>%
         mutate(H = ifelse(jobs == "H", 1, 0)) -> dat

head(dat,20)
#>    jobs A B C D E F G H
#> 1     G 0 0 0 0 0 0 1 0
#> 2     F 0 0 0 0 0 1 0 0
#> 3     F 0 0 0 0 0 1 0 0
#> 4     G 0 0 0 0 0 0 1 0
#> 5     C 0 0 1 0 0 0 0 0
#> 6     C 0 0 1 0 0 0 0 0
#> 7     E 0 0 0 0 1 0 0 0
#> 8     A 1 0 0 0 0 0 0 0
#> 9     C 0 0 1 0 0 0 0 0
#> 10    D 0 0 0 1 0 0 0 0
#> 11    B 0 1 0 0 0 0 0 0
#> 12    E 0 0 0 0 1 0 0 0
#> 13    C 0 0 1 0 0 0 0 0
#> 14    F 0 0 0 0 0 1 0 0
#> 15    C 0 0 1 0 0 0 0 0
#> 16    G 0 0 0 0 0 0 1 0
#> 17    H 0 0 0 0 0 0 0 1
#> 18    E 0 0 0 0 1 0 0 0
#> 19    F 0 0 0 0 0 1 0 0
#> 20    G 0 0 0 0 0 0 1 0

Created on 2020-03-01 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.