Dear Stata Community,
I have run into a problem with my dataset as it seems that some of my variables are referring to jobs in chronological order whereas others do the reverse. What I am trying to do with the example data below is have the first instance of hrp refer to the last instance of tenure. My data are referring to jobs held by various people over the years (so the combination of caseid, year, and jobnumber serves as a unique identifier). The changes should occur within people and years. To illustrate what I mean: For the first instance (caseid=14, year=1979), the data is fine as is. There is one job which is matched with the correct values of tenure and hrp. For the second instance (caseid=14, year=1984), i need the value of hrp (650) to refer to the most recent job, jobnumber=7. In the third case the same needs to happen such that the hrp levels get matched in reverse order to the most recent instances, such that 850 would appear in the last line, the two 650s in the two lines before, and the 400 would be matched with jobnumer=6.
If anybody could offer any help, that would be very much appreciated.
P.S.: The example here only contains information on one person, so as to keep the output manageable, but my data obviously contains more. So the changes are supposed to occur by caseid and year.
I have run into a problem with my dataset as it seems that some of my variables are referring to jobs in chronological order whereas others do the reverse. What I am trying to do with the example data below is have the first instance of hrp refer to the last instance of tenure. My data are referring to jobs held by various people over the years (so the combination of caseid, year, and jobnumber serves as a unique identifier). The changes should occur within people and years. To illustrate what I mean: For the first instance (caseid=14, year=1979), the data is fine as is. There is one job which is matched with the correct values of tenure and hrp. For the second instance (caseid=14, year=1984), i need the value of hrp (650) to refer to the most recent job, jobnumber=7. In the third case the same needs to happen such that the hrp levels get matched in reverse order to the most recent instances, such that 850 would appear in the last line, the two 650s in the two lines before, and the 400 would be matched with jobnumer=6.
If anybody could offer any help, that would be very much appreciated.
P.S.: The example here only contains information on one person, so as to keep the output manageable, but my data obviously contains more. So the changes are supposed to occur by caseid and year.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(caseid year) byte jobnumber int tenure long hrp 14 1979 1 9 237 14 1979 2 . . 14 1979 3 . . 14 1979 4 . . 14 1979 5 . . 14 1979 6 . . 14 1979 7 . . 14 1979 8 . . 14 1979 9 . . 14 1985 1 . 650 14 1985 2 . . 14 1985 3 . . 14 1985 4 . . 14 1985 5 20 . 14 1985 6 73 . 14 1985 7 41 . 14 1985 8 . . 14 1985 9 . . 14 1986 1 . 855 14 1986 2 . 650 14 1986 3 . 650 14 1986 4 . 400 14 1986 5 . . 14 1986 6 87 . 14 1986 7 55 . 14 1986 8 15 . 14 1986 9 14 . end label values tenure vlX0155800
Comment