Hi,
I have a panel dataset with a single variable:
I created the Rank variable because I need to get the top/bottom 3 countries according the 2015 value of Variable X and plot them in the same graph, preferably with the top in the primary y axis and the bottom in the secondary y axis. I have to repeat this with multiple versions of Variable X so the top/bottom countries are random. I started with this:
Is there a way to "unpack" the members of the macros to plot them in a single graph? I had two ideas:
Pseudocode 1
twoway (tsline Variable_X if Country is in top, yaxis(1))
(tsline Variable_X if Country is in bottom, yaxis(2))
Pseudocode 2
xtline Variable X if Country is in top or if Country is bottom, overlay
But I couldn't implement neither of them. Any suggestions?
Thank you.
I have a panel dataset with a single variable:
Year | Country | Variable_X | Rank |
2000 | ARG | 64 | 3 |
... | ... | ... | ... |
2015 | ARG | 34 | 3 |
2000 | AUS | 67 | 1 |
... | ... | ... | ... |
2015 | AUS | 54 | 1 |
Code:
preserve collapse (mean) Rank, by(Country) levelsof(Country) if Rank <= 3, local(bottom) levelsof(Country) if Rank >= [_N-3], local(top) restore
Is there a way to "unpack" the members of the macros to plot them in a single graph? I had two ideas:
Pseudocode 1
twoway (tsline Variable_X if Country is in top, yaxis(1))
(tsline Variable_X if Country is in bottom, yaxis(2))
Pseudocode 2
xtline Variable X if Country is in top or if Country is bottom, overlay
But I couldn't implement neither of them. Any suggestions?
Thank you.
Comment