Announcement

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

  • Calculating unemployment duration in spell data

    I am working with spell data that looks like this:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(persnr_siab nspell) int(erwstat begorig endorig) float(episode_length episode_length_M)
    
    2  1 101 17167 17531 365 11.991786
    2  2 101 17532 17897 366  12.02464
    2  3  11 17953 18205 253  8.312115
    2  4  11 18206 18210   5 .16427104
    2  5  11 18211 18227  17 .55852157
    2  6 101 18251 18262  12  .3942505
    2  7 101 18876 18992 117 3.8439424
    
    end
    format %tdD_m_CY begorig
    format %tdD_m_CY endorig
    label values erwstat erwstat_en
    label def erwstat_en 11 "11 ALG Unemployment benefits", modify
    label def erwstat_en 101 "101 Employees liable to social security without special characteristics", modify
    label var persnr_siab "Individual ID (simplified)" 
    label var nspell "Non-parallel spell counter" 
    label var erwstat "Employment status" 
    label var begorig "Original start date" 
    label var endorig "Original end date" 
    label var episode_length "Length/duration of spell" 
    label var episode_length_M "Monthly length/duration of spell"

    I have to calculate unemployment duration, measured as the difference between the beginning date of unemployment erw == 11 and the beginning date of the immediate next employment spell (erw ==101). In essence, for each unemployment spell, I need to find the duration between the beginning date of that unemployment spell to the beginning date of the next employment spell. In this example, for nspell 3, (mod of 17953 - 18251), for nspell 4 (mod of 18206 - 18251), for spell 5 (mod of 18211 - 18251).

    How do I code this?

  • #2
    Code:
    by persnr_siab (nspell), sort: assert begorig <= endorig & endorig <= begorig[_n+1]
    by persnr_siab (nspell): gen uspell = sum(erwstat != erwstat[_n-1])
    rangestat (min) next = begorig, by(persnr_siab) interval(uspell 1 1)
    by persnr_siab uspell (nspell), sort: gen wanted = next - begorig if erwstat == 11
    drop uspell next
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC.

    Comment


    • #3
      Dear Clyde,

      Thanks so much for the codes to compute the UE duration.

      But on running line 1, stata says the assertion is false, because there are contradictions. It is because some spells are overlapping (endorig > begorig[_n+1]). I need to truncate the overlapping spells so that I can maintain linear continuity. The truncations typically need to be based on only one condition: in two overlapping spells the latter spell is truncated, unless one of those spells happen to be unemployment spells (erw == 11). Erw==11 spells have priority, so any spell overlapping with them (or coinciding completely) would be truncated (or completely removed). So, is there a way to truncate the overlapping spells?

      Comment


      • #4
        I think the following code will do the truncation/deletion you need, if I understand your criteria correctly:
        Code:
        by persnr_siab (nspell begorig), sort: assert begorig[_n+1] >= begorig if _n > 1
        by persnr_siab: replace begorig = endorig[_n-1] + 1 if endorig[_n-1] > begorig & erw != 11 & _n > 1
        by persnr_siab: replace endorig = begorig[_n+1] - 1 if endorig > begorig[_n+1] & erw[_n+1] == 11
        by persnr_siab nspell: drop if endorig < begorig
        Run it before the code in #2.

        Comment

        Working...
        X