Code:
     +-------------------------------------------------------------+
     | country   year     NGDPRPC     NGDPDPC   NGSD_N~P   PCPIPCH |
     |-------------------------------------------------------------|
  1. |   Malta   2010   15939.801   21150.423     18.954     2.041 |
  2. | Estonia   2010    11052.81   14672.328     23.075     2.741 |
  3. |  Cyprus   2010   20490.637   31261.236     12.558     2.558 |
  4. |  Greece   2010   20327.829   26972.873      5.664     4.704 |
     +-------------------------------------------------------------+
Q1. I want to rank countries by year based on the values of the variables NGDPRPC - PCPIPCH. To be specific, for each variable, a country gets rank 1 if it posses the highest value. For example, I tried the following code for the variable NGDPRPC; and it seems to be working.
Code:
gsort year -NGDPRPC
bysort year: egen rank_NGDPRPC = rank(- NGDPRPC)
My question is : Is it the right approach or does a better solution exist?

Q2. Assuming the above code is correct, I want to apply it to all variables. The desired variable names are rank_ followed by the corresponding variables' names. How could I do so?

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str32 country int year double(NGDPRPC NGDPDPC NGSD_NGDP PCPIPCH)
"Cyprus"  2010 20490.637 31261.236 12.558  2.558
"Cyprus"  2011  20051.42 32692.698 14.706  3.481
"Cyprus"  2012 18936.417 29066.268  10.16  3.089
"Cyprus"  2013 17732.983  27825.87  8.246   .381
"Cyprus"  2014 17644.755 27267.428  8.022  -.268
"Estonia" 2010  11052.81 14672.328 23.075  2.741
"Estonia" 2011 11928.681 17470.842 26.442   5.08
"Estonia" 2012 12487.099  17431.54 27.143  4.219
"Estonia" 2013  12774.29 19078.213 27.426  3.247
"Estonia" 2014 13170.071 19969.128 26.937   .476
"Greece"  2010 20327.829 26972.873  5.664  4.704
"Greece"  2011 18464.601 25896.934  5.099  3.118
"Greece"  2012  17173.71 22171.911  8.972  1.035
"Greece"  2013  16742.04 21805.257   9.56  -.854
"Greece"  2014 16984.502  21726.89  10.28 -1.394
"Malta"   2010 15939.801 21150.423 18.954  2.041
"Malta"   2011 16113.851 22933.749 19.254  2.513
"Malta"   2012 16450.882  22069.52 19.718  3.227
"Malta"   2013 17005.342 24021.743 21.781   .979
"Malta"   2014 18097.074 26202.597 26.674   .771
end