Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: RE: AW: RE: AW: RE: AW: AW: RE: -ciplot- -eclplot- combine with box-options?

From   "Nick Cox" <>
To   <>
Subject   st: RE: AW: RE: AW: RE: AW: AW: RE: -ciplot- -eclplot- combine with box-options?
Date   Mon, 10 May 2010 14:13:24 +0100

Your code does not work for me beyond example 1, as your commands make reference to a variable -sex- which is no longer in the dataset after your -statsby-. 

But it is entirely possible to tweak a -by()- option so that it behaves more like -over()-:

sysuse bpwide, clear 

stripplot bp*, 
by(sex, compact col(1)) 
subtitle(, pos(9) ring(1) nobexpand bcolor(none) placement(e))

In words, you can 

1. insist that -by()- panels are aligned vertically. 

2. move the panel subtitle away from the top of each panel. 

See also 

SJ-8-2  gr0034  . . . . . . . . . .  Speaking Stata: Between tables and graphs
        (help labmask, seqvar if installed) . . . . . . . . . . . .  N. J. Cox
        Q2/08   SJ 8(2):269--289
        outlines techniques for producing table-like graphs


Kaulisch, Marc

Nick, you are right. I was not not clear enough ( I hope the e-mail-programs show the tabs clear enough):

I would like to see the confidence-intervals (boxes) for each of the categories and combination of categories in vertical order. I think this more readable as if the plots for each first category (Cat1) are separately plotted. Especially, if I would like to spot not only differences between one category (Cat2) but also to see whether items in category 1 are different. This is less a problem with "sex" as a by-variable but if I have eight items in a by-var it is very hard to tell differnces...

I hope the examples in my earlier post show this...

My example 1 shows the categories like this:
	cat2_1      box
	cat2_2	box
	cat2_1	box
	cat2_2	box

My example 2 shows the categories like:
CompCat_1_1		box
CompCat_1_2		box
CompCat_2_1		box
CompCat_2_2		box

With By() I get
		Cat1_1		Cat1_2
Cat2_1	box			box
Cat2_2	box			box


-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von Nick Cox
Gesendet: Montag, 10. Mai 2010 12:31
Betreff: st: RE: AW: RE: AW: AW: RE: -ciplot- -eclplot- combine with box-options?

My comment was a lament, not a reproach. I'll look at the help for
-stripplot- to make it clearer that -by()- is an easy alternative to -over()-. 

In return, I am not clear what you mean by better interpretable graphs than those generated with -by()-. 


Kaulisch, Marc

Dear Nick,

Thanks for the follow up clarifing opportunities with -stripplot-. I am not as much into Stata that I can adhoc find solutions for two nice-to-haves I would like. 1) Avoid a composite variable for including two categorical variables (comparing sex by agegroup). 2) Better interpretable graphs than those generated with by().

I might miss features of -stripplot- or Stata again.

. sysuse bpwide, clear

1) Example with boxplot
. graph hbox bp_before bp_after , over(sex, label(labs(vsmall))) over(agegrp, label(labs(vsmall)) sort(1) descending)

2) Example with Confidence-intervals:

. tempfile tf1 tf2
. statsby mean1=r(mean) ub1=r(ub) lb1=r(lb) N1=r(N), by(agegrp)
saving(`tf1'): ci bp_before
. statsby mean2=r(mean) ub2=r(ub) lb2=r(lb) N2=r(N), by(agegrp)
saving(`tf2'): ci bp_after
. dsconcat `tf1' `tf2'
. generate axis = 6 if agegrp == 3 & sex == 0 . replace axis = 5 if agegrp == 3 & sex == 1 . replace axis = 4 if agegrp == 2 & sex == 0 . replace axis = 3 if agegrp == 2 & sex == 1 . replace axis = 2 if agegrp == 1 & sex == 0 . replace axis = 1 if agegrp == 1 & sex == 1 . la de laxis 6 "60+ Male" 5 "Female" 4 "46-59 Male" 3 "Female" 2 "30-45 Male" 1 "Female"
. la val axis laxis
. twoway scatter  axis mean1 || rcap ub1 lb1 axis, hori || scatter  axis
mean2 || rcap ub2 lb2 axis, hori , ///
			ylabel(1(1)6, labs(vsmall) nogrid val
angle(hori))			///	
			legend(label(1 "Mean bp_before") label(2 "CI
bp_before") ///
			label(3 "Mean bp_after") label(4 "CI bp_after")
size(vsmall) rows(2) span)

3) Stripplot (!?) with Confidence intervals:
* Generate axis as in solution (2)
. stripplot bp_before bp_after , by(axis, compact) vertical bar
boffset(0) ms(none) xsc(r(0.8 2.2))

Nick Cox

It's a pity that Marc missed a (simpler) solution with -stripplot- that requires no dataset manipulation at all. 

sysuse bpwide 

stripplot bp_before bp_after , by(sex, compact) stack vertical bar

gets you there directly. 

If you really want only the c.i. bars, so that the data points are suppressed, that's perverse, but you can do it too: 

stripplot bp_before bp_after , by(sex, compact) vertical bar boffset(0)
ms(none) xsc(r(0.8 2.2))

In short, -stripplot- for two or more variables and two or more groups requires -by()- not -over()-. As program writer, I saw no point trying to re-create a complicated set-up when -by()- does it for you for free. 


Kaulisch, Marc

Okay, it seems that -statsby- does the trick together with -dsconcat- (ssc).

Preliminary without labels etc:

sysuse bpwide
tempfile tf1 tf2
statsby mean1=r(mean) ub1=r(ub) lb1=r(lb) N1=r(N), by(agegrp)
saving(`tf1') subsets total: ci bp_before statsby mean2=r(mean)
ub2=r(ub) lb2=r(lb) N2=r(N), by(agegrp)
saving(`tf2') subsets total: ci bp_after dsconcat `tf1' `tf2'
twoway rcap ub1 lb1 agegrp || scatter mean1 agegrp || rcap ub2 lb2 agegrp || scatter mean2 agegrp 

Kaulisch, Marc


Thanks a lot for this extensive answer. I learn a lot. I haven't had time yet to go deeper in the opportunities to work with statsby (will do this later). But experimenting with -stripplot- I come very early to an end...

I would like to create a graph such as
. sysuse bpwide
. graph hbox bp_before bp_after, over(sex) over(agegrp), sort(1)

But I do not want a boxplot but a ci-bar as in stripplot...

-stripplot- does not allow two vars with over.

. ciplot bp_before bp_after, by(agegrp)
looks closer to my interest...

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index