The natural log transformation is often used to model nonnegative, skewed dependent variables such as wages or cholesterol. We simply transform the dependent variable and fit linear regression models like this:

Unfortunately, the predictions from our model are on a log scale, and most of us have trouble thinking in terms of log wages or log cholesterol. Below, I show you how to use Stata’s **margins** command to interpret results from these models in the original scale. I’m also going to show you an alternative way to fit models with nonnegative, skewed dependent variables.

## The data and the model

Let’s open the NLSW88 dataset by typing

This dataset includes variables for hourly wage (**wage**), current grade completed (**grade**), and job tenure measured in years (**tenure**).

I would like to fit a linear regression model using **grade** and **tenure** as predictors of **wage**. A summary of the data shows that there are 2,246 observations for hourly wage with a minimum of $1 and a maximum of $40.7.

And a histogram shows that **wage** has a skewed distribution.

Let’s create a new variable for the natural logarithm of **wage**.

We can fit a regression model for our transformed variable including **grade**, **tenure**, and the square of **tenure**. Note that I have used Stata’s factor-variable notation to include **tenure** and the square of **tenure**. The **c**. prefix tells Stata to treat **tenure** as a continuous variable, and the **##** operator tells Stata to include the main effect (**tenure**) and the interaction (**tenure*****tenure**).

Now we can use **margins** to help us interpret the results of our model.

This **margins** command reports the average predicted log wage. Based on this model and assuming we have a random or otherwise representative sample, we expect that the average hourly log wage in the population is 1.87 with a confidence interval of [1.85, 1.89]. However, I’m not sure if that’s high or low because I’m not used to thinking on a log-wages scale.

It is tempting to simply exponentiate the predictions to convert them back to wages, but the reverse transformation results in a biased prediction (see references Abrevaya [2002]; Cameron and Trivedi [2010]; Duan [1983]; Wooldridge [2010]).

## How to estimate unbiased predictions

Let’s assume that the errors from our model are normally distributed and independent of grade and tenure. In this situation, we can remove the bias of the reverse transformation by including a function of the variance of the errors in our prediction,

E(**Y**|**X**) = e^{XB}e^{σ2/2}

where σ^{2} is the variance of the errors.

We can use the square of the root mean squared error (RMSE) as an estimate of the error variance. The RMSE remains in memory after we use **regress**, and we can refer to it by typing **`e(rmse)’**. So if we wanted predictions of hourly wages for each individual, we could type

Here **lnwage_hat** is the prediction of log wage, and we plug this into the function above to obtain the predicted wages in **wage_hat**.

To interpret the results of our model on the wage scale, we will likely want to go beyond these individual-level predictions.

## The expression() option in margins

Fortunately, we can use **margins** with the **expresssion()** option to compute margins and estimate effects based on a transformation of predictions. In the **expression()** option, we can refer to the linear prediction of log wage as **predict(xb)**. Our first instinct might be to use the same expression we used in our **generate** command above and estimate the expected average hourly wage by typing

However, the standard error of our estimate will be incorrect. Because **regress** reports the RMSE but does not estimate its variance, the result of this **margins** command would include the RMSE as though it were a known value, measured without error. Fortunately, there is a way around this.

## How to obtain unbiased estimates and their standard errors

Let’s fit our linear regression model using Stata’s **gsem** command.

Notice that the variance of the errors (**var(e.lnwage)**) is included at the bottom of the output. **gsem** also estimated the standard error of that variance, and **margins** will incorporate that standard error into its calculations. In the **margins** command below, I have replaced **xb** with **eta** and **`e(rmse)’^2** with **_b[/var(e.lnwage)]**.

Now the results are easier to interpret—the expected average wage is $7.67 per hour. Our standard error and confidence interval are also on the original wage scale.

With these predictions correctly incorporated in the **expression()** option, we can answer many additional interesting questions using **margins**. For instance, we can use the **at()** option to estimate expected hourly wages for different values of the independent variables. For example, what is the expected hourly wage if we set **grade** at values ranging from 12 to 18 years of education?

Taking the difference between these values, say, the difference between the expected value when **grade**=16 and when **grade**=12, gives us the effect of having a college education instead of a high school education on hourly wages.

## Use poisson rather than regress; tell a friend

Bill Gould wrote a blog post in 2011 titled “Use poisson rather than regress; tell a friend“. He recommends that we abandon the practice of linear regression with log-transformed dependent variables and instead use Poisson regression with robust standard errors. I won’t reiterate his reasoning here, but I will show you how to use this method.

First, we use **poisson** with the option **vce(robust)** to fit the model for the untransformed dependent variable **wage**.

Then, we use **margins** just as we did above to estimate the average hourly wage.

We can again use **margins, at()** to obtain estimates for different values of **grade**.

With **regress**, we made the assumption that the errors were normal. If that assumption is valid, the estimates we obtain using that method are more efficient. However, this approach that uses **poisson** is more robust.

Whether you use a log transform and linear regression or you use Poisson regression, Stata’s **margins** command makes it easy to interpret the results of a model for nonnegative, skewed dependent variables.

— Chuck Huber

Associate Director of Statistical Outreach

## References

- Abrevaya, J. 2002. Computing marginal effects in the Box–Cox model.
*Econometric Reviews*21: 383–393. - Cameron, A. C., and P. K. Trivedi. 2010.
*Microeconometrics Using Stata*. Rev. ed. College Station, TX: Stata Press. - Duan, N. 1983. Smearing estimate: A nonparametric retransformation method.
*Journal of the American Statistical Association*78: 605-610. - Wooldridge. J. M. 2010.
*Econometric Analysis of Cross Section and Panel Data*. 2nd ed. Cambridge, MA: MIT Press.