0

I want to generate a new variable in Stata by grouping an old one according to its value characteristics. I have one variable called status that reflects employment type and status, so it has values like "Manager", "Ex-Manager", "Employee", "Ex-Employee".

Now I want to generate a new dummy variable that equals 1 if the person is still employed (contains "Manager" and "Employee") and equals 0 if the person is no longer employed ("Ex-Employee", "Ex-Manager").

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Freyana
  • 61
  • 8
  • Are you referring to a numeric variable with value labels or a string variable, because the answer will vary accordingly. "Value characteristics" could mean either; it's not standard Stata terminology – Nick Cox Feb 09 '22 at 09:37
  • @NickCox status is a string variable – Freyana Feb 09 '22 at 09:48

1 Answers1

1
generate wanted = inlist(status, "Manager", "Employee") if !missing(status) 

will produce an indicator variable that is 1 if status is either of the specified values, 0 if it is another specified value, and missing if status is missing (meaning, an empty string).

See the help for inlist() and FAQs such as

https://www.stata.com/support/faqs/data-management/creating-dummy-variables/

https://www.stata.com/support/faqs/data-management/true-and-false/

Note that the comparison is entirely literal (no incorrect spellings or extra spaces or characters).

Nick Cox
  • 35,529
  • 6
  • 31
  • 47