Hi everybody,
I have a dataset for about 200 countries ("id") for the years 1960 to 2013 for different variables. I want to calculate the mean over the years 1980-2005 for one variable (here "data1250") and for each country but only if for country i there is no missing data for the years 1980-2005. If at least one data (i.e. year 1999) is missing, I do not want stata to calculate the mean. I was able to calculate the mean for all data with the following:
bysort id: egen mdata1250 = mean(data1250) if year>=1980 & year<=2005
However, I wasn't able to figure out how to keep stata from calculating the mean if data was missing. Could anybody please help me?
Thank you
I have a dataset for about 200 countries ("id") for the years 1960 to 2013 for different variables. I want to calculate the mean over the years 1980-2005 for one variable (here "data1250") and for each country but only if for country i there is no missing data for the years 1980-2005. If at least one data (i.e. year 1999) is missing, I do not want stata to calculate the mean. I was able to calculate the mean for all data with the following:
bysort id: egen mdata1250 = mean(data1250) if year>=1980 & year<=2005
However, I wasn't able to figure out how to keep stata from calculating the mean if data was missing. Could anybody please help me?
Thank you

Comment