Hello everyone,

I am struggling with filling missing values with mean values, because I have to separate several cases and fill missing values when it is appropriate.

I want to fill missing values (.) if those missing spaces are both blocked with numbers except 0 and -99. Mean value would be the average of those two values, the front one and the back.

If there is either 0 or -99 in either front or back, then missing spaces should be left as it is.

Below is my data form.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte pid int(salary2000 salary2001) byte salary2002 int(salary2003 salary2004 salary2005 salary2006)
1 100   . .   . 250 250 280
2   .   . . 300 450 450 600
3   0   0 0  80  70  80  85
4 150 170 .   .  50 -99 -99
5 -99 -99 0   0 100 180   .
end

The form I want should look like below!


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte pid int(salary2000 salary2001 salary2002 salary2003 salary2004 salary2005 salary2006)
1 100  75  75  75 250 250 280
2   .   .   . 300 450 450 600
3   0   0   0  80  70  80  85
4 150 170 110 110  50 -99 -99
5 -99 -99   0   0 100 180   .
end

I think it is quite complicated, and I really need help!

Thank you very much.

Halim.