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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: bar graph axis color- frustrated


From   "Airey, David C" <david.airey@Vanderbilt.Edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: bar graph axis color- frustrated
Date   Fri, 11 Jun 2010 12:09:22 -0500

.

I like how you actually use the _stack variable by labeling it with the variable labels. Whenever I use stack, I never know what to do with _stack!

I typically use reshape, but for example here I lose the variable labels, and wind up with not as nice a graph as you got.

/* Scott */
sysuse auto,clear
local i = 1
foreach var of varlist mpg head turn gear  {
	local l`var' : var label `var'
	local a " `a' `i' `"`l`var''"' "
	local ++i
}
collapse mpg head turn gear,  by(fore)
stack mpg head turn gear, into(a) clear
label def _stack `a'
label val _stack _stack
bys _s: gen origin = _n -1
reshape wide a, i(_s) j(origin)
label var a0 "Domestic"
label var a1 "Foreign"
graph dot (asis) a*,  over(_s) name(stack, replace)

/* Dave */
sysuse auto,clear
collapse (mean) mpg head turn gear, by(foreign)
foreach var of varlist mpg-gear {
	rename `var' mean`var'
}
gen row = _n
reshape long mean, i(row) j(var) string
drop row
reshape wide mean, i(var) j(foreign)
label var mean0 "Domestic"
label var mean1 "Foreign"
graph dot (asis) mean*, over(var) name(reshape, replace)




> A result like this?
> 
> sysuse auto,clear
> local i = 1
> foreach var of varlist mpg head turn gear  {
> 	local l`var' : var label `var'
> 	local a " `a' `i' `"`l`var''"' "
> 	local ++i
> }
> collapse mpg head turn gear,  by(fore)
> stack mpg head turn gear, into(a) clear
> label def _stack `a'
> label val _stack _stack
> bys _s: gen origin = _n -1
> reshape wide a, i(_s) j(origin)
> label var a0 "Domestic"
> label var a1 "Foreign"
> graph dot (asis) a*,  over(_s)
> 
> 
> Scott
> 


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index