Hello everybody,
I have a dataset where some data are missing for the year 2011.
Now I want to replace this missing data (with missing data I mean the "NA" once) with the mean of the 2010 and 2012 values.
For example
2010 --------- 10
2011 --------- "NA"
2012 --------- 14
(so 2011 should be 12)
I tried this in every variation, with and without space, destring... but I get the error code 109 (mostly).
The code I tried e.g. is
replace revenue = (revenue[_n-1]+revenue[_n+1])/2 if revenue=="NA"&year==2011
even this does not work and the restriction that this should only happen if 2010 and 2012 have no "NA" in their data
(should be something like this but does not work revenue[_n-1]>="."&year==2010 & revenue[_n+1]>="."&year==2012
I am very grateful for any advice!
I have a dataset where some data are missing for the year 2011.
Now I want to replace this missing data (with missing data I mean the "NA" once) with the mean of the 2010 and 2012 values.
For example
2010 --------- 10
2011 --------- "NA"
2012 --------- 14
(so 2011 should be 12)
I tried this in every variation, with and without space, destring... but I get the error code 109 (mostly).
The code I tried e.g. is
replace revenue = (revenue[_n-1]+revenue[_n+1])/2 if revenue=="NA"&year==2011
even this does not work and the restriction that this should only happen if 2010 and 2012 have no "NA" in their data
(should be something like this but does not work revenue[_n-1]>="."&year==2010 & revenue[_n+1]>="."&year==2012
I am very grateful for any advice!
Comment