0
votes

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.

1
If you want to put X1 times X2 in lm, you should write X1:X2. Note that X1*X2 is shorthand for X1 + X2 + X1:X2. - DanY
Also, in case you like shorter code: lm(y ~ 1 + x) is the same as lm(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

1 Answers

0
votes

You can create a new variable with the ifelse function:

price <- ifelse(INDEX == 1, logRP, logPP)

I am using your index for not being in a promotion. If it is 1,the new variable will take the value of logRP, and if it is 0, it will the value of logPP. In this way the new variable will have the prices you are only interested in and you can use it as an explanatory variable.