Announcement

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

  • duration of employment spells by personal id

    Hi!

    I would like to calculate duration of low wage employment (dummy 0/1) for each individual in my data set.
    My data is in long format, every personal identifier is repeated ten times, one for each year. Do any of you have any ideas of how to create a new variable that captures the duration of the spell/ if low wage emplyment lasts for all years in the data set/only a couple of years etc, by personal id? That is for the specific individual.

    best,
    Karin

  • #2
    maybe this is what you want,
    Code:
    bys id (year): gen spell = sum(dummy!=dummy[_n-1])
    bys id spell (year): gen duration = year[_N]-year[1]

    Comment


    • #3
      Thank you! that worked

      Comment


      • #4
        Originally posted by Øyvind Snilsberg View Post
        maybe this is what you want,
        Code:
        bys id (year): gen spell = sum(dummy!=dummy[_n-1])
        bys id spell (year): gen duration = year[_N]-year[1]
        Or actually there is a problem with using this, maybe you can help me to figure out how to alter the code. It calculates the duration of any spell, 1, 0 or missing. Even when I recode the dummy to two different dummies, only containing 1 (for low wage or high wage) and the rest missing, it still calculates the missings as, thus I cannot seperate spells from each other I cannot seperate if it is a low wage or a high wage spell. I need something like bys id (year): gen spell = sum(dummy if dummy=1 !=dummy[_n-1]).

        Best,
        Karin

        Comment


        • #5
          Or I just sorted it with replacing the duration with . if the dummy is . maybe not the finest coding but it got me the information I wanted, thanks again!

          Comment

          Working...
          X