Day 23. Derivatives, Partial Derivatives & Taylor Series
Rates of change, marginal effects and elasticities, and local polynomial approximations of any smooth function.
- ●Differentiate with the product, quotient and chain rules and compute partial derivatives.
- ●Compute marginal effects and elasticities in linear, log and non-linear models.
- ●Build first- and second-order Taylor approximations in one and several variables.
- ●Explain the log-point approximation and when it breaks down.
Theory
The derivative
is the instantaneous rate of change: the slope of the tangent line. Rules you need:
| Rule | Formula |
|---|---|
| Power | |
| Exponential, log | , |
| Product | |
| Quotient | |
| Chain |
Partial derivatives and the gradient
For , the partial derivative holds every other variable fixed: ceteris paribus in symbols. The gradient stacks the partials; the Hessian collects the second partials (symmetric for smooth ).
Marginal effects and elasticities
- Marginal effect: . In a linear model it is ; with interactions or non-linear links it depends on .
- Elasticity: .
- Semi-elasticity: , the coefficient in a log-level regression.
Taylor series
Near a point ,
and in several variables
The first-order term is the delta method (Day 12); the second-order term is the curvature that Newton's method (Day 25) and Fisher information (Day 11) use. The famous log-point approximation is the first-order expansion , good when is small.
Part 1 · Warm-up
Exercise 1 · A polynomial
Differentiate .
Show solution
.
Exercise 2 · Chain rule
Differentiate and .
Show solution
and .
Exercise 3 · Partial derivatives
For , find , and the Hessian.
Show solution
, . (note ).
Exercise 4 · A constant elasticity
Demand is . Find the price elasticity.
Show solution
Step 1. Take logs: .
Step 2. Elasticity .
Answer: −1.5 at every price: a 1% price rise cuts quantity demanded by 1.5%.
Exercise 5 · A logit marginal effect
In a logit, with . If and the predicted probability is 0.3, what is the marginal effect of ?
Show solution
Step 1. Chain rule: .
Step 2. At : .
Answer: about 17 percentage points per unit of at this point; at it would be .
Part 2 · Proofs
Exercise 6 · The product rule
Prove from the definition.
Show solution
. Divide by and let ; continuity of gives , so the limit is .
Exercise 7 · The derivative of the log
Using and the chain rule, prove .
Show solution
Differentiate both sides: , so .
Exercise 8 · The error of a linear approximation
Show that if is bounded by near , the first-order approximation error is at most .
Show solution
Step 1. Taylor's theorem with remainder: for some between and .
Step 2. So the error is .
Step 3. It shrinks quadratically: halve the distance, quarter the error.
Exercise 9 · Cobb–Douglas and Euler's theorem
For , show and .
Show solution
Step 1. , so the elasticity is .
Step 2. Then and , so : with constant returns, paying factors their marginal products exhausts output.
Exercise 10 · Second-order Taylor of the log
Derive the second-order Taylor expansion of at 0 and evaluate it at .
Show solution
Step 1. Derivatives of : , .
Step 2. At 0: , , .
Step 3. Second-order expansion: .
Step 4. At : , versus the true .
Answer: ; error 0.0003 at , against 0.005 for the first-order .
Part 3 · Applied
Exercise 11 · Log points versus percent
A log-wage regression gives a training coefficient of 0.25. What percentage effect is that, and how wrong is the "25%" reading?
Show solution
Step 1. A log-point coefficient means wages are multiplied by .
Step 2. .
Answer: 28.4%, not 25%. The approximation understates large positive effects; below about 0.1 the gap is under half a point.
Exercise 12 · Returns to experience
Wages follow . Find the marginal effect of experience at 10 years and where it peaks.
Show solution
Step 1. .
Step 2. At 10 years: per extra year.
Step 3. Peak: years (second derivative ).
Answer: the return is 1 per year at 10 years of experience, and the wage profile peaks at 20 years.
Exercise 13 · Heterogeneous treatment effects via interactions
with , . What is the effect of for a unit with ? With ?
Show solution
Step 1. Differentiate with respect to : .
Step 2. At : . At : .
Answer: 4 and 2. The "main effect" is the effect only where , which is why covariates are often centred before interacting.
Exercise 14 · Approximating the wage bill
A region's wage bill (in $ billion) is , where is the log growth of the average wage and is employment (millions). Start from . Approximate to first order and evaluate it at 10% wage growth () and employment of 1.2 million; compare with the exact value.
Show solution
Step 1. Value at the base point: .
Step 2. Partial derivatives: and at .
Step 3. First-order approximation: . At : .
Step 4. Exact: .
Answer: $1.30 billion approximately versus $1.326 billion exactly. The gap is the second-order (interaction) term: wage growth applies to the extra workers too.
Exercise 15 · Back to the delta method
Use a first-order Taylor expansion of around to recover Day 12's standard error for the odds when .
Show solution
Step 1. has at .
Step 2. First-order Taylor: .
Step 3. So .
Answer: 0.559, Day 12's result: the delta method is Taylor's theorem plus the CLT.
Verify in Python
import numpy as np
# Numerical derivatives (central differences) versus the formulas
d = lambda f, x, h=1e-6: (f(x + h) - f(x - h)) / (2 * h)
print("d/dx ln(x^2+1) at 1:", round(d(lambda x: np.log(x**2 + 1), 1.0), 6), "formula:", 2 * 1 / 2)
lam = lambda z: 1 / (1 + np.exp(-z))
z0 = np.log(0.3 / 0.7) # where the predicted probability is 0.3
print("logit marginal effect:", round(0.8 * d(lam, z0), 4))
for x in (0.01, 0.1, 0.25, 0.5):
print(f"x={x}: ln(1+x)={np.log1p(x):.5f}, 1st order={x:.5f}, 2nd order={x - x**2/2:.5f}")
print("exact % effect of 0.25 log points:", round(100 * (np.exp(0.25) - 1), 2))
print("e^x y at (0.1, 1.2):", round(np.exp(0.1) * 1.2, 4), " first-order approx: 1.3")
Key takeaways
- Derivatives give marginal effects; logs turn them into elasticities and semi-elasticities.
- Taylor expansions replace any smooth function with a local line or parabola; the error shrinks quadratically.
- The delta method, Newton's method and Fisher information are all Taylor expansions.
Simulation Lab: Taylor Approximations
Open full screen →Approximate eˣ, ln(1+x), sin x or the logistic function by polynomials of order 1–4 around any point.
The Taylor polynomial matches the function's value and first few derivatives at the point a. Near a the error shrinks like |x − a|^(order+1); far away the approximation can be poor. Hover to read the error.