Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: bar graph axis color- frustrated


From   "Airey, David C" <[email protected]>
To   "[email protected]" <[email protected]>
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index