Dear Statalist users,
I would like to have a stacked bar graph like the one that can be found at http://www.surveydesign.com.au/tipsgraphs.html (code is at the end of this message) but I am having trouble customizing it.
More specifically, there are 2 things I would like to achieve:
1. Include an xlabel that says "Year/Quarter"
2. Change the colors of the bars so that all the bars that correspond to "1" are in red tones and all the ones that correspond to "2" are in blue tones.
Any help is appreciated.
Thanks!
Ana
--------
Code
--------
// Stacked bar graph - reshaping the data
//creating the data
clear
set obs 1000
egen id = seq(), block(10)
egen time = seq(), to(10)
format time %tq
gen time2=string(time, "%tq")
gen sector = ceil(3 * runiform())
bysort id: replace sector=sector[1]
label define sector 1 "SECTOR 1" 2 "SECTOR 2" 3 "SECTOR 3"
label values sector sector
gen sales=exp(rnormal())*1000
gen sales2=2*sales
//reshaping the data
gen obs = _n
rename sales sales1
reshape long sales, i(obs) j(which)
graph bar (sum) sales , over(sector) over(which) ///
over(time2, label(labsize(vsmall))) asyvars stack legend(size(vsmall))
I would like to have a stacked bar graph like the one that can be found at http://www.surveydesign.com.au/tipsgraphs.html (code is at the end of this message) but I am having trouble customizing it.
More specifically, there are 2 things I would like to achieve:
1. Include an xlabel that says "Year/Quarter"
2. Change the colors of the bars so that all the bars that correspond to "1" are in red tones and all the ones that correspond to "2" are in blue tones.
Any help is appreciated.
Thanks!
Ana
--------
Code
--------
// Stacked bar graph - reshaping the data
//creating the data
clear
set obs 1000
egen id = seq(), block(10)
egen time = seq(), to(10)
format time %tq
gen time2=string(time, "%tq")
gen sector = ceil(3 * runiform())
bysort id: replace sector=sector[1]
label define sector 1 "SECTOR 1" 2 "SECTOR 2" 3 "SECTOR 3"
label values sector sector
gen sales=exp(rnormal())*1000
gen sales2=2*sales
//reshaping the data
gen obs = _n
rename sales sales1
reshape long sales, i(obs) j(which)
graph bar (sum) sales , over(sector) over(which) ///
over(time2, label(labsize(vsmall))) asyvars stack legend(size(vsmall))
Comment