Sub topic 13
Estimating elasticity from data with a log-log regression
This chapter assumes you can compute elasticity from two observations, know that a constant-elasticity demand curve has the form Q = A·P^ε, and can read basic derivatives. You also need to know what a least-squares line is. Earlier chapters computed elasticity from two points. Here you estimate it from many observations.
Why a regression instead of two points
The midpoint formula uses two prices and two quantities. Real data has many observations, and each one carries noise from weather, promotions, and measurement error. A regression uses all of them and gives one estimate plus a measure of its uncertainty.
The log-log form suits this because it makes the slope an elasticity directly. You don't need to convert the slope or evaluate it at a chosen point.
The algebra behind the log-log form
Start with the constant-elasticity demand function:
Q = A · P^ε
Take natural logs of both sides:
ln Q = ln A + ε · ln P
This is a straight line. The variable on the vertical axis is ln Q, the one on the horizontal axis is ln P, the intercept is ln A, and the slope is ε.
The slope equals the elasticity because of how logs and derivatives relate. The derivative of ln Q with respect to ln P is:
d ln Q / d ln P = (dQ / Q) / (dP / P) = (dQ/dP) × (P/Q)
That is the point elasticity formula from the earlier chapter. For this functional form it has the same value at every price, so one slope describes the whole curve.
A first example with exact data
The code below builds data from a demand curve with ε = -1.5 and fits a line to the logs. np.polyfit with degree 1 returns the slope first, then the intercept.
import numpy as np
prices = np.array([2.0, 4.0, 5.0, 8.0, 10.0])
quantities = 200 * prices ** -1.5
slope, intercept = np.polyfit(np.log(prices), np.log(quantities), 1)
print(round(slope, 2)) # -1.5The fit is perfect because the data has no noise. The slope is -1.5, so a 1% price increase is associated with about a 1.5% fall in quantity. Since |ε| > 1, demand is elastic, and a price increase lowers total revenue.
The estimation workflow
The steps are the same whatever software you use.
A realistic example with noise
Real quantities do not sit exactly on the curve. The usual model multiplies the curve by a random factor, so the log of that factor becomes an additive error term:
ln Q = ln A + ε · ln P + u
The next script simulates 200 observations with true ε = -1.5 and error standard deviation 0.1. It fits the line with ordinary least squares and computes the standard error of the slope by hand, so you can see where the uncertainty comes from.
import numpy as np
rng = np.random.default_rng(42)
n = 200
prices = rng.uniform(2, 10, size=n)
noise = rng.normal(0, 0.1, size=n)
quantities = 200 * prices ** -1.5 * np.exp(noise)
y = np.log(quantities)
X = np.column_stack([np.ones(n), np.log(prices)])
beta, *_ = np.linalg.lstsq(X, y, rcond=None)
residuals = y - X @ beta
sigma2 = residuals @ residuals / (n - X.shape[1])
cov = sigma2 * np.linalg.inv(X.T @ X)
se = np.sqrt(np.diag(cov))
elasticity = beta[1]
half_width = 1.96 * se[1]
print(f"elasticity: {elasticity:.2f} +/- {half_width:.2f}")The printed estimate lies close to -1.5, with an interval a few hundredths wide. Change the seed and the estimate shifts slightly. That variation is the sampling uncertainty the standard error describes. If you raise the noise level from 0.1 to 0.5, the interval widens noticeably.
Report the elasticity with its interval, not as a single number. An estimate of -1.5 with an interval of ±0.03 supports a firm conclusion that demand is elastic. An estimate of -1.1 with an interval of ±0.4 does not, because the interval includes -1 (unit elastic) and values in the inelastic range.
Reading the coefficient correctly
The slope is a percentage-to-percentage relationship, and it is exact only for small changes. For larger changes, compute the effect directly from the demand function.
With ε = -1.5, a 10% price rise multiplies price by 1.1. Quantity is multiplied by 1.1^(-1.5), which is about 0.867. Quantity falls by about 13.3%, not the 15% you get by multiplying 10% by 1.5.
elasticity = -1.5
price_factor = 1.10
quantity_factor = price_factor ** elasticity
print(round((quantity_factor - 1) * 100, 1)) # -13.3The intercept is ln A, so A = exp(intercept). When you transform fitted values back to quantities, exp of the predicted log is typically a little too low on average. This is the retransformation bias. The slope you care about is not affected.
Comparing the linear and log-log approaches
| Feature | Linear demand, Q = a + bP | Log-log demand, ln Q = a + ε ln P |
|---|---|---|
| Slope means | Change in quantity per unit of price | Elasticity, in percent per percent |
| Elasticity along the curve | Changes with P (needs P/Q) | Constant |
| Extra step to get elasticity | Evaluate b × (P/Q) at a chosen point | None |
| Handles Q = 0 | Yes | No, ln 0 is undefined |
| Typical use | Local analysis, textbook examples | Estimation over a wide price range |
Neither form is correct by default. The log-log form assumes the elasticity is the same at every price. If your data covers a range where demand clearly bends, for example a very low price versus a very high one, a constant elasticity may be a poor description.
Limitations and common mistakes
Common problems to check for:
- Zero or negative values. You cannot take the log of zero. Dropping zero-sales observations biases the result if the zeros occur at high prices. Count the zeros before you drop them.
- Omitted variables. Income, the prices of substitutes, season, and advertising all shift demand. Add them as regressors, usually in logs, so the price coefficient is not picking up their effects. The coefficient on log income is an income elasticity, by the same logic.
- Mixing units. Changing the unit of price (dollars to cents) changes the intercept but not the slope. A change in units of quantity also leaves the slope unchanged. This is a convenient property, and a useful check that your code is right.
- Extrapolating. An elasticity estimated between prices of 2 and 10 says little about a price of 50.
- Wrong sign. A positive estimated slope usually signals a simultaneity problem or an omitted variable, not a real upward-sloping demand curve.
- Treating one number as universal. An estimate holds for one product, market, and time period. Short-run and long-run elasticities differ, as the determinants chapter explained.
Summary of the method
- Check that price and quantity are positive.
- Take natural logs of both.
- Regress ln Q on ln P, ideally with controls for other demand shifters.
- Read the price slope as the elasticity, and report its standard error.
- Ask whether the price variation you used is independent of demand shifts.
Exercise
A log-log regression of weekly coffee sales on price gives a slope of -0.8 with a standard error of 0.1. (a) Is demand elastic or inelastic? (b) Using an approximate 95% interval of slope ± 1.96 × standard error, can you rule out unit elasticity? (c) If the price rises 5%, what exact percentage change in quantity does the fitted curve imply?
Show answer
(a) |−0.8| < 1, so demand is inelastic. (b) The interval is −0.8 ± 0.196, which runs from about −0.996 to −0.604. It only just excludes −1, so unit elasticity is barely ruled out at this level, and the evidence is weak. (c) Quantity is multiplied by 1.05^(−0.8) = exp(−0.8 × ln 1.05) ≈ exp(−0.03903) ≈ 0.9617, a fall of about 3.8%. The linear approximation gives 4%.
Exercise
A researcher regresses ln(quantity) on ln(price) using monthly data and gets a slope of +0.4. Prices in the data rose mainly during holiday months, when demand was strong. Explain why the sign is positive and name one fix.
Show answer
Holiday demand shifts the demand curve outward, which raises both price and quantity. The data then traces a mix of demand shifts, not movement along one demand curve, so the slope is biased upward and can turn positive. Fixes include adding a holiday indicator or other controls for demand shifters, or using price variation that is unrelated to demand, such as supply-side cost shocks as an instrument.
Exercise
You rescale price from dollars to cents in a log-log regression. What happens to the slope and to the intercept?
Show answer
The slope is unchanged, because ln(100P) = ln 100 + ln P adds only a constant to the regressor. That constant is absorbed by the intercept, which changes by ε × ln 100 (the new intercept is the old one minus ε × ln 100). The elasticity is unit-free, so rescaling price cannot change it.