How to estimate missing data? I am running a regression with several independent variables with 32 observations (from 1975 to 2006 and they are yearly data). The issue here is that there does not exist any observation for one of the variables prior to 1980. Consequently, that variable has 5 missing observations (from 1975 to 1979).
Is there any method in R to provide an estimation for these missing values? By the way, the explanatory variable here is "total labor force" and it has a very pronounced trend. Therefore, I know very well that it is statistically very possible to estimate the past values.
 A: x <- 1:30; y <- c(rnorm(25) + 1:25, rep(NA, 5)) #generate data with NAs
df1 <- data.frame(x, y)                         #combine into data frame
lmx <- lm(y~x, data=df1)                        #create model to predict from
ndf <- data.frame(x=1:30)                       #create data to predict to
df1$fit <- predict(lmx, newdata=ndf)            #get predictions
df1$y2 <- with(df1, ifelse(is.na(y) == T, fit, y)) 

The last line creates a new variable in the data frame that has all of the old variables as well as the fitted variables from the regression.
A: It is often a good idea to consider the possible reasons for data being missing, ie mising completely at random, missing at random, missing not at random. Depending on this, methods to estimate missing data may be biased.
A sophisticated way to deal with data missing at random is multiple imputation, which acknowledges that there is uncertainty about the values of the missing quantities. This can be done in R using the MICE package. Here is a reproducible example using the nhanes data that comes with the package:
library(mice)
imp <-mice(nhanes)
fit <-with(imp, lm(bmi~chl+hyp))
fit
summary(pool(fit))
complete(imp)  # returns the data with first imputed values. complete(imp,2) returns 2nd set

A: Another approach would be to use simulation solution like Gibbs Sampling based on statistics on past observations.
I believe there is support for that in R : http://darrenjw.wordpress.com/2011/07/31/faster-gibbs-sampling-mcmc-from-within-r/
