Hello everyone, I have managed to create the stacked barchart I want, but in order to do so, I had to manually calculate proportions which is inefficient if I want to do many of these! I was therefore hoping you could recommend a way to achieve the same with code alone.
An example of my dataset consists of two variables as below:
What I did was first use the code:
to manually obtain the proportions of each procedure within each year, and then re-input the following:
which outputs my desired graph.

Any way to achieve the same directly from the initial dataset? Also, if a proportion is equal to zero for a certain year, the option "stack" reports an error- any way around it?
Many thanks in advance
An example of my dataset consists of two variables as below:
Code:
clear input long year procedure 2010 1 2010 1 2010 2 2010 3 2011 1 2011 2 2011 2 2011 3 2011 3 2012 1 2012 2 2012 3 2012 3 end
Code:
tab procedure year, col
Code:
clear input long procedure year prop 1 2010 .5 1 2011 .2 1 2012 .25 2 2010 .25 2 2011 .4 2 2012 0.25 3 2010 .25 3 2011 .4 3 2012 .5 end graph bar (asis) prop, over(procedure) over(year) asyvars stack
Any way to achieve the same directly from the initial dataset? Also, if a proportion is equal to zero for a certain year, the option "stack" reports an error- any way around it?
Many thanks in advance
Comment