Dear All,
I would like to ask for your help with a graph.
I am trying to plot a time series graph for a set of countries covering a long time period. In this graph, I want to shade different time periods such as 1914-1918 representing WWI and 1929-1933 for, say, the Great Depression. The idea is to examine and highlight the behavior of the variable of interest during crises and wars.
Here is a small sample of my dataset:
I first tried xtset as follows:
and this is what I get:

However, I want to add another red shaded area representing the Great Depression from 1929 to 1933. However, either it is not possible to use a second addplot in a xtline command or I do not know the syntax. Therefore, I tried using twoway command as follows:
And, this is exactly what I need, with one issue:

The problem is that all the lines have the same color. I can change the color of each country one by one but doing that for 30 countries is cumbersome. As a result, what is the best way to draw line graphs using different colors for each cross-section (i.e., country) and shading different time periods?
Thanks much!
I would like to ask for your help with a graph.
I am trying to plot a time series graph for a set of countries covering a long time period. In this graph, I want to shade different time periods such as 1914-1918 representing WWI and 1929-1933 for, say, the Great Depression. The idea is to examine and highlight the behavior of the variable of interest during crises and wars.
Here is a small sample of my dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 countrycode long country float(growth year) "AUS" 1 10.024693 1911 "AUS" 1 9.974738 1912 "AUS" 1 9.75042 1913 "AUS" 1 10.057388 1914 "AUS" 1 7.283008 1915 "AUS" 1 10.12659 1916 "AUS" 1 7.42883 1917 "AUS" 1 7.57371 1918 "AUS" 1 6.327252 1919 "AUS" 1 7.21542 1920 "AUS" 1 7.095078 1921 "AUS" 1 8.320311 1922 "AUS" 1 5.399998 1923 "AUS" 1 10.180904 1924 "AUS" 1 10.06109 1925 "AUS" 1 7.486308 1926 "AUS" 1 10.340823 1927 "AUS" 1 7.752385 1928 "AUS" 1 7.759354 1929 "AUS" 1 7.530534 1930 "AUS" 1 7.639144 1931 "AUS" 1 10.162165 1932 "AUS" 1 5.608512 1933 "AUS" 1 7.279832 1934 "AUS" 1 6.331858 1935 "BEL" 3 8.85781 1911 "BEL" 3 8.178906 1912 "BEL" 3 9.323483 1913 "BEL" 3 9.402299 1914 "BEL" 3 9.476538 1915 "BEL" 3 9.074595 1916 "BEL" 3 10.578003 1917 "BEL" 3 8.696825 1918 "BEL" 3 9.128453 1919 "BEL" 3 10.017156 1920 "BEL" 3 9.139081 1921 "BEL" 3 8.072706 1922 "BEL" 3 8.88786 1923 "BEL" 3 8.1320095 1924 "BEL" 3 7.959105 1925 "BEL" 3 9.338673 1926 "BEL" 3 7.812702 1927 "BEL" 3 7.918984 1928 "BEL" 3 7.454969 1929 "BEL" 3 7.351252 1930 "BEL" 3 8.828863 1931 "BEL" 3 7.184987 1932 "BEL" 3 8.069019 1933 "BEL" 3 9.006024 1934 "BEL" 3 8.311745 1935 "DEU" 8 7.892393 1911 "DEU" 8 9.651399 1912 "DEU" 8 8.632092 1913 "DEU" 8 8.28789 1914 "DEU" 8 7.977337 1915 "DEU" 8 10.431575 1916 "DEU" 8 7.570191 1917 "DEU" 8 7.742984 1918 "DEU" 8 10.417802 1919 "DEU" 8 8.221521 1920 "DEU" 8 7.508376 1921 "DEU" 8 7.702057 1922 "DEU" 8 10.70087 1923 "DEU" 8 7.923444 1924 "DEU" 8 9.978134 1925 "DEU" 8 9.152789 1926 "DEU" 8 8.491194 1927 "DEU" 8 9.136617 1928 "DEU" 8 10.640782 1929 "DEU" 8 8.840117 1930 "DEU" 8 9.80104 1931 "DEU" 8 8.808121 1932 "DEU" 8 8.611423 1933 "DEU" 8 8.196269 1934 "DEU" 8 7.710318 1935 "ESP" 16 6.683319 1911 "ESP" 16 6.053169 1912 "ESP" 16 4.6855 1913 "ESP" 16 2.43726 1914 "ESP" 16 7.01205 1915 "ESP" 16 3.524547 1916 "ESP" 16 1.63328 1917 "ESP" 16 7.355763 1918 "ESP" 16 2.944922 1919 "ESP" 16 5.046619 1920 "ESP" 16 7.467513 1921 "ESP" 16 6.907943 1922 "ESP" 16 4.981208 1923 "ESP" 16 6.118643 1924 "ESP" 16 4.19532 1925 "ESP" 16 7.569752 1926 "ESP" 16 3.51857 1927 "ESP" 16 6.868908 1928 "ESP" 16 6.126564 1929 "ESP" 16 2.993657 1930 "ESP" 16 6.490144 1931 "ESP" 16 6.188913 1932 "ESP" 16 6.752308 1933 "ESP" 16 2.08029 1934 "ESP" 16 2.703319 1935 end label values country country1 label def country1 1 "Australia", modify label def country1 3 "Belgium", modify label def country1 8 "Germany", modify label def country1 16 "Spain", modify
I first tried xtset as follows:
Code:
xtset country year sum growth g shade=round(r(max)) xtline growth, overlay ytitle("Growth") leg(off) text(11.5 1916 "World War I") addplot (area shade year if inrange(year,1914,1918), color(red%25))
However, I want to add another red shaded area representing the Great Depression from 1929 to 1933. However, either it is not possible to use a second addplot in a xtline command or I do not know the syntax. Therefore, I tried using twoway command as follows:
Code:
twoway line growth year, plotregion(margin(0)) c(L) leg(off) ytitle("growth") text(11.5 1915 "World War I" 11.5 1931 "Great Depression" , size(*0.6))|| area shade year if inrange(year,1914,1918), color(red%25) || area shade year if inrange(year, 1929,1933), color(red%25)
The problem is that all the lines have the same color. I can change the color of each country one by one but doing that for 30 countries is cumbersome. As a result, what is the best way to draw line graphs using different colors for each cross-section (i.e., country) and shading different time periods?
Thanks much!
Comment