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?
Related Posts with Calculate mean when values are missing
Define frequency distribution avoiding repetition of a variableI have 3 variables: CompanyID RoundNumber (from 1 to 16) RoundNumber_max (from 1 to 16) For each co…
Data stored with information on several individuals in one row. How to make each individual a unique observation?My data come compactly stored with information on several individuals (familymembers) in one row (ca…
Panel or PoolDear researchers, This might be a simple question, but I just wanted to confirm. If the structure o…
Destringing vars and changing commas to dotsHi all I have some datasets in which Italian notation has been used - this means that commas have …
Multi-variable Pay-Rates Over Time?Hello, let me start off by saying that I've only recently begun my journey to learn & master STA…
Subscribe to:
Post Comments (Atom)
0 Response to Calculate mean when values are missing
Post a Comment