I would like to write
in order to display the mean of Y. This yields:
However when I do this there is a gap between the Y and the n. Using
This avoids the gap however in that case the bar above the Y is not long enough for my liking.
I have seen that there exists a question \overline and \widehat with subscript but that question asks about subscript added to the bar symbol, not subscript added to the symbol(s) which are under the bar.
I'm also aware of this question: Overline over a symbol with an index but that question is about what you should or shouldn't do; not a method to solve this problem.
Thanks in Advance!
EDIT: I realize that this question is very similar to this one: Symbol with overline and subscript leads to wrong kerning, however the answer given below is better than the ones to that question.