import {Inputs, tex} from "@observablehq/stdlib"
// --- Controls ---
viewof loglinear = Inputs.form({
nameX: Inputs.text({label: html`Name of ${tex`X`}`, value: "Good Banana"}),
nameY: Inputs.text({label: html`Name of ${tex`Y`}`, value: "Loan Spread (bps)"}),
beta: Inputs.number({label: html`Coefficient estimate ${tex`\hat{\beta}`}`, value: -0.38, step: 0.0001}),
sigmaX: Inputs.number([0, Infinity], {label: html`Standard deviation of ${tex`X`}`, value: 0.06, step: 0.0001}),
muY: Inputs.number({label: html`Sample mean of ${tex`Y`}`, value: 205.31, step: 0.0001}),
mulnY: Inputs.number({label: html`Sample mean of ${tex`\ln Y`}`, value: 5.066, step: 0.0001}),
showVarName: Inputs.toggle({label: "Show variable names in output", value: true})
})
_DeltaY = (Math.exp(loglinear.mulnY + loglinear.beta * loglinear.sigmaX) - Math.exp(loglinear.mulnY)).toFixed(4)
_absDeltaY = Math.abs(_DeltaY)
A Note on Interpreting Regression Estimates
Research Notes
This note provides convenient tools to interpret the economic significance of regression estimates.
Log-linear model
Suppose we have estimated a regression model: \[ \ln Y = \beta X + \cdots + \varepsilon, \tag{1}\] where \(Y\) is the dependent variable, \(X\) is a key independent variable, and \(\varepsilon\) is the error term.
Note that the sample mean of \(\ln Y\) is NOT equal to the log of the sample mean of \(Y\), unless \(Y\) is constant.
Mathematically, mean of \(\ln Y\) is \(\mathbb{E}[\ln Y]\), while log of the mean of \(Y\) is \(\ln(\mathbb{E}[Y])\). By Jensen’s inequality, since the natural logarithm function \(\ln(\cdot)\) is concave, \[ \mathbb{E}[\ln Y] \le \ln\big(\mathbb{E}[Y]\big), \] with equality only when \(Y\) is constant.
Log-log model
Suppose we have estimated a regression model: \[ \ln Y = \beta \ln X + \cdots + \varepsilon, \tag{2}\] where \(Y\) is the dependent variable, \(X\) is a key independent variable, and \(\varepsilon_{it}\) is the error term.
Old notes
To begin, note that the regression is linear in the logs of \(Y\) and \(X\). This means that if \(\ln(X)\) increases by one unit, then \(\ln(Y)\) increases by approximately \(\hat\beta\) units.
Unit change in \(X\)
If \(X\) increases by one unit, then change in \(\ln(X)\) is
\[ \Delta \ln(X) \equiv \ln(X + 1) - \ln(X) = \ln\left(\frac{X + 1}{X}\right). \]
\(\ln(Y)\) therefore increases by \(\hat\beta \Delta \ln(X)\) units, and hence \(Y\) changes from \(Y_{\text{old}}\) to
\[ Y_{\text{new}} = Y_{\text{old}} \exp\!\big( \hat\beta \, \Delta \ln(X) \big) = Y_{\text{old}} \left( \frac{X + 1}{X} \right)^{\hat\beta}. \]
A change in \(X\) from \(X_1\) to \(X_2\)
If \(X\) increases from \(X_1\) to \(X_2\), then change in \(\ln(X)\) is
\[ \Delta \ln(X) \equiv \ln(X_2) - \ln(X_1) = \ln\left(\frac{X_2}{X_1}\right). \]
\(\ln(Y)\) therefore increases by \(\hat\beta \Delta \ln(X)\) units, and hence \(Y\) changes from \(Y_{\text{old}}\) to
\[ Y_{\text{new}} = Y_{\text{old}} \exp\!\big( \hat\beta \, \Delta \ln(X) \big) = Y_{\text{old}} \left( \frac{X_2}{X_1} \right)^{\hat\beta}. \]
\(\Delta Y\), the additive change in \(Y\), is therefore
\[ \begin{align} \Delta Y &= Y_{\text{new}} - Y_{\text{old}} \\ &= Y_{\text{old}} \exp\big( \hat\beta \, \Delta \ln(X) \big) - Y_{\text{old}} \\ &= \exp\Big( \ln Y_{\text{old}} + \hat\beta \Delta \ln(X) \Big) - \exp\big( \ln Y_{\text{old}} \big). \end{align} \tag{3}\]
In the last step of Equation 3, only the logs of \(Y\) and \(X\) appear. This is to be consistent with the fact that the regression in Equation 2 involves the logs of \(Y\) and \(X\).
Equation 3 also shows that the change in \(Y\) depends on the baseline level of \(\ln Y_{\text{old}}\). To interpret the economic significance of \(\hat\beta\), we therefore need to choose a representative baseline level of \(\ln Y_{\text{old}}\). A common choice is its sample mean.
Let \(\bar m \equiv \overline{\ln Y}\) from the sample. Then the representative change in \(Y\) from a change in \(\ln X\) of \(\Delta \ln X\) is \[ \Delta Y = \exp\big(\bar m + \beta \Delta\ln X\big)-\exp(\bar m), \]
We must compute the mean of \(\ln Y\), not the log of the mean of \(Y\). The latter is \(\ln(\bar Y)\), which is not equal to \(\overline{\ln Y}\) unless \(Y\) is constant.
A common special case is a \(k\)-standard-deviation move in \(\ln X\): \[ \Delta Y(k\sigma) = \exp\!\big(\bar m + \beta\,k\,\sigma_{\ln X}\big)\;-\;\exp(\bar m). \]