Dear all,
I am trying to merge two dataset based on a condition (described below) and was wondering whether this would be possible.
First, my dataset "year-state" has two variables, [YEAR] and [STATE]. Therefore a sample of the data might look like:
YEAR STATE (in numeric code)
1943 01
1950 01
1975 01
1944 09
1950 09
1952 22
Second, my dataset "stepdown" has two variables, [STATE], [STEPDOWNYEAR], which includes every instance of leadership change of a country. A sample of data might look like:
STATE STEPDOWNYEAR
01 1942
01 1950
01 1979
01 1983
01 1987
09 1942
09 1957
(so a country can have several instances of leadership change)
For every YEAR-STATE combination in my first dataset, I would like to add a closest STEPDOWNYEAR that happens after the YEAR variable. So, For [STATE 01 in 1943], although possible STEPDOWNYEAR are 1942, 1950, 1979, 1983, 1987, I would only like to keep "1950," which satisfies the requirement.
Is there any suggestions on how to do it?
I am trying to merge two dataset based on a condition (described below) and was wondering whether this would be possible.
First, my dataset "year-state" has two variables, [YEAR] and [STATE]. Therefore a sample of the data might look like:
YEAR STATE (in numeric code)
1943 01
1950 01
1975 01
1944 09
1950 09
1952 22
Second, my dataset "stepdown" has two variables, [STATE], [STEPDOWNYEAR], which includes every instance of leadership change of a country. A sample of data might look like:
STATE STEPDOWNYEAR
01 1942
01 1950
01 1979
01 1983
01 1987
09 1942
09 1957
(so a country can have several instances of leadership change)
For every YEAR-STATE combination in my first dataset, I would like to add a closest STEPDOWNYEAR that happens after the YEAR variable. So, For [STATE 01 in 1943], although possible STEPDOWNYEAR are 1942, 1950, 1979, 1983, 1987, I would only like to keep "1950," which satisfies the requirement.
Is there any suggestions on how to do it?
Comment