Your model is effectively $$E[y \vert x,w]=\hat y =\hat \alpha+\hat \beta \cdot x + \hat \gamma \cdot w.$$ With the eydx()
option, margins
calculates the average of
$$\frac{\partial \hat y}{\partial x}\cdot\frac{1}{\hat y}= \frac{\hat \beta}{\hat y} \approx \frac{\frac{\Delta \hat y}{y}}{\Delta x}$$ in the estimation sample. This means the OLS coefficient is rescaled by the predicted value of the outcome and then averaged.
This is a kind of semi-elasticity, and can be interpreted as the percentage/proportionate change in the expected value of $y$ for a one unit change in $x$.
This is not exactly equivalent to running the logged outcome regression, though it will often yield fairly similar estimates. margins
is a post-estimation command that relies on previous estimates and performs none of its own.
Similarly, eyex()
calculates the average of $$\frac{\partial \hat y}{\partial x}\cdot \frac{x}{\hat y}= \hat \beta \cdot \frac{x}{\hat y} \approx \frac{\frac{\Delta \hat y}{\hat y}}{\frac{\Delta x}{x}},$$
which is percent change in $y$ for a percent change in $x$, the full elasticity.
Here's Stata code showing these claims:
. sysuse auto, clear
(1978 Automobile Data)
. reg price mpg weight
Source | SS df MS Number of obs = 74
-------------+---------------------------------- F(2, 71) = 14.74
Model | 186321280 2 93160639.9 Prob > F = 0.0000
Residual | 448744116 71 6320339.67 R-squared = 0.2934
-------------+---------------------------------- Adj R-squared = 0.2735
Total | 635065396 73 8699525.97 Root MSE = 2514
------------------------------------------------------------------------------
price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg | -49.51222 86.15604 -0.57 0.567 -221.3025 122.278
weight | 1.746559 .6413538 2.72 0.008 .467736 3.025382
_cons | 1946.069 3597.05 0.54 0.590 -5226.245 9118.382
------------------------------------------------------------------------------
. margins, eydx(mpg)
Average marginal effects Number of obs = 74
Model VCE : OLS
Expression : Linear prediction, predict()
ey/dx w.r.t. : mpg
------------------------------------------------------------------------------
| Delta-method
| ey/dx Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg | -.0086381 .0151161 -0.57 0.569 -.0387787 .0215024
------------------------------------------------------------------------------
. margins, eyex(mpg)
Average marginal effects Number of obs = 74
Model VCE : OLS
Expression : Linear prediction, predict()
ey/ex w.r.t. : mpg
------------------------------------------------------------------------------
| Delta-method
| ey/ex Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg | -.196516 .3468786 -0.57 0.573 -.8881724 .4951403
------------------------------------------------------------------------------
.
. predict double yhat
(option xb assumed; fitted values)
. gen double se = _b[mpg]*1/yhat
. gen double e = _b[mpg]*mpg/yhat
. sum se e
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
se | 74 -.0086381 .0024589 -.0145348 -.0050496
e | 74 -.196516 .1110846 -.5834932 -.0605946
.
. gen ln_p = ln(price)
. reg ln_p mpg weight
Source | SS df MS Number of obs = 74
-------------+---------------------------------- F(2, 71) = 15.26
Model | 3.37488699 2 1.68744349 Prob > F = 0.0000
Residual | 7.84864609 71 .110544311 R-squared = 0.3007
-------------+---------------------------------- Adj R-squared = 0.2810
Total | 11.2235331 73 .153747029 Root MSE = .33248
------------------------------------------------------------------------------
ln_p | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg | -.0106498 .0113942 -0.93 0.353 -.0333692 .0120696
weight | .0002087 .0000848 2.46 0.016 .0000396 .0003778
_cons | 8.237352 .4757123 17.32 0.000 7.288809 9.185896
------------------------------------------------------------------------------
The margins semi-elasticity is a 0.86% decrease in price for an additional mile per gallon, holding weight constant (I find it helpful to multiply $\frac{\Delta \hat y}{\hat y} = 0.0086$ by 100 here). The logged outcome model's semi-elasticity is a 1% decrease.
The elasticity is 19.65% reduction in price for a 1% increase in mpg. If you fit the log-log model, the difference between the margins approach will be starker than in the semi-elasticity case.