Sub topic 12
Estimating elasticities from data with log-log regression
Earlier chapters computed elasticities from two observations with the midpoint method. Real data has many observations, noise, and several drivers of demand at once. This chapter shows how a log-log regression turns a data set into estimates of income elasticity and cross-price elasticity.
I assume you can compute a midpoint elasticity, read its sign and size, and understand ceteris paribus reasoning. I also assume you have seen a linear regression, meaning a line fitted to data by least squares. No statistics beyond that is needed.
Why logarithms give elasticities
An elasticity is a ratio of percentage changes. A natural logarithm turns small proportional changes into differences: a change in ln(Q) of 0.01 is about a 1% change in Q. So if you regress ln(Q) on ln(Y), the slope is the change in ln(Q) per unit change in ln(Y). That is the percentage change in quantity per percentage change in income, which is the definition of income elasticity.
The log-log model with income Y, own price P, and the price of a related good P_other is:
ln(Q) = a + b1 ln(P) + b2 ln(Y) + b3 ln(P_other) + e
Each slope is a constant elasticity.
| Coefficient | Variable | Meaning | How to read it |
|---|---|---|---|
| b1 | ln(P) | Own-price elasticity | Usually negative. Below -1 means elastic demand. |
| b2 | ln(Y) | Income elasticity | Negative: inferior. Between 0 and 1: normal necessity. Above 1: luxury. |
| b3 | ln(P_other) | Cross-price elasticity | Positive: substitutes. Negative: complements. Near 0: unrelated. |
| a | intercept | Scale of demand | Carries units and has no elasticity meaning. |
| e | error term | Everything not modeled | Should average zero and be unrelated to the regressors. |
The thresholds in the last column are the same ones used in the chapters on reading the sign and size. Only the way you obtain the number changes.
The simplest case: one driver, exact data
Start with data built to have a known answer. Quantity is 2 times the square root of income, so the true income elasticity is 0.5.
import numpy as np
income = np.array([100, 400, 900, 1600])
quantity = 2 * np.sqrt(income) # 20, 40, 60, 80
# In a log-log regression the slope is the constant elasticity.
slope, intercept = np.polyfit(np.log(income), np.log(quantity), 1)
print(round(slope, 2)) # 0.5np.polyfit(x, y, 1) fits a straight line and returns the slope first. Because the data has no noise, the fit is exact. The intercept equals ln(2), which is the log of the constant in the formula.
Check this against the midpoint method between the first two points. Income goes from 100 to 400 and quantity from 20 to 40. The midpoint elasticity is about 0.67/1.2, which is roughly 0.56. This is close to 0.5 but not equal. The midpoint method measures an arc over a large jump, while the regression recovers the exact constant elasticity of the underlying function. For small changes the two agree closely.
A realistic case: several drivers and noise
Demand depends on own price, income, and the related good's price at once. If you leave one out, its effect leaks into the others. The code below simulates 500 households, then estimates all three elasticities together. It uses numpy only, so you can see what regression software does internally.
import numpy as np
rng = np.random.default_rng(42)
n = 500
income = rng.lognormal(mean=10, sigma=0.4, size=n)
price = rng.lognormal(mean=0, sigma=0.2, size=n)
price_other = rng.lognormal(mean=0, sigma=0.2, size=n)
noise = rng.normal(0, 0.05, size=n)
# True elasticities: own price -1.2, income 0.8, cross price 0.4
ln_q = 2.0 - 1.2 * np.log(price) + 0.8 * np.log(income) \
+ 0.4 * np.log(price_other) + noise
X = np.column_stack([
np.ones(n),
np.log(price),
np.log(income),
np.log(price_other),
])
beta, *_ = np.linalg.lstsq(X, ln_q, rcond=None)
# Standard errors from the usual least-squares formula
resid = ln_q - X @ beta
k = X.shape[1]
sigma2 = resid @ resid / (n - k)
se = np.sqrt(np.diag(sigma2 * np.linalg.inv(X.T @ X)))
names = ["intercept", "own price", "income", "cross price"]
for name, b, s in zip(names, beta, se):
print(f"{name:12s} estimate {b: .3f} se {s:.3f}")The estimates land near -1.2, 0.8, and 0.4, and each is within a few standard errors of the truth. An approximate 95% confidence interval for an elasticity is the estimate plus or minus two standard errors. Report the interval, not only the point estimate. An income elasticity of 1.1 with a standard error of 0.3 cannot be told apart from a necessity at 0.9.
The workflow has a fixed order, shown below.
Preparing the data
Careful data preparation matters more than the regression command.
- Deflate money values. Prices and income must be in real terms, meaning adjusted by a price index. With nominal values, general inflation pushes all prices and incomes up together and distorts the estimates. Quantity should be a physical or real-spending measure, not nominal spending.
- Handle zeros. The log of 0 is undefined. A household that buys none of a good cannot enter this model as is. Dropping those rows biases estimates toward people who buy the good. Models designed for zeros, such as Tobit or two-part models, exist for this case.
- Choose the income measure. Current income is volatile, so consumers adjust spending to expected long-run income. Total expenditure is a common stand-in for permanent income in household surveys. State which you used, because the elasticities differ.
- Pick the related good deliberately. A cross-price elasticity only makes sense against a named good. Which substitute or complement to include is a judgment about the market, not something the regression decides.
Cross-section and time series
The same model fits different kinds of data, but they answer different questions.
- Cross-section data compares many households at one time, such as a household budget survey. Income varies a lot across households, so cross-sections suit income elasticity. Prices barely vary within one market and one period, so they suit own-price and cross-price elasticities poorly.
- Time-series data follows one market over months or years. Prices vary over time, so it can identify price elasticities. But trends in income, tastes, and population move together, which makes separating them hard.
- Panel data follows many units over time. It offers the most variation, and you can add unit effects to control for fixed differences between households or regions.
What can go wrong
Common errors, in rough order of how often they occur:
- Omitted variables. Leaving out a substitute's price pushes its effect into whichever included variable correlates with it. Include the plausible related prices, or at least state what you left out.
- Multicollinearity. Prices of related goods and incomes often move together. The coefficients stay unbiased, but standard errors become large and estimates swing between samples. Wide intervals are the symptom.
- Constant elasticity assumed. The log-log form forces the same elasticity at every income level. In reality a good can be a luxury at low income and a necessity at high income. A test is to add a squared ln(Y) term. If it is significant, the elasticity changes with income, and you should report it at specific income levels.
- Reading association as cause. A coefficient of 0.4 on a related price describes how quantity and price moved together in your sample. It is a causal effect only under the assumptions above.
- Extrapolating. An estimate from incomes between 20,000 and 80,000 says little about incomes of 500,000.
- Retransformation. If you predict Q from a log model, exponentiating the predicted ln(Q) understates the average quantity because of the error term. For forecasting, apply a correction such as multiplying by exp(sigma2/2) under normal errors, or use a method that models Q directly.
Comparing with the midpoint method
| Feature | Midpoint method | Log-log regression |
|---|---|---|
| Data needed | Two observations | Many observations |
| Result | Arc elasticity over a range | Constant elasticity across the sample |
| Controls for other variables | Only by assumption | Yes, by including them |
| Uncertainty | Not measured | Standard errors and intervals |
| Main risk | One pair may be unrepresentative | Wrong functional form or omitted variables |
Use the midpoint method for a quick check or a teaching example. Use regression when you have data and need to separate the influences on demand, and compare the two as a sanity check.
Exercise
A log-log regression of quantity of train tickets on income, ticket price, and the price of bus fares gives these estimates: income 0.35 (se 0.10), ticket price -0.9 (se 0.15), bus fare 0.6 (se 0.20). Classify train travel by income, and classify buses relative to trains. Which estimate is least precise relative to its size, and what range would you report for it?
Show answer
The income elasticity of 0.35 lies between 0 and 1, so train travel is a normal good and a necessity. The positive cross-price elasticity of 0.6 means buses and trains are substitutes: a 10% rise in bus fares is associated with about a 6% rise in train ticket demand. The bus fare estimate has the largest standard error relative to its size (0.20/0.6, about one third). An approximate 95% interval is 0.6 plus or minus 0.4, so from about 0.2 to 1.0. The data supports a substitute relationship, but not a precise strength.
Exercise
Write Python that checks whether a good's income elasticity changes with income. Using arrays income and quantity, fit ln(Q) on ln(Y) and its square, and print the income elasticity at the income level 1,000 and at 100,000. Then explain how you would read the result.
Show answer
Code: import numpy as np def elasticityat(income, quantity, y): ly = np.log(income) c2, c1, c0 = np.polyfit(ly, np.log(quantity), 2) return c1 + 2 c2 np.log(y) print(elasticityat(income, quantity, 1000)) print(elasticity_at(income, quantity, 100000)) With ln(Q) = c0 + c1 ln(Y) + c2 (ln Y)^2, the derivative with respect to ln(Y) is c1 + 2 c2 ln(Y), which is the elasticity at income Y. If c2 is near zero, the two printed values will be similar and the constant-elasticity model is adequate. If the value at 1,000 is above 1 and the value at 100,000 is below 1, the good behaves as a luxury for poorer households and a necessity for richer ones.