I have this data:
This is a river basin with 3 countries. The first 4 observations are the whole basin per year with area and rainfall. The remaining observations are combinations of the countries within the basin. I need to fill in the area and rain data throughout the dataset, by country. As you can see, sometimes the country is in c1, sometimes in c2, sometimes in c3. For example, in observation 13, I need to fill area2 and rain2 for BLR, but that data is located in area3 and rain3 in obs 1-11.
I have tried xfill (installed by typing in: net from http://www.sealedenvelope.com/), but get errors. I have also tried this loop, but it says I am specifying too many variables (I think with the * to get all the country and area variables):
I appreciate any insight - I'm really stumped here.
I have also cross-posted this on Stack Overflow.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year str3 c1 float(area1 rain1) str3 c2 float(area2 rain2) str3 c3 float(area3 rain3) 1991 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1992 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1993 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1994 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1995 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1996 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1997 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1998 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1999 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 2000 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 2001 "RUS" 17.83 460.1 "UKR" 57.97 564.7 "BLR" 24.19 618.1 1991 "RUS" . . "UKR" . . "NA" . . 1991 "RUS" . . "BLR" . . "NA" . . 1991 "UKR" . . "BLR" . . "NA" . . 1991 "RUS" . . "BLR" . . "UKR" . . 1992 "RUS" . . "UKR" . . "NA" . . 1992 "RUS" . . "BLR" . . "NA" . . 1992 "UKR" . . "BLR" . . "NA" . . 1992 "RUS" . . "BLR" . . "UKR" . . 1993 "RUS" . . "UKR" . . "NA" . . 1993 "RUS" . . "BLR" . . "NA" . . 1993 "UKR" . . "BLR" . . "NA" . . 1993 "RUS" . . "BLR" . . "UKR" . . end
I have tried xfill (installed by typing in: net from http://www.sealedenvelope.com/), but get errors. I have also tried this loop, but it says I am specifying too many variables (I think with the * to get all the country and area variables):
Code:
levelsof c*, local(lm_country) foreach c in `lm_country' { levelsof area* if c* == `country', local(lm_area) replace area* = `lm_area' if c == `country' }
I have also cross-posted this on Stack Overflow.
Comment