Hi,

I have a dataset which i want to be uniques with the variables gvkey, fyear and loc.
But there are duplicates. Incase of duplicates, I want to remove the observations which have data, if there is data in 2 observations i want to keep the one with max value.
Any suggestions please.

Below is the data extracted with dataex.
input str6 gvkey str4 curcd double(fyear at capx ceq dltt ebitda oiadp oibdp revt sale txdb xopr xrd) str4 loc byte(check checkcurcd temp)
"114881" "USD" 2010 3.165 .005 3.027 0 -1.16 -1.195 -1.16 1.817 1.817 0 2.977 . "AIA" 0 0 0
"114881" "USD" 2011 2.439 .005 2.343 0 -.66 -.668 -.66 1.417 1.417 0 2.077 . "AIA" 0 0 0
"114881" "USD" 2012 3.362 0 3.256 0 -.093 -.098 -.093 1.766 1.766 0 1.859 . "AIA" 0 0 0
"114881" "USD" 2013 3.607 .002 3.369 0 -.785 -.79 -.785 1.939 1.939 0 2.724 . "AIA" 0 0 0
"114881" "USD" 2014 3.997 .005 3.84 0 -2.624 -2.627 -2.624 .032 .032 0 2.656 1.181 "AIA" 0 0 0
"114881" "USD" 2015 1.129 .001 .951 0 -2.946 -2.949 -2.946 .112 .112 0 3.058 1.23 "AIA" 0 0 0
"114881" "USD" 2016 .129 .007 -.316 .348 -2.619 -2.623 -2.619 .279 .279 0 2.898 1.078 "AIA" 0 0 0
"114881" "USD" 2017 .558 .004 -.147 .502 -1.752 -1.756 -1.752 .093 .093 0 1.845 .833 "AIA" 0 0 0
"114881" "USD" 2018 .769 .012 .678 0 -2.684 -2.69 -2.684 .107 .107 0 2.791 .948 "AIA" 0 0 0
"114881" "USD" 2019 9.787 .007 8.407 .103 -.993 -1.467 -.993 4.517 4.517 0 5.51 1.014 "AIA" 0 0 0
"114881" "USD" 2020 10.969 .028 8.67 .121 .58 .015 .58 7.148 7.148 0 6.568 1.149 "AIA" 0 0 0
"114881" "USD" 2021 13.926 .008 9.351 .09 1.005 .439 1.005 12.475 12.475 .21 11.47 1.679 "AIA" 0 0 0
"024368" "USD" 2010 279.359 2.533 90.672 16.323 29.34 26.353 29.34 264.13 264.13 2.908 234.79 . "ANT" 0 0 0
"024368" "USD" 2011 303.735 4.748 87.603 16.815 39.314 35.904 39.314 331.297 331.297 1.993 291.983 . "ANT" 0 0 0
"024368" "USD" 2012 332.274 7.047 85.868 17.64 43.933 40.158 43.933 343.927 343.927 2.842 299.994 . "ANT" 0 0 0
"024368" "USD" 2013 437.151 8.149 86.793 63.971 51.206 46.901 51.206 452.149 452.149 2.205 400.943 . "ANT" 0 0 0
"024368" "USD" 2014 464.919 5.405 88.88 60.18 46.058 41.423 46.058 486.993 486.993 1.968 440.935 . "ANT" 0 0 0
"024368" "USD" 2015 391.394 4.15 74.644 61.82 40.559 36.005 40.559 419.303 419.303 .781 378.744 . "ANT" 0 0 0
"024368" "USD" 2016 386.822 6.389 49.174 58.936 49.71 45.527 49.71 489.085 489.085 .968 439.375 . "ANT" 0 0 0
"024368" "USD" 2017 179.811 1.927 75.202 .038 14.854 13.163 14.854 196.93 196.93 .072 182.076 . "ANT" 0 0 0
"024368" "USD" 2018 140.93 1.926 29.216 .469 21 19.291 21 231.272 231.272 .228 210.272 . "ANT" 0 0 0
"024368" "USD" 2019 41.827 1.139 12.458 .377 1.054 .161 1.054 68.814 68.814 0 67.76 . "ANT" 0 0 0
"024368" "USD" 2020 17.037 .215 9.378 0 -.944 -1.34 -.944 .327 .327 0 1.271 . "ANT" 0 0 0
"024368" "USD" 2021 7.984 0 4.216 0 -.541 -.541 -.541 .487 .487 0 1.028 . "ANT" 0 0 0
"014033" "USD" 2010 255.126 1.743 39.265 10.748 28.077 26.161 28.077 257.056 257.056 4.174 228.979 . "ARE" 0 0 0
"014033" "USD" 2011 232.053 .859 45.684 7.345 38.597 36.507 38.597 329.592 329.592 4.822 290.995 . "ARE" 0 0 0
"014033" "USD" 2012 326.532 1.526 131.305 4.831 52.715 50.778 52.715 413.683 413.683 8.528 360.968 . "ARE" 0 0 0
"014033" "USD" 2013 422.45 3.325 153.836 2.739 75.33 73.266 75.33 547.344 547.344 6.666 472.014 . "ARE" 0 0 0
"014033" "USD" 2014 497.072 2.375 193.36 1.466 92.432 90.035 92.432 700.045 700.045 6.217 607.613 . "ARE" 0 0 0
"014033" "USD" 2015 502.986 .568 216.209 .518 69.13 67.068 69.13 563.451 563.451 5.201 494.321 . "ARE" 0 0 0
"014033" "USD" 2016 574.605 .072 262.483 .049 70.684 68.905 70.684 551.831 551.831 4.491 481.147 . "ARE" 0 0 0
"014033" "USD" 2017 512.827 .443 218.715 .027 47.92 46.303 47.92 413.901 413.901 .802 365.981 . "ARE" 0 0 0
"014033" "USD" 2018 26.157 -1.18 -1.395 27.582 -324.812 -325.58 -324.812 64.437 64.437 .291 389.249 . "ARE" 0 0 0
"035993" "USD" 2017 . . . . . . . . . . . . "ARE" 0 0 0
"035993" "USD" 2018 199.937 .271 60.978 28.109 29.919 24.203 29.919 35.839 35.839 0 5.92 . "ARE" 0 0 0
"035993" "USD" 2019 307.252 38.69 109.416 102.785 37.06 31.274 37.06 44.085 44.085 0 7.025 . "ARE" 0 0 0
"035993" "USD" 2020 432.624 97.215 128.619 259.304 29.789 23.91 29.789 41.832 41.832 0 12.043 . "ARE" 0 0 0
"104579" "AED" 2010 1199.604 . 623.683 134.422 -52.169 -54.378 -52.169 190.923 . . . . "ARE" 0 0 0
"104579" "AED" 2011 1060.163 . 614.172 106.608 7.427 5.189 7.427 105.506 . . . . "ARE" 0 0 0
"104579" "AED" 2012 1048.919 . 627.802 82.8 37.7 35.911 37.7 139.564 . . . . "ARE" 0 0 0
"104579" "AED" 2013 882.36 . 478.636 48.578 -16.096 -17.521 -16.096 53.856 . . . . "ARE" 0 0 0
"104579" "AED" 2014 878.82 . 417.819 22.578 -51.284 -52.017 -51.284 16.524 . . . . "ARE" 0 0 0
"104579" "AED" 2015 904.093 . 349.421 .155 -38.331 -39.048 -38.331 92.429 . . . . "ARE" 0 0 0
"104579" "AED" 2016 871.008 . 260.852 185.014 -68.597 -69.278 -68.597 166.776 . . . . "ARE" 0 0 0
"104579" "AED" 2017 636.412 . 115.481 154.94 -109.639 -110.313 -109.639 76.582 . . . . "ARE" 0 0 0
"104579" "AED" 2018 548.268 . 105.235 117.84 -14.336 -14.902 -14.336 54.04 . . . . "ARE" 0 0 0
"104579" "AED" 2019 463.148 . 74.433 105.967 4.166 3.705 4.166 34.373 . . . . "ARE" 0 0 0
"104579" "AED" 2020 386.018 . 8.795 60.439 -12.457 -12.783 -12.457 49.366 . . . . "ARE" 0 0 0
"104580" "AED" 2010 931.925 . 301.066 . 47.112 46.725 47.112 187.838 . . . . "ARE" 0 0 0
"104580" "AED" 2011 972.166 . 322.866 . 43.53 43.274 43.53 172.435 . . . . "ARE" 0 0 0
"104580" "AED" 2012 1066.548 . 355.572 . 41.99 41.762 41.99 198.232 . . . . "ARE" 0 0 0
"104580" "AED" 2013 1166.439 . 393.02 . 44.514 44.26 44.514 204.143 . . . . "ARE" 0 0 0
"104580" "AED" 2014 1214.164 . 421.529 . 48.423 48.133 48.423 214.017 . . . . "ARE" 0 0 0
"104580" "AED" 2015 1266.055 . 439.163 . 40.759 40.406 40.759 204.493 . . . . "ARE" 0 0 0
"104580" "AED" 2016 1334.176 . 459.247 . 41.909 41.307 41.909 204.992 . . . . "ARE" 0 0 0
"104580" "AED" 2017 1325.57 . 481.631 . 44.411 43.763 44.411 212.141 . . . . "ARE" 0 0 0
"104580" "AED" 2018 1331.312 . 497.355 . 49.11 48.028 49.11 220.195 . . . . "ARE" 0 0 0
"104580" "AED" 2019 1370.119 . 515.372 . 45.762 44.713 45.762 215.756 . . . . "ARE" 0 0 0
"104580" "AED" 2020 1446.262 . 526.899 . 48.432 47.486 48.432 208.518 . . . . "ARE" 0 0 0
"104580" "AED" 2021 1374.202 . 538.617 . 34.75 34.023 34.75 203.616 . . . . "ARE" 0 0 0
"179660" "USD" 2010 .06 0 -.055 0 -.061 -.061 -.061 .025 .025 0 .086 . "ARE" 0 0 0
"179660" "USD" 2011 .257 0 .201 0 -.594 -.624 -.594 .008 .008 0 .602 . "ARE" 0 0 0
"179766" "AED" 2010 3037.836 24.188 1599.889 157.485 -123.286 -191.494 -123.286 1814.393 1814.393 .337 1937.679 . "ARE" 0 0 0
"179766" "AED" 2011 3029.986 70.709 1663.037 66.438 161.691 77.101 161.691 1736.108 1736.108 .309 1574.417 . "ARE" 0 0 0
"179766" "AED" 2012 3144.126 46.514 1598.924 83.534 -113.808 -189.351 -113.808 1946.845 1946.845 2.671 2060.653 . "ARE" 0 0 0
"179766" "AED" 2013 3209.399 26.197 1448.843 126.755 -60.001 -122.082 -60.001 2318.403 2318.403 1.928 2378.404 . "ARE" 0 0 0
"179766" "AED" 2014 2981.469 20.623 1461.355 95.424 93.036 33.961 93.036 1940.249 1940.249 .283 1847.213 . "ARE" 0 0 0
"179766" "AED" 2015 2489.921 9.346 1167.822 43.94 -132.953 -190.739 -132.953 1640.627 1640.627 .248 1773.58 . "ARE" 0 0 0
"179766" "AED" 2016 2625.1 10.7 1215.7 45.6 113.8 65.2 113.8 1730.3 1730.3 0 1616.5 . "ARE" 0 0 0
"179766" "AED" 2017 2620.1 22.5 1397 25.9 231.2 192.6 231.2 1800.3 1800.3 .2 1569.1 . "ARE" 0 0 0
"179766" "AED" 2018 2392.1 25 1140.9 22.8 85.3 46.9 85.3 1802.3 1802.3 .1 1717 . "ARE" 0 0 0
"179766" "AED" 2019 1944.8 22.6 717.1 52.2 -332.3 -372.2 -332.3 1375.8 1375.8 .1 1708.1 . "ARE" 0 0 0
"179766" "AED" 2020 1266.4 5.7 225.5 18.2 -328.1 -365.7 -328.1 599.7 599.7 .1 927.8 . "ARE" 0 0 0
"179766" "AED" 2021 1053.5 2.7 269.4 47.3 20.8 -6.3 20.8 801.6 801.6 .1 780.8 . "ARE" 0 0 0
"187366" "USD" 2010 0 0 -3.26 0 -.733 -.733 -.733 0 0 0 .733 . "ARE" 0 0 0
"187366" "USD" 2011 .049 0 -6.418 0 -6.892 -6.893 -6.892 .021 .021 0 6.913 . "ARE" 0 0 0
"187366" "USD" 2012 .017 0 -8.319 0 -2.143 -2.143 -2.143 0 0 0 2.143 . "ARE" 0 0 0
"187366" "USD" 2013 .009 0 -6.417 0 -.954 -.954 -.954 0 0 0 .954 . "ARE" 0 0 0
"187366" "USD" 2014 .01 0 -6.235 0 -1.094 -1.094 -1.094 0 0 0 1.094 . "ARE" 0 0 0
"187366" "USD" 2015 .058 .042 -7.058 0 -.747 -.751 -.747 0 0 0 .747 . "ARE" 0 0 0
"187366" "USD" 2016 .063 0 -6.532 0 -.589 -.593 -.589 0 0 0 .589 . "ARE" 0 0 0
"201676" "USD" 2010 2658.274 424.103 2092.946 0 676.199 487.723 676.199 780.409 780.409 83.231 104.21 . "ARE" 0 0 0
"201676" "USD" 2011 3351.317 406.782 2588.545 0 1061.624 856.205 1061.624 1150.513 1150.513 115.815 88.889 . "ARE" 0 0 0
"201676" "USD" 2012 3843.093 366.749 2859.316 0 1002.542 790.908 1002.542 1155.143 1155.143 141.789 152.601 . "ARE" 0 0 0
"201676" "USD" 2013 4396.2 281.105 3239.499 0 902.862 687.732 902.862 1047.89 1047.89 175.633 145.028 . "ARE" 0 0 0
"201676" "USD" 2014 4960.056 546.51 3708.204 0 895.023 578.616 895.023 1093.057 1093.057 146.38 198.034 . "ARE" 0 0 0
"251138" "AED" 2010 178271.194 . 19564.787 23460.695 4326.384 4217.589 4326.384 9003.58 . . . . "ARE" 0 0 0
"251138" "AED" 2011 183725.63 . 22072.006 22386.414 6358.269 6177.394 6358.269 10527.417 . . . . "ARE" 0 0 0
"251138" "AED" 2012 180795.723 . 24269.789 18346.172 5639.246 5476.433 5639.246 9234.079 . . . . "ARE" 0 0 0
"251138" "AED" 2013 183142.536 . 24176.598 15523.791 5450.712 5293.059 5450.712 8985.543 . . . . "ARE" 0 0 0
"251138" "AED" 2014 204019.463 . 26408.436 21853.912 5740.638 5582.64 5740.638 8907.947 . . . . "ARE" 0 0 0
"251138" "AED" 2015 228267.101 . 28727.762 26744.179 6675.859 6524.423 6675.859 8866.834 . . . . "ARE" 0 0 0
"251138" "AED" 2016 258289.257 . 30350.885 26328.845 6881.809 6736.996 6881.809 11053.376 . . . . "ARE" 0 0 0
"251138" "AED" 2017 265003.295 . 32444.94 33254.821 7602.257 7437.143 7602.257 12058.344 . . . . "ARE" 0 0 0
"251138" "AED" 2018 279830.338 . 32805.543 31895.319 9390.717 9214.79 9390.717 13564.078 . . . . "ARE" 0 0 0
"251138" "AED" 2019 405134.677 . 55638.387 44351.405 12433.922 12002.688 12433.922 18872.421 . . . . "ARE" 0 0 0
"251138" "AED" 2020 411156.301 . 56597.369 52636.977 8751.692 8252.472 8751.692 16771.725 . . . . "ARE" 0 0 0
"251138" "AED" 2021 440278.369 . 59359.8 51806.629 7951.733 7454.896 7951.733 14358.324 . . . . "ARE" 0 0 0
"251139" "AED" 2010 75257.518 . 6107.577 6708.931 2163.868 2086.653 2163.868 4089.952 . . . . "ARE" 0 0 0
"251139" "AED" 2011 74335.066 . 8568.458 6798.033 2134.597 2043.207 2134.597 4282.217 . . . . "ARE" 0 0 0
end
[/CODE]
------------------ copy up to and including the previous line ------------------

Listed 100 out of 572444 observations
Use the count() option to list more