I need to create a variable that is the mean of the observations from three other variables. I did this:
gen CPI_foodweight_20142016 = (CPI_foodweight_2014+CPI_foodweight_2015+CPI_foodw eight_2016)/3

However, some of the the values are missing for one or two of these three variables, which leads to a missing value on the varibale I'm creating. I would like to find a way to make Stata calculate the mean with what is available, meaning:
-If there are no missing values, calulate the mean using all three observations
-If one observation is missing, calculate the mean of the two observations that are available
-If two observations are missing, make the observation on the new variabe equal to the observation from the variable that isn't missing

Is there any way I could code for that?