As far as I can tell, both Stata and R have a "predict" function. I'm trying to replicate results that were performed in Stata using R, and the results involve calculating standard deviations of predicted values. Is there a functionality in R, maybe using its "predict" function, that will allow me to do this? I can't seem to replicate the results perfectly. In case it helps, the Stata code does the following:
reg Y X1 X2 if condition
predict resid, r
predict stdf, stdf
The definition of the stdf
argument is:
stdf
calculates the standard error of the forecast, which is the standard error of the point prediction for 1 observation. It is commonly referred to as the standard error of the future or forecast value. By construction, the standard errors produced bystdf
are always larger than those produced bystdp
; see Methods and formulas in [R] predict
And the R code I've been writing is:
fit <- lm(Y ~ X1 + X2, data=df)
new.df <- data.frame(...) # This is a new data frame with my new data period I want to predict in
predict(fit, new.df, se.fit = TRUE)
However, when I convert the standard errors to standard deviations, they don't match the Stata output.
Thanks in advance!