Dear all,
I would like to create the stacked bar chart to show the proportion of prescriptions of antithrombotic medications in 2006-2010.
What I would like to make looks as below.

But I've got looks:

I would really appreciate If you may find time to help me solve the problem.
Thank you in advance.
I would like to create the stacked bar chart to show the proportion of prescriptions of antithrombotic medications in 2006-2010.
What I would like to make looks as below.
But I've got looks:
Dataset looks as below and by using loops I got the proportion of prescriptions for each medication.
clear
input byte(id aspirin2006 clopidogrel2006 statin2006 fibrate2006 aspirin2007 clopidogrel2007 statin2007 fibrate2007 aspirin2008 clopidogrel2008 statin2008 fibrate2008 aspirin2009 clopidogrel2009 statin2009 fibrate2009 aspirin2010 clopidogrel2010 statin2010 fibrate2010 sex) int str12 first_date last_date
1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 1 2007 2010
2 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 2 2006 2010
3 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 2007 2009
4 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 2006 2010
5 0 0 0 1 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 2 2007 2009
6 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 2 2006 2010
7 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 2006 2009
8 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 2007 2010
9 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 2 2006 2010
end
destring first_date last_date, replace
reshape long aspirin clopidogrel statin fibrate, i(id) j(year)
keep if inrange(year, first_date, last_date)
// CALCULATE RATES BY SEX BY YEAR FOR EACH DRUG
collapse (sum) aspirin-fibrate (count) denom = id, by(sex year)
foreach v of varlist aspirin-fibrate{
gen `v'_prop = `v'/denom * 100
}I would really appreciate If you may find time to help me solve the problem.
Thank you in advance.
Comment