Hello Everyone,

Can anybody please help me to code/program the following situation?

I have three variables which are x1, x2 and x3. These variables have missing values in them. Now I want to generate a new variable x which will basically sum x1, x2 and x3 in the following way:

a. If there is no missing values in an observation of x1, x2 and x3, then x will show the sum of the three variables.

b. If there is only one missing value in either x1 or x2 or x3, then x will average the two existing values and multiplies it by three (Thus I am assuming that the missing value is the average of the two existing values)

c. x will show a missing value (NA) if there are two or three missing values in x1, x2 or x3.

Thank you very much.

Naveed