Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Univariate distribution graphs in a twoway environment?

 From Phil Clayton <[email protected]> To [email protected] Subject Re: st: Univariate distribution graphs in a twoway environment? Date Mon, 7 Oct 2013 23:02:03 +1100

```How is something like this? You can use -kdensity- to generate variables that form the basis of a graph.

----------------------------------------------------------
clear
set obs 5
gen group=_n
expand 100
gen x=rnormal(group, 0.5)
forvalues i=1/5 {
kdensity x if group==`i', gen(k_`i'_x k_`i'_d) nograph
replace k_`i'_d=k_`i'_d + `i' - 0.5
local line `line' line k_`i'_d k_`i'_x ||
}
twoway `line', ylab(1/5) ytitle(Group) legend(off)
----------------------------------------------------------

Phil

On 07/10/2013, at 10:37 PM, [email protected] wrote:

> Dear Statalisters,
>
> I was asked to display the age distributions (e.g. kdensity, histogram ...) of several subgroups in one graph.
> Age is scaled on the x-axis, another numeric variable on the y-axis.
>
> The nearest example I found to explain this is -twoway rcap- :
>
>      sysuse sp500, clear
>      gen num = _n
> 	  keep if uniform() <.05
>       twoway rcap high low num, hor ylabel(,angle(0)) || scatter  num close
>
>
> In this case the y-var 'num' defines the vertical position of each rcap.
>
> Now exchange each rcap with e.g. a kdensity curve (not available with the given data) and it would be what I'm looking for.
> The y-var determines the vertical position of each curve but not it's scaling.
> I didn't find any way to create a graph like this.
> ***
>
> Another example would be to place diagrams inside a graph where x/y determines the position only.
> Again I don't know how to make this, but I know that -spmap- draws basic diagrams on a map using centroid coordinates.
>
>
> Best wishes
>
> Stefan Gawrich
> Dillenburg
> Germany
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```

• References: