I want to create a new variable with a certain value when two other variables: CountryOfOrigin and CountryOfBirth are identical. I use Variable-Conditional Compute-Multiple.
IF
PAIS_NACIM == PAIS_PROC_DEST THEN
"País de procedencia"I always get the following error
n argument: `LugarNacimiento = ifelse(PAIS_NACIM == PAIS_PROC_DEST,
"País de procedencia", NA)`.
Caused by error in `Ops.factor()`:
! level sets of factors are different
Thank you for any comment.
When I faced a similar issue comparing two factor variables, I realized the key was making sure both were coded in the same format before running the conditional compute. If the variables differ in hidden ways, like trailing spaces or inconsistent labeling, the comparison will fail even if they look identical on the surface. In my case, I had to recode both variables into a consistent set before applying the IF statement, and then it worked perfectly. Interestingly, while solving this, I was multitasking and browsing salvage car options at Autobidmaster burnt cars for sale, which turned out to be super useful.