Announcement

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

  • Splitting episodes & merging

    Hey Stata Community,

    I need to split every job episode according to calendar years (rrdat dataset; monthly data starting from 1900) and then merge to this yearly subepisode the unemployment rate (UE dataset) of this particular year.

    Here are the steps I have done so far:

    gen start = 0
    gen event = tfin != ti

    gen tstart1 = 1900 + tstart/12
    gen tstart2 = int(tstart1)

    gen tfin1 = 1900 + tfin/12
    gen tfin2 = int(tfin1)

    gen duration = tfin2 - tstart2 + 1
    tab duration

    gen newid = _n

    stset duration, f(event) id(newid)
    expand duration
    by newid, sort: replace start = duration[_n - 1] if newid == newid[_n-1]
    by newid, sort: gen year = tstart2[_n-1]+ _n-1 if newid==newid[_n-1]
    replace year = tstart2 if year==.

    However, after I merge the datasets and run stset duration, f(event) id(newid), Stata gives me a probable error.

    Could you please advise what is wrong and how this can be fixed?

    I appreciate any help!
    Attached Files
    Last edited by Sofiya Volvakova; 17 Feb 2023, 17:38.

  • #2
    Sofiya, please see 12.5 of the FAQ (https://www.statalist.org/forums/help). Nearly no one opens attached dta files here, I'd suggest posting code-based data using the command dataex.

    For those who'd like to help but don't want to download the dta files, here is a chunk of the rrdat1 data, followed by the complete UE data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int id byte noj int(tstart tfin) byte sex int(ti tb te tmar) byte(pres presn edu)
     1 1 555 982 1 982 351 555 679 34 -1 17
     2 1 593 638 2 982 357 593 762 22 46 10
     2 2 639 672 2 982 357 593 762 46 46 10
     2 3 673 892 2 982 357 593 762 46 -1 10
     3 1 688 699 2 982 473 688 870 41 41 11
     3 2 700 729 2 982 473 688 870 41 44 11
     3 3 730 741 2 982 473 688 870 44 44 11
     3 4 742 816 2 982 473 688 870 44 44 11
     3 5 817 828 2 982 473 688 870 44 -1 11
     4 1 872 926 2 982 604 872 872 55 -1 13
     5 1 583 650 1 982 377 583 701 44 44 11
     5 2 651 787 1 982 377 583 701 44 44 11
     5 3 788 982 1 982 377 583 701 44 -1 11
     6 1 691 716 1 982 492 691 781 29 47 11
     6 2 728 753 1 982 492 691 781 47 47 11
     6 3 771 846 1 982 492 691 781 47 56 11
     6 4 859 982 1 982 492 691 781 56 -1 11
     7 1 652 704 2 982 476 652 748 21 22  9
     7 2 705 729 2 982 476 652 748 22 22  9
     7 3 730 735 2 982 476 652 748 22 32  9
     7 4 736 750 2 982 476 652 748 32 -1  9
     8 1 838 843 1 982 609 838 881 44 38 11
     8 2 844 891 1 982 609 838 881 38 27 11
     8 3 892 982 1 982 609 838 881 27 -1 11
     9 1 591 601 1 982 377 591 690 41 41 12
     9 2 602 633 1 982 377 591 690 41 41 12
     9 3 634 642 1 982 377 591 690 41 41 12
     9 4 643 982 1 982 377 591 690 41 -1 12
    10 1 580 700 1 982 382 580 824 33 41 11
    10 2 701 842 1 982 382 580 824 41 55 11
    10 3 862 982 1 982 382 580 824 55 -1 11
    11 1 605 631 1 982 361 605 668 44 44 12
    11 2 632 693 1 982 361 605 668 44 44 12
    11 3 694 982 1 982 361 605 668 44 -1 12
    12 1 653 806 1 982 473 653 813 40 40  9
    12 2 807 883 1 982 473 653 813 40 18  9
    12 3 884 911 1 982 473 653 813 18 42  9
    12 4 912 982 1 982 473 653 813 42 -1  9
    end
    UE:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int Year double UE
    1955 4.3
    1956 3.5
    1957 2.9
    1958   3
    1959   2
    1960 1.1
    1961  .6
    1962  .6
    1963  .4
    1964  .4
    1965  .3
    1966  .2
    1967 1.3
    1968 1.5
    1969  .9
    1970  .8
    1971  .9
    1972  .8
    1973  .8
    1974 1.6
    1975 3.6
    1976 3.7
    1977 3.6
    1978 3.5
    1979 3.2
    1980   3
    1981 4.4
    1982 6.1
    1983   8
    1984 7.1
    1985 7.2
    1986 6.4
    1987 6.2
    1988 6.2
    1989 5.6
    1990   5
    end

    Comment

    Working...
    X