Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Problematic twoway lineplot with -by-


From   Steinar Fossedal <[email protected]>
To   [email protected]
Subject   st: Problematic twoway lineplot with -by-
Date   Thu, 13 Aug 2009 14:55:43 +0200

Hi, listers

I'm trying to create a twoway graph using two line graphs, and have it
split into groups using -by- _on_only_one_of_the_graphs_. I'm finding
this a bit tricky to pull off, and I've cooked up an example below
which illustrates the problem. My goal is to have graph 2 included on
each of the plots in graph 1, resulting in a graph with two plots
having two lines each. Instead, I get a graph with four plots in it,
and only a single line per plot.

Is there any way to produce the graph that I want without rearranging my data?

Hope you can help,
-Steinar


Example :

// Create dataset
clear
set obs 40
gen id = int((_n-1)/10)+1
gen group = (id>=3) + 1
bysort id: gen time = _n
replace time = time -.5 if id  == 4
gen value = uniform()
bysort id (time): replace value = value[_n-1] + uniform() if _n > 1

// Create plots
// Graph 1 (using by)
twoway (line value time if group==1, sort by(id))
graph rename graph1
// Graph 2 (not using by)
twoway (line value time if group==2, sort)
graph rename graph2
// Graph 3 (Attempt to merge the two graphs together, getting graph 2
on each of the plots in graph 1)
twoway (line value time if group==1, sort by(id)) (line value time if
group==2, sort)
graph rename graph3

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index