Price elasticity of demand measures how much a product’s consumption changes in response to price changes. A good is elastic if a price adjustment results in a significant shift in either supply or demand. If a price adjustment for the goods does not significantly affect demand or supply, it is inelastic. The elasticity of a product is impacted by the accessibility of an alternative. Demand won’t change as the price increases if the product is necessary and there are no suitable alternatives, making it inelastic.
In this chapter, we will learn about the following:
In this case, we will use food truck sales data to analyze the impact of different pricing strategies.
In order to be able to follow the steps in this chapter, you will need to meet the next requirements:
The concept of price elasticity is used when trying to explain the responsiveness of the number of goods sold to proportional increases in price. This is valuable information for managers that need to anticipate how the finance of the company will be affected by price rises and cuts.
Mathematically, it is as follows:
Here, each term represents the following:
Price elasticity is a measure of how sensitive the quantity required is to price, with nearly all goods seeing a fall in demand when prices rise but some seeing a greater decline. Price elasticity determines, while holding all other factors constant, the percentage change in quantity demanded by a 1% rise in price. When the elasticity is -2, the amount demanded decreases by 2% for every 1% increase in price. Outside of certain circumstances, price elasticity is negative. When a good is described as having an elasticity of 2, it almost invariably indicates that the formal definition of that elasticity is -2.
The term more elastic means that the elasticity of a good is greater, regardless of the sign. Two uncommon exceptions to the rule of demand, the Veblen and Giffen goods are two groups of goods with positive elasticity. A good’s demand is considered to be inelastic when its absolute value of elasticity is less than 1, meaning that price changes have a relatively minor impact on the amount demanded. If a good’s demand is more elastic than 1, it is considered to be elastic. A good with an elastic demand of -2 has a drop-in quantity that is twice as great as its price rise, whereas a good with an inelastic demand of -0.5 has a decrease in the quantity that is only half as great as the price increase.
When the price is chosen so that the elasticity is exactly 1, revenue is maximized. The incidence (or “burden”) of a tax on a good can be predicted using the elasticity of the good. To ascertain price elasticity, a variety of research techniques are employed, such as test markets, historical sales data analysis, and conjoint analysis.
The experiment’s initial data source is the sales of a food truck outside of office buildings. It’s vital to review excessive prices because of the pressure on costs. The proprietor of a food truck must be aware of how a price increase affects the store’s demand for hamburgers. In other words, to determine how much the price can be raised, it is critical to understand the price elasticity of demand for the burgers in the store. In actuality, price elasticity measures how much a product’s price influences demand.
We will use the following Python modules in the next example:
import seaborn as sns; sns.set(style="ticks",
data = pd.read_csv('foodcar_data.csv',
data.head()
This results in the next DataFrame, showing the data that contains the transactional data of items sold by a food truck, along with some other external variables:
Figure 5.1: Food truck sales data to be analyzed
The data consists of the following variables:
data.drop(['ITEM_ID'],axis=1).describe()
This results in the following output:
Figure 5.2: Statistical description summary of the data
print(d)
This results in the following output:
Figure 5.3: Products that are being sold
pd.concat([d.SELLER, pd.get_dummies(d.ITEM_NAME)], axis=1).groupby(d.SELLER).sum().reset_index(drop=True)
This results in the following output:
Figure 5.4: Combination of products sold
sns.pairplot(data[['PRICE','QUANTITY']],height=5,aspect=1.2)
This results in the following output:
Figure 5.5: Pair plot of price and quantity
At a simple glance, we can see that there are many superimposed trends in the relationship between price and quantity. We can also see two very distinct groups, one placed in the lower-left quadrant and the other in the upper-right quadrant.
fig = sns.histplot(x='PRICE',data=data,hue='CAT',
palette=['red','blue'])
This results in the following output:
Figure 5.6: Price histogram differentiated by CAT
We can see in the preceding plot that the products that have a CAT value of 2 are more highly priced than the other ones.
sns.pairplot(data[['PRICE','QUANTITY','ITEM_NAME']], hue = 'ITEM_NAME', plot_kws={'alpha':0.1},height=5,aspect=1.2)
This results in the following output:
Figure 5.7: Price, quantity, and item name pair plot
We can see now the differences between the prices of each item in a bit more detail. In this case, the burgers have the highest price, and water is the cheapest (again, reasonable). What is interesting to see is that for the same items, we have different prices, and differences in the number of units being sold.
We can conclude then that is necessary to analyze the price difference by having a clear distinction per item, as we will most likely have different elasticities and optimal prices for each one of them.
fig = sns.histplot(x='ITEM_NAME',data=data,hue='CAT', palette=['red','blue'])
This results in the following output:
Figure 5.8: Histogram of item names per category
From this histogram, we can see that the burger is the only item that belongs to category 0, so that is sold alone. This means that Coke, water, and coffee are all sold in a bundle along with a burger. This is useful information, as it shows us the way the food truck owner sells their products, thus allowing us to think of better ways to price or combine products to be offered to customers.
Figure 5.9: Price versus quality relationship for CAT = 2 items
In the relationship plot shown here, we can see the relationship between price and quality in items that belong to the second category, meaning that all of them were sold as part of a combo. Besides the outliers, which were priced much higher than the rest of the data points, most of the items are within a certain range. Although we are looking at several items at the same time, we can see a certain relationship by realizing that items that were priced lower were sold in greater quantities. Our job will now be to dive into the specifics of these relationships at the item level in order to be able to determine the price that will maximize the revenue.
d['QUANTITY'] = (d['QUANTITY'] - d['QUANTITY'].mean())/((d['QUANTITY'].max() - d['QUANTITY'].min()))
Figure 5.10: Price versus quality relationship over time
It is interesting to see that price reductions have always led to increases in the quantities being sold. In this case, we can see that the biggest price drop was in the first half of 2020, which led to an increase in the quantities being sold. The question that we need to ask is whether the amount of revenue that was lost by this price reduction has been compensated for by an increase in the number of products sold.
Figure 5.11: Correlation between variables
The data shown here gives us an idea of how the variables are correlated. We can see that there is a negative correlation between price versus temperature (people do not fancy a coffee and a burger combo when it is too hot perhaps), positive with a school break (maybe kids also buy products on these days), and a negative relationship with the weekend, which might indicate that the location of the food truck has less traffic during the weekends.
Please take these conclusions with a grain of salt, as we would need to go through a case-by-case analysis by item to corroborate these assumptions, and always remember the maxima that correlation does not imply causation.
Now that we have explored the data to understand the price differences for what would otherwise have seemed like the same items, as well as to understand how this distribution looks, we can try to estimate the demand curve. Knowing the demand curve allows us to establish the relationship between price and quantity sold, and it’s what we will do in the next section.
A demand curve in economics is a graph that depicts the relationship between the price of a specific good and the amount of that good needed at that price. Individual demand curves are used for price-volume interactions between individual consumers, while market-wide demand curves are utilized for all consumers (a market demand curve).
It is generally accepted that the demand curve declines because of the law of demand. For the majority of things, demand declines as price rises. This law does not apply in several peculiar circumstances. These include speculative bubbles, Veblen goods, and Giffen goods, and when prices rise, purchasers are drawn to the products.
Demand curves are used in combination with supply curves to establish an equilibrium price. At this ideal point, both sellers and buyers have achieved a mutual understanding of how valuable a good or service really is, which allows us to produce just enough to satisfy the demand without shortages or excess.
In order to find the demand curve for each one of the items, first, we will isolate the data for each item into a separate data frame:
burger_2752 = data[data['ITEM_ID']==2752].drop(['
Figure 5.12: Burger data
model = ols("QUANTITY ~ PRICE", burger_2752).fit()
price_elasticity))
Figure 5.13: Burger OLS model summary
One of the ways in which we can analyze the model performance is by looking at the regression plots of the intercept and error. These are scatter plots that provide us with a sense of the relationship between dependent and independent variables in linear regression.
Figure 5.14: Burger OLS model partial regression plot
return price_elasticity, model
models = {}
price_elasticity, item_model =
create_model_and_find_elasticity(data[data[
'ITEM_ID']==item_id])
Figure 5.15: Product items elasticities
Now that we have determined the price elasticities for each item, we can simulate the different possible prices and find the point which maximizes revenue.
Once we have established the relationship between the price and the quantity, we can simulate the revenue for each one of the possible prices. To do this, we will find the minimum and maximum price for each item, establish a threshold, create a range of possible prices, and use the stored model to predict the quantity sold. The next step is to determine the total revenue by multiplying the price by quantity. It is important to note that in this kind of analysis, it is always better to look at the revenue rather than the profit because most of the time, we don’t have the data for the cost of each item. We will explore how to do so using the following steps:
test.head()
Figure 5.16: First rows of the predicted revenue for each price
test['QUANTITY'] = (test['QUANTITY']-test['QUANTITY'].mean())/(test['QUANTITY'].max()-test['QUANTITY'].min())
test['REVENUE'] = (test['REVENUE']-test['REVENUE'].mean())/(test['REVENUE'].max()-test['REVENUE'].min())
test.plot(figsize=(12,8),title='Price Elasticity - Item 2752)
Figure 5.17: burger_2752 demand curve
We can see from the demand curve that this item is inelastic, meaning that even if the price goes up, more of this kind of product will continue to sell. To get a better picture, we will repeat the same exercise for a different item.
test['QUANTITY'] = (test['QUANTITY']-test['QUANTITY'].mean())/(test['QUANTITY'].max()-test['QUANTITY'].min())
test['REVENUE'] = (test['REVENUE']-test['REVENUE'].mean())/(test['REVENUE'].max()-test['REVENUE'].min())
test.plot(figsize=(12,8),title='Price Elasticity - Item 3052')
By running the preceding code, we can see that the demand curve is concave, with a negative elasticity, which means that if the price goes up, fewer units will be sold. Although this will create a decrease in revenue due to fewer units being sold, it also means that it will increase due to the higher price.
Figure 5.18: coffee_3052 demand curve
The way in which we can determine the optimal price is quite simple. We just need to find the maximum value in the REVENUE column and find the optimal set of values. We can do this simply by using the NumPy package and the where clause, which will return the values at which the revenue is highest:
def find_optimal_price(data, model,item_id): start_price = data.PRICE.min() - 1 end_price = data.PRICE.max() + 10 test = pd.DataFrame(columns = ["PRICE", "QUANTITY"]) test['PRICE'] = np.arange(start_price, end_price,0.01) test['QUANTITY'] = model.predict(test['PRICE']) test['REVENUE'] = test["PRICE"] * test["QUANTITY"] test['P'] = (test['PRICE']-test['PRICE'].mean())/(test['PRICE'].max()-test['PRICE'].min()) test['Q'] = (test['QUANTITY']-test['QUANTITY'].mean())/(test['QUANTITY'].max()-test['QUANTITY'].min()) test['R'] = (test['REVENUE']-test['REVENUE'].mean())/(test['REVENUE'].max()-test['REVENUE'].min()) test[['P','Q','R']].plot(figsize=(12,8),title='Price Elasticity - Item'+str(item_id)) ind = np.where(test['REVENUE'] == test['REVENUE'].max())[0][0] values_at_max_profit = test.drop(['P','Q','R'],axis=1).iloc[[ind]] values_at_max_profit = {'PRICE':values_at_max_profit['PRICE'].values[0],'QUANTITY':values_at_max_profit['QUANTITY'].values[0],'REVENUE':values_at_max_profit['REVENUE'].values[0]} return values_at_max_profit
optimal_price[item_id] =
find_optimal_price(data[data['ITEM_ID']==item_id],
models[item_id],item_id)
After running this for all of the items in the data, we can determine the parameters that will maximize the revenue for the food truck.
Figure 5.19: item_6249 demand curve
We can see for the other two items left to be analyzed that their elasticity is also negative, implicating that the higher the price, the lower the number of units sold is.
Figure 5.20: item_4273 demand curve
print(item_id,optimal_price[item_id])
Figure 5.21: Optimal parameters for each item
In this way, we can determine the optimal price, regardless of the item’s characteristics, and how much the customers are willing to pay for each item.
In this chapter, we dived into the relationship between the price of an item and the number of items being sold. We studied that different items have different demand curves, which means that in most cases, a higher price leads to the least items being sold, but this is not always the case. The relationship between price and quantity being sold can be modeled using price elasticity, which gives us an idea of how much the number of products being sold will be reduced by a given increase in the price.
We looked into the food truck sales data in order to determine the best price for each one of their items and we discovered that these items have different elasticities and that for each item, we can determine the price, which will maximize the revenue.
In the next chapter, we will focus on improving the way we bundle and recommend products by looking at how to perform a Market Basket analysis to recommend meaningful products that are frequently bought together.