Announcement

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

  • Inserting a new row/s based on the value of another column

    I have a small dataset on job ads in Savannah, GA in 2021.
    I am working with the three variables below:

    ```
    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str41 jobtitle_translated int salary byte job_openings str9 posted_date
    "collection specialist" 6000 6 "6/2/2021"
    "Accountant" 6000 1 "6/2/2021"
    "manager assistant" 6000 1 "6/2/2021"
    "general graphic" 6000 3 "6/2/2021"
    "Director of Human Resources" 6000 1 "6/2/2021"
    "Data entry" 6000 1 "6/2/2021"
    "Public Accountant" 6000 2 "6/2/2021"
    "waiter" 5000 2 "6/2/2021"
    "manager assistant" 5000 2 "6/2/2021"
    "Graphic Design" 5000 1 "6/2/2021"
    "Coffee and tea maker" 5000 5 "6/2/2021"
    "civil engineer" 5000 5 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    ```

    The issue that I am having is that rather than having the dataset organized by job titles, I instead want it to be organized by the number of job openings per job title. Specifically, if there are 10 job openings for "Electrical Engineer" as in the last row above, I want to have 10 rows for "Electrical Engineer" along with the same variables such as a salary of $5000 and date of "6/2/2021".

    For instance, the dataset would like something as below based on the last two rows above, is that possible?
    ```
    jobtitle_translated int salary byte job_openings str9 posted_date
    "civil engineer" 5000 5 "6/2/2021"
    "civil engineer" 5000 5 "6/2/2021"
    "civil engineer" 5000 5 "6/2/2021"
    "civil engineer" 5000 5 "6/2/2021"
    "civil engineer" 5000 5 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    "Electrical Engineer" 5000 10 "6/2/2021"
    ```

  • #2
    Code:
    expand job_openings

    Comment

    Working...
    X