Hi All,

I have data that resembles the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year rank country)
1900 1 1
1900 0 2
1901 1 1
1901 0 2
1901 1 3
1901 0 4
1901 1 5
1902 1 1
1902 0 2
1902 1 3
1902 0 4
1902 1 5
1903 . 1
1903 . 2
1903 . 3
1903 . 4
1903 . 5
1904 . 1
1904 . 2
1904 . 3
1904 . 4
1904 . 5
1904 . 6
end

In the above, I have information,by year, on whether a country is below or above the median income (as indicated by a dummy variable that takes the value of 1), and the country code is given by the country variable. What I wish to do is to infact replace all the missing rank values for 1903 onwards (till 2000) by the rank of the country in 1902.

What I wish to do is something like:

Code:
by country (year), sort: replace incomerank=incomerank[value of income rank in 1902] if year<=2000
I am not sure how to call the specific value of the country's rank variable in 1902. Any help on this is much appreciated.


Best,
CS