Announcement

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

  • Create long data fomat based on conditions

    Hello I have data in the following format fomrat:

    Personid lfs lfs_1 lfs_2
    0203 1 . .
    3333 . 1 0

    note: lfs, lfs_1 and lfs_2 are in different time periods

    I want it to be in the following format:

    Personid Period lfs
    0203 1 1
    3333 2 1
    3333 3 0


    Notice here I want to do 2 things:

    Firstly:
    Generate a column called period. Period =1 if the lfs column is not null. Period= 2 if lfs_1 column is not null. Period=3 if lfs_2 is not null.

    Secondly:
    Given that some indiviuals might have non null values in 2 or more lfs columns (like the person with id=3333). I want my data to be in long format where person id is duplicated (replicated) if a person has observation in multiple time periods.
Working...
X