As of now, I am a fourth year data science student. As of now, I also have my own company where I work parttime (8/12 hours per week) to gain some more experience in the domain. As you can imagine, I am not as experienced and have some difficulties bringing all theory from my studies together in practice. Now, I am doing a project where I am conducting a time series analysis regarding price elasticity for a brand. They sell a ton of different products on numerous platforms, all with variable prices. All products can be categorised into numerous subcategories. They want me to provide 10-15 insights into the subject of price elasticity (of demand) and their (sub)categories of products. These insights can vary from sales around the holidays to cross price elasticity with their own products.

What data do I have?

Sales Data: Contains records of all transactions, including product details (ID, name, category), sale price, discount applied (if any), quantity sold, date and time of purchase, and the sales channel (website or third-party). Product Information: Detailed information about each product, including unique identifiers, product names, descriptions and category classifications (main and sub-categories).

What have I done so far?

Summary: I have categorised the data into 3 main categories. Then, I calculated the number of sales in a week, a 4-week moving average price and the average price for the categories respectively. I log-difference transformed them (making them stationary, as they showed seasonality around March every year). Then, I calculated the price elasticity by dividing the log-differenced number of sales over the log differenced (moving) average price. I did the same for monthly basis, instead of weekly basis. For all periods in time (weekly and monthly), I can not calculate the price elasticity and therefore gain insights.


This approach seems to give me normal values for price elasticity, but also really large and really small values (think of ±5000). I get this is abnormal. So, I thought there has to be a problem. I think the problem here is that I am trying to measure the difference in sales as it is completely dependent on price changes. However, in reality, this does not have to be the case.

I am wondering what you guys think of this. If my assumption regarding the problem is correct, what do you suggest me looking into to solve it? I do not ask you to solve it for me in any way, I just want a push towards the right direction. Thanks in advance! :)


1 Answer 1


Can I ask what the logic is for dividing the log-differenced number of sales by the log-differenced moving average of price? Not saying the logic is wrong, I just haven't really seen this before. Wouldn't the scale of the elasticity be on the differenced series rather than the original series?

IMO, an easier way would be to use basic linear regression, with a logged response. Maybe fit a model (for the ith observation in the jth category) such as:

$$\text{log(sales}_i) = \beta_0 + \beta_1 \text{time}_i + \beta_2\text{log(price}_i) + \beta_3\text{category}_{ij} + \beta_{4,j} \times\text{log(price}_i)\times\text{category}_{ij} + \epsilon_i. $$

The model above would fit separate elasticities for each product category, where you would be interested in the quantity $\beta_2+ \beta_{4,j}$ from your model. The interpretation of this would be "a one percent change in price yields a $(\beta_2+ \beta_{4,j})$% change in sales for category j, on average (holding all else constant)".

Check for violations in homescedasticity and/or auto correlated residuals by time + product and maybe consider the use of sandwich estimators for standard errors to account for any violations.

Another alternative that is more in line with what you were doing: consider an ARIMAX model, using the exact model above as exogenous regressors (I'd probably drop time as an independent variable in this case though) but model $\epsilon_i$ as an ARIMA process. This would also correct for any kind of auto correlation in your errors. You would conduct inference in the exact same way as described above.

Yet another option is to consider mixed effect models (include a random intercept by product category, but don't include a random slope by product category since you are interested in estimating elasiticities by category). These models will likely be more efficient than the models above, albeit more complicated.

  • $\begingroup$ Hi, thanks for your reply! Log-differencing converts changes to percentages and stabilises the variance. I started doing some SARIMAX modelling. Sadly, I am still stuck but bit-by-bit improving. $\endgroup$
    – Martijn
    Apr 2 at 18:53
  • $\begingroup$ @Martijn The logging converts coefficient changes to percentages and (may) stabilize the variance, but the differencing part is to get rid of possible trends within your time series data, i.e. to deal with autocorrelation. What happens when you use the SARIMAX approach with the log of price as an exogenous regressor and category, regressed against the log of sales? Do you still get results that are unintuitive? $\endgroup$
    – aranglol
    Apr 4 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.