Dear Statalist forum users,
I am struggling with following issue for few days and any help is very much appreciated!
I would like to produce a graph where I stack "Var1" and "Var2" for each year and then put a marker like a "diamond" to show the variable "Truesum" which is the overall length of the bar corresponds to the bar’s total value (Var1+Var2= Truesum). I have tried using command "graph bar " which allows for stacking but then I cannot add the third element (Truesum). I also tried the command "twoway bar" but could not manage make it work. I used :
twoway bar Var1 year || bar Var2 year || scatter Truesum year, msymbol(D) ||,xlabel(1995(1)2019, angle(vertical)) xtitle("Year") ytitle("XX") legend(label(1 "Var1") label(2 "Var2") label(3 "Truesum")) .
Using this command, produces a graph where for some years one bar related to Var1 hides under Var2 (i attach the graph produced to this post"
My data set looks like below:
If you have any solution to my problem, please help me out!
Many thanks in advance!
I am struggling with following issue for few days and any help is very much appreciated!
I would like to produce a graph where I stack "Var1" and "Var2" for each year and then put a marker like a "diamond" to show the variable "Truesum" which is the overall length of the bar corresponds to the bar’s total value (Var1+Var2= Truesum). I have tried using command "graph bar " which allows for stacking but then I cannot add the third element (Truesum). I also tried the command "twoway bar" but could not manage make it work. I used :
twoway bar Var1 year || bar Var2 year || scatter Truesum year, msymbol(D) ||,xlabel(1995(1)2019, angle(vertical)) xtitle("Year") ytitle("XX") legend(label(1 "Var1") label(2 "Var2") label(3 "Truesum")) .
Using this command, produces a graph where for some years one bar related to Var1 hides under Var2 (i attach the graph produced to this post"
My data set looks like below:
year | Truesum | Var1 | Var2 |
1995 | -3,83 | 0,15 | -3,98 |
1996 | -1,19 | 0,55 | -1,74 |
1997 | 4,24 | 0,30 | 3,94 |
1998 | 3,58 | 0,64 | 2,94 |
1999 | 3,49 | 0,09 | 3,40 |
2000 | -1,57 | -0,29 | -1,28 |
2001 | -1,58 | 0,17 | -1,75 |
2002 | 0,81 | 0,21 | 0,60 |
2003 | 1,04 | 0,24 | 0,79 |
2004 | 1,10 | 0,03 | 1,08 |
2005 | 3,48 | 0,14 | 3,34 |
2006 | 1,65 | 0,54 | 1,11 |
2007 | -1,81 | -0,34 | -1,47 |
2008 | -2,19 | -0,80 | -1,39 |
2009 | 3,09 | 1,46 | 1,64 |
2010 | -0,15 | 0,21 | -0,36 |
2011 | -1,06 | 0,09 | -1,15 |
2012 | 0,79 | 0,15 | 0,64 |
2013 | -0,20 | 0,11 | -0,31 |
2014 | 2,23 | 1,27 | 0,96 |
2015 | 1,59 | 0,51 | 1,08 |
2016 | 0,85 | 0,13 | 0,73 |
2017 | 0,09 | 0,20 | -0,11 |
2018 | 0,26 | 0,47 | -0,21 |
2019 | -0,28 | 0,24 | -0,52 |
Many thanks in advance!
Comment