Linear regression in R with if statement [duplicate]
问题 This question already has an answer here : How to run linear model in R with certain data range? (1 answer) Closed 3 years ago . I have a dummy variable black where black==0 is White and black==1 is Black. I am trying to fit a linear model lm for the black==1 category only, however running the code below gives me the incorrect coefficients. Is there a way in R to run a model with the if statement, similar to Stata? library(foreign) df<-read.dta("hw4.dta") attach(df) black[black==0]<-NA model3