1
$\begingroup$

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.

Distribution

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – Nick Cox
    Commented Apr 3, 2020 at 8:06

2 Answers 2

2
$\begingroup$

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.

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

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).

$\endgroup$
6
  • 1
    $\begingroup$ You are clearly allowed to answer your question, but here the answer underlines that the original question was misleading! $\endgroup$
    – Nick Cox
    Commented Apr 15, 2020 at 22:04
  • $\begingroup$ I did include my code though? The problem was the asinh command, which was in the Pastebin link. $\endgroup$
    – ahorn
    Commented Apr 16, 2020 at 5:11
  • $\begingroup$ But yes, I agree that saying I "logged" the variable was misleading. $\endgroup$
    – ahorn
    Commented Apr 16, 2020 at 5:12
  • $\begingroup$ 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. $\endgroup$
    – Nick Cox
    Commented Apr 16, 2020 at 11:26
  • $\begingroup$ 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. $\endgroup$
    – ahorn
    Commented Apr 16, 2020 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.