# In a lognormal distribution, is the median further left than when the variable is logged?

I created a kernel density estimate of the earnings distribution in South Africa in 2017, quarter 4, using Stata.

I summarized the earnings variable, putting a sampling weight as an analytical weight (because the summarize command doesn't take sampling weights). I then saved the mean and median, and generated the log mean and log median from those.

I then logged the real earnings variable, and ran a kernel density command on it, with sampling weights. In the graph, I added the abovementioned log mean and log median as vertical lines.

My concern is that the median looks too far to the left. I would have thought that half the area under the curve should be to the left and half to the right. Am I correct in thinking that this looks wrong?

My code is here. I'm not sure what I did wrong.

• The log of the mean of a lognormal doesn't have any clear reference. Perhaps more to the point, your data are roughly symmetric on logarithmic scale, but not especially close to lognormal. A quantile plot is a better check. Commented Apr 3, 2020 at 8:06

The log of the mean of y will generally not equal the mean of log(y) because of Jensen's inequality: it will be larger. There's a similar result for medians.

But you have the opposite problem, so that can't be it. Looking at the code, your kernel density has an if condition that constrains the sample, but the summarize where you calculate the mean does not. That would be my first guess where to look, but I can't confirm without your data.

My second guess would be the type weights are different in the two calculations. Try using the same type of weight throughout.

• Isn't that the other way round, because the log function is concave? Commented Apr 3, 2020 at 21:05
• @ahorn Yes, thanks for the correction. Commented Apr 3, 2020 at 21:13
• If you agree with me, then it seems Jensen's Inequality doesn't help to explain what went wrong with my graph. Commented Apr 3, 2020 at 21:15
• Seems like I need a MWE with sysuse data. Commented Apr 4, 2020 at 13:16

You used the inverse hyperbolic sine transformation (IHS) to log the variable. This tends to $$\ln(2) + \ln(x)$$ as $$x$$ gets large, so the values were $$\ln(2)$$ too big. The IHS should only be used in regressions (as then the level would not matter for the coefficients on regressors).

• You are clearly allowed to answer your question, but here the answer underlines that the original question was misleading! Commented Apr 15, 2020 at 22:04
• I did include my code though? The problem was the asinh command, which was in the Pastebin link. Commented Apr 16, 2020 at 5:11
• But yes, I agree that saying I "logged" the variable was misleading. Commented Apr 16, 2020 at 5:12
• If the limit you cite were the only point there would be no gain to using asinh. Let's spell out that the deal is being to accommodate zeros and negative values: how many did you have. Commented Apr 16, 2020 at 11:26
• Only about 50 zero values (out of about 11 000), and no negative. Sorry. I was taught about asinh in Honours, but obviously not thoroughly enough, as I finished the course not knowing why it is not always used. Commented Apr 16, 2020 at 13:01