library(wooldridge)
library(tidyverse)
library(stargazer)
setwd("C:/Users/Charlie/Desktop/R Homework")
data(wage1)
reg_wage1 <- lm(lwage ~ female + educ + (female * educ), data = wage1)
stargazer(reg_wage1, type = "text")
female_at_zero <- data.frame(female=0)
pred <- predict(reg_wage1, female_at_zero)
stargazer(pred, type = "text")
My problem is when I try to run this code it keeps asking me to put in a value for educ, but I do not want to change education, I only want to see the model's results in stargazer if female is equal to 0.
The issue that you're running into is that you've defined your model reg_wage1
with educ
so it won't know how to make a prediction without an educ
value. lm
has defined the female
variable based on the values of the educ
variable (not to mention the interacted variable you added to the model). If you want to see the effect on lwage
with just female = 0
, you're going to have to redefine your model.
Another option is to simply call female_at_zero <- data.frame(female = 0, educ = 0)
. By setting educ
to 0, you're essentially looking at just the effect of female
. But this solution is redundant because the value of pred
will simply be the value of Constant
from the output of stargazer(reg_wage1, type = "text")
. This is due to the fact that a linear model ( lm
) defines its intercept ( Constant
) as the point at which all independent variables are equal to 0.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.