I am using Stata 15.1 MP on a Windows 10 PC and face the following problem: I want to plot six different density plots in one graph while controlling the range of the x-axis. However, I am unable to do the latter one and found no solution in the web.
Let me explain you my problem with the following MWE, where I just plot two different densities:
Code:
sysuse auto, clear ** Demeaning, that both new variables are centered around zero sum price replace price = price - r(mean) sum mpg replace mpg = mpg - r(mean) * Graph twoway (kdensity price) || (kdensity mpg)
Code:
twoway (kdensity price, xscale(range(-5 5)) xlabel(-5(1)5) ) || (kdensity mpg, xscale(range(-5 5)) xlabel(-5(1)5))
Code:
twoway (kdensity price) || (kdensity mpg) , xscale(range(-5 5)) xlabel(-5(1)5)
My Google search pointed me towards the Stata tip https://www.stata-journal.com/sjpdf....iclenum=gr0019 that explains that the range suboption will never decrease but just increase the range.
Does anybody know how to solve my problem?
Just as background, before I am being asked why I want to do this: I am comparing different estimators and one of those has a relatively huge spread (similar to the one of the variable price in the MWE above). Due to that, the default range set by Stata explodes and the graph is not intuitive anymore. For the reader of my publication it is sufficient to the see the flat line of the density of the respective estimator in the interval, which I want to choose by truncating the x-axis.
Many thanks in advance.
Best,
Andreas
0 Response to Twoway Kdensity Plot – Truncate X-Axis
Post a Comment