<>
Last two lines should be
*************
gr combine graph1 graph2, /*
*/ rows(1)
*************
These things do not always transfer well...
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Martin Weiss
Gesendet: Donnerstag, 13. August 2009 15:09
An: [email protected]
Betreff: st: AW: Problematic twoway lineplot with -by-
<>
*************
// 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
separate value if group==1, by(id)
tw (line value1 time if group==1, sort) /*
*/ (line value time if group==2, sort), /*
*/ legend(off) nodraw
graph rename graph1
tw (line value2 time if group==1, sort) /*
*/ (line value time if group==2, sort), /*
*/ legend(off) nodraw
graph rename graph2
gr combine graph1 graph2,
rows(1)
*************
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Steinar Fossedal
Gesendet: Donnerstag, 13. August 2009 14:56
An: [email protected]
Betreff: st: Problematic twoway lineplot with -by-
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/
*
* 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/
*
* 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/