Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: programming graphs in stata


From   "Dott. A.R. Osella" <[email protected]>
To   <[email protected]>
Subject   Re: st: programming graphs in stata
Date   Wed, 17 Oct 2007 12:34:48 +0200

----- Original Message ----- From: "Maarten buis" <[email protected]>
To: <[email protected]>
Sent: Wednesday, October 17, 2007 12:27 PM
Subject: Re: st: programming graphs in stata



--- Scott Merryman <[email protected]> wrote:
Do you mean something like this?
<snip>

Matthias was looking for a spineplot, and Scott's code got close to
that, but is not a spineplot. The code below should give you a
spineplot (and a barplot and a combination of the two for comparison).

*---------------- begin example --------------------
sysuse auto,clear
collapse (count) mpg, by(rep foreign)
drop if rep78 >=.
reshape wide mpg, i(rep78) j(foreign)
graph bar (asis) mpg1 mpg0, ///
over(rep78) stack ///
legend(order(1 "foreign" 2 "domestic")) ///
title("bar plot") ///
bar(1, color(gs8)) bar(2,color(gs12)) ///
name(bar,replace)

sysuse auto, clear
collapse (count) mpg (mean) foreign, by(rep)
keep if rep !=.
sum mpg
gen freq = .95*mpg/r(sum)
sort rep78
gen gr_order = _n - 1
expand 2
bysort rep: gen t = _n

gen gap = gr_order * .05/4
gen sum = sum(fre) if t ==2
replace sum = sum[_n-1] if t == 1
replace sum = 0 in 1
replace sum = sum + gap

forvalues i = 0/4 {
local ibegin = `i' * 2 + 1
local iend = `i' * 2 + 2
local begin = sum[`ibegin']
local end = sum[`iend']
local mid = `begin' + (`end' - `begin')/2
local lab = rep78[`ibegin']
local xlab `"`xlab' `mid' "`lab'""'
}

gen foo = 1

twoway area foo sum if rep <=1, color(gs12) ///
|| area foreign sum if rep <=1, color(gs8) ///
|| area foo sum if rep <=2 & rep>1 , color(gs12) ///
|| area foreign sum if rep <=2 & rep>1, color(gs8) ///
|| area foo sum if rep <=3 & rep>2 , color(gs12) ///
|| area foreign sum if rep <=3 & rep>2 , color(gs8) ///
|| area foo sum if rep <=4 & rep>3 , color(gs12) ///
|| area foreign sum if rep <=4 & rep>3, color(gs8) ///
|| area foo sum if rep <=5 & rep>4 , color(gs12) ///
|| area foreign sum if rep <=5 & rep>4, color(gs8) ///
||, legend(order(1 "domestic" 2 "foreign")) ///
xlabel(`xlab') xtitle("") ///
ylab(0(.25)1) ytitle("") ///
title("spineplot") ///
name(spine, replace)

grc1leg bar spine
*--------------------- end example -----------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


___________________________________________________________
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.13/1074 - Release Date: 16/10/07 14.14



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.14.13/1074 - Release Date: 16/10/2007 14.14


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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