Hello, I want to calculate/estimate the price elasticity of demand for different products or product categories. It would be great to be guided towards literature or better yet tutorials or packages.
Let's say I've got a dataframe like the following:
library(tibble)
df <- tibble(cafe_id = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3),
timestamp = structure(
c(1596283511, 1596283511, 1596287730, 1596287730, 1596287730,
1596370505, 1596378076, 1596386672, 1596386672, 1596283999,
1596283999, 1596283999, 1596291727, 1596368783, 1596368783,
1596369685, 1596285196, 1596285327, 1596285327, 1596286869,
1596291836, 1596293731, 1596293731, 1596370648, 1596370648),
class = c("POSIXct", "POSIXt"), tzone = "UTC"),
invoice_id = c(1, 1, 2, 2, 2, 3, 4, 5, 5, 1, 1, 1, 2,
3, 3, 4, 1, 2, 2, 3, 4, 5, 5, 6, 6),
item = c("coffee", "latte macchiato", "cake", "cappuchino",
"tea", "coffee", "cake", "espresso", "orange juice",
"tea", "bagel", "espresso", "coffee", "ice cream",
"espresso", "cake", "latte macchiato", "cake",
"cappuchino", "bagel", "espresso", "tea", "cake",
"coffee", "bagel"),
quantity = c(1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 3, 1, 1,
2, 3, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2),
item_price = c(2, 3, 3, 2.5, 2.5, 2, 3, 1.5, 2.6,
2.5, 3, 1.5, 2, 2.3, 1.5, 3, 3, 3,
2.5, 3, 1.5, 2.5, 3, 2, 3),
total = c(2, 3, 6, 5, 2.5, 4, 3, 3, 2.6, 5, 9, 1.5, 2,
4.6, 4.5, 3, 3, 3, 2.5, 3, 3, 2.5, 3, 4, 6))
head(df)
#> # A tibble: 6 x 7
#> cafe_id timestamp invoice_id item quantity item_price total
#> <dbl> <dttm> <dbl> <chr> <dbl> <dbl> <dbl>
#> 1 1 2020-08-01 12:05:11 1 coffee 1 2 2
#> 2 1 2020-08-01 12:05:11 1 latte macchi~ 1 3 3
#> 3 1 2020-08-01 13:15:30 2 cake 2 3 6
#> 4 1 2020-08-01 13:15:30 2 cappuchino 2 2.5 5
#> 5 1 2020-08-01 13:15:30 2 tea 1 2.5 2.5
#> 6 1 2020-08-02 12:15:05 3 coffee 2 2 4
This is the scenario:
I've got several cafés of the same brand (e.g. Starbucks) which offer more or less the same products with the same price. I want to calculate the own and cross price elasticity for hot drinks (coffee, tea, espresso, etc.) as the demand of e.g. normal coffee is probably influenced by the prices of cappuchino, espresso etc.
As I have several cafés offering the same products I want to capture the hierarchical nature of the data with a mixed effects model. I have time series data for around 2 years of operations during which the prices of the products have changed. Now I'm wondering how I would implement such a model (maybe even in the tidymodels framework?). Any help is much appreciated. Thanks a lot.