R prediction package VS Stata margins
问题 I'm switching from Stata to R, and I find inconsistent results when I use prediction to compute marginal pred and the results from the Stata command margins fixing the values of a variable to x . Here is the example: library(dplyr) library(prediction) d <- data.frame(x1 = factor(c(1,1,1,2,2,2), levels = c(1, 2)), x2 = factor(c(1,2,3,1,2,3), levels = c(1, 2, 3)), x3 = factor(c(1,2,1,2,1,2), levels = c(1, 2)), y = c(3.1, 2.8, 2.5, 4.3, 4.0, 3.5)) m2 <- lm(y ~ x1 + x2 + x3, d) summary(m2) marg2a