4

I want to run an OLS regression of this type:

lm(S.Educ ~ i.Educ.A + i.Educ.A^2, tsdata)

But the coefficient of i.Educ.A^2 does not shows up. How can I run this regression?

smci
  • 32,567
  • 20
  • 113
  • 146
  • 6
    I believe you are missing a call to `I()` in the formula, like so: `lm(formula = S.Educ ~ i.Educ.A + I(i.Educ.A^2), data = tsdata)`. See `?I` and [this excellent answer](http://stackoverflow.com/questions/24192428/capital-letter-i-in-r-linear-regression/24192745#24192745) for more info. – Jealie Apr 03 '17 at 23:50
  • 3
    Another way to do this would be `lm(S.Educ ~ poly(i.Educ.A, 2, raw = TRUE), tsdata)` In this case `raw = TRUE` is mostly to get the same values you would if you coded it by hand; you'll get the same predictions either way. Another occasionally-useful variation: `lm(S.Educ ~ cbind(i.Educ.A, i.Educ.A ^ 2), tsdata)` – alistaire Apr 03 '17 at 23:53
  • 5
    Please close as duplicate of either [In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)](http://stackoverflow.com/questions/8055508/in-r-formulas-why-do-i-have-to-use-the-i-function-on-power-terms-like-y-i) or [What does the capital letter “I” in R linear regression formula mean?](http://stackoverflow.com/questions/24192428/capital-letter-i-in-r-linear-regression) – smci Apr 03 '17 at 23:55

0 Answers0