Announcement

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

  • Creating ID group

    Hi,
    I have panel data comprising companies and employees. The companies have existing IDs, but I need to 1) create new 3 digit ID's for the companies starting from 101, 102, etc. and 2)IDs for employees where the first 3 digits are that of the company and then add a unique ID for the employee. Example:

    Company_name Person_name Company_ID Person ID
    xyz Richard 101 10101
    xyz Ann 101 10102

    How can I go about this?

    Thanks








  • #2
    Code:
    by company_name, sort: gen company_id = 1 if _n == 1
    replace company_id = sum(company_id)
    replace company_id = 100 + company_id
    
    by company_id person_name, sort: gen pid = 1 if _n == 1
    by company_id (person_name): replace pid = sum(pid)
    replace pid = 100 + pid
    egen person_id = concat(company_id pid)
    drop pid
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thanks!

      Will keep that in mind Clyde !

      Comment

      Working...
      X