Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • From 6-digit job codes to 2-digit job codes.

    Hello everyone,

    I have one question that I am pretty sure is easy for everyone, but not for me. Below is an example of data. ID is a person's ID, and jobcode_6 is a 6-digit code for an occupation. How can I generate a 2 digit code from a 6-digit code for an occupation? For example, ID 1 and 2 would be under the same job category (i.e., 11), and ID 3 and 5's occupation code is 12, and ID 4 is 13. I have tried the -destring- command, but it fails since jobcode_6 is non-numeric (e.g., 11198X).

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float ID str20 jobcode_6
    1 "112564"
    2 "11198X"
    3 "126783"
    4 "13649Y"
    5 "126112"
    end
    I appreciate your help. Stay safe.

  • #2
    Code:
    gen jobcode_2=substr(jobcode_6,1,2)

    Comment

    Working...
    X