# Linear model to account for confounding factors in dataset by using keywords

I have a dataset of home listings, in R. Here is a sample:

City      Price      Term    Size    Bedrooms     Bathrooms    Description

Appleton  3400       12      1150    1            2            Good location
Appleton  3780       12      1600    7            2            Nice area;
Barstow   1400       6       900     3            2            Shady st
Raleigh   3700       12      1400    1            1            Quiet st, *veranda*
Ames      2200       12      1300    3            2            Good location
Ames      3400       12      1150    1            2            Good location, *veranda*


What I would like to do is ascertain which cities have the highest premiums and discounts for verandas. Certainly one way to do this would be to build two datasets: get cities WITHOUT verandas (i.e regular listings), and get cities WITH verandas. I could then get the mean rent per city using aggregate, and calculate the difference in mean between the two datasets.

But, I think there is a better way. The above approach does not take into consideration confounding factors like Size, Bedrooms, Bathrooms, etc. How might I take a multiple regression approach which would look at the impact of "veranda-ness" while controlling for other factors? I still want to answer the question of which cities have highest premiums/discounts, only using a more quantitative, robust approach.

I'm familiar with R's lm function and how to run a regression, but not sure how to extrapolate that to answer the question.

Price ~ City*HasVeranda + Bedrooms + Bathrooms + Size

• What do you mean "search for this"? If you mean how to create the feature, something like my_data$HasVeranda <- grepl('veranda', my_data$Description) may work. – khol Jun 25 '18 at 22:55
• wash.listings.Recode<-mutate(wash.listings, Check=ifelse(wash.listings$ListingDescription == grepl('Veranda', wash.listings$ListingDescription, ignore.case=TRUE), 'Veranda','NonVeranda')) – DiamondJoe12 Jun 25 '18 at 23:04