I want to fit a regression where the outcome is sales units and the predictors are the log prices. I want to calculate elasticities.
However I have 2 variables, one is regular price and another promotion price. And I would like to have 2 distinct elasticities. However in my dataset both prices are always present, I mean, when the product is not in promotion the regular price is equal the promo price. When its in promotion the promo price is lower.
I tried few ways of calculating it, using indicator variables.
1. I created an index that is 1 when the product is not in discount and 0 when it is.
lm(logSales ~ 1 + logRP:I(INDEX==1) + logPP:I(INDEX!=1) ...)
logRP:I(INDEX == 1)FALSE -1.45618 0.06189 -23.53 <2e-16 ***
logRP:I(INDEX == 1)TRUE -2.24568 0.08454 -26.56 <2e-16 ***
logPP:I(INDEX != 1)FALSE -2.18178 0.01997 -109.27 <2e-16 ***
logPP:I(INDEX != 1)TRUE -1.85235 0.01646 -112.50 <2e-16 ***
However it seems this is not a correct solution as I dont want estimates for when its false.
2. I created dummy variables for both regular and promo prices and used the indicator I.
lm(logSales ~ 1 + I(logRP*RP_Multiplier) + I(logPP*PP_Multiplier)
But here the results make no sense to me at all, I have wrong sign.
3. I tried to simply interact
lm(logSales ~ 1 + logRP*RP_Multiplier + logPP*PP_Multiplier
However I dont want to estimate the coefficients for the multiplier or for the price alone. Anyway, this is not my goal at all.
How can I setup my model to estimate the coefficient ONLY WHEN the observation meets the condition I set? In this case, elasticity would be only computed if the multiplier is 1 for that variable.
lm, you should writeX1:X2. Note thatX1*X2is shorthand forX1 + X2 + X1:X2. - DanYlm(y ~ 1 + x)is the same aslm(y ~ x). R will put the constant in there for you, so the "1+" is not necessary (but it's also not hurting anything). - DanY