Dear all,

I am trying to create new variables based on some specific variables ending with "dac2a". Dataex contains a number of donors, which are listed below. My objective is to demonstrate the similarities and groupings between donor countries, based on their aid flows to recipients.

I prepare these data for hierarchical clustering using Euclidian or Cosine metrics (y ax represents recipients and x represents donors). The amount of aid volume varies greatly across different donors, so I need to standardize all variables. Standardizing all variables will allow me to make a more accurate comparison between donors. Some other way may be getting a percentage of aid amount received by a specific country, as a share of a specific donors' total aid flows. For instance, Ethiopia gets 20 percent of Germany's total ODA flows, but it also gets 10 percent of Switzerland's total ODA flows.

At this time, instead of creating percentages, I want to get new standardized variables for all variables ending with "dac2a" (*dac2a). However, I couldn't create standardized variables for each donor at once. As an example, I provide a code that I used to remove negative values from each variable. A similar code structure should be used to create new standardized variables.




Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float(year usdac2a) str3 ccode float(switdac2a slovakdac2a slovendac2a pordac2a polanddac2a norwaydac2a newzedac2a)
2000       . "ABW"     .    .   .      .     .     .     .
2001       . "ABW"     .    .   .      .     .     .     .
2002       . "ABW"     .    .   .      .     .     .     .
2003       . "ABW"     .    .   .      .     .     .     .
2004       . "ABW"     .    .   .      .     .     .     .
2005       . "ABW"     .    .   .      .     .     .     .
2006       . "ABW"     .    .   .      .     .     .     .
2007       . "ABW"     .    .   .      .     .     .     .
2008       . "ABW"     .    .   .      .     .     .     .
2009       . "ABW"     .    .   .      .     .     .     .
2010       . "ABW"     .    .   .      .     .     .     .
2011       . "ABW"     .    .   .      .     .     .     .
2012       . "ABW"     .    .   .      .     .     .     .
2013       . "ABW"     .    .   .      .     .     .     .
2014       . "ABW"     .    .   .      .     .     .     .
2015       . "ABW"     .    .   .      .     .     .     .
2016       . "ABW"     .    .   .      .     .     .     .
2017       . "ABW"     .    .   .      .     .     .     .
2018       . "ABW"     .    .   .      .     .     .     .
2019       . "ABW"     .    .   .      .     .     .     .
2020       . "ABW"     .    .   .      .     .     .     .
2021       . "ABW"     .    .   .      .     .     .     .
2000    3.52 "AFG"  9.86    .   .      .   .04 19.95   .25
2001   10.97 "AFG" 14.26    .   .      .   .16 63.36  1.39
2002  515.61 "AFG"  23.5    .   .   1.66   .47 87.66  4.27
2003  668.18 "AFG"  22.7  .32   .    .32   .16 85.37  2.31
2004 1042.52 "AFG" 26.15  .56   .   2.35   .28 75.62 13.96
2005 1712.17 "AFG" 24.39 6.12   .   6.37   .38 58.83 11.81
2006 1768.53 "AFG" 23.89 1.98   .   7.25   .59 62.61  4.51
2007 1857.63 "AFG" 25.03 1.41   .   8.82  1.68 75.25  4.29
2008 2541.62 "AFG" 18.08  .24 .14  12.97  1.49 90.75  9.16
2009 3563.97 "AFG" 22.57  .48 .13  10.91  6.14 94.62  5.36
2010 3473.09 "AFG" 19.08  .49  .5  13.72  6.27 89.12  3.79
2011 3536.82 "AFG" 21.85 1.13 .57   1.96  8.29 89.35  5.72
2012  3084.5 "AFG" 27.56  .78 .43   2.39  8.55 81.52 14.96
2013 1892.14 "AFG" 26.69 2.21 .29    .22  3.13 80.74   6.7
2014 2113.98 "AFG" 30.61  .52 .15    .05  1.17 80.46  3.24
2015 1771.05 "AFG" 35.55  .29 .14    .76   .59 76.05   3.7
2016 1478.64 "AFG" 33.99  .35 .09     .9   .58 78.41  3.47
2017 1281.66 "AFG" 29.76  .85 .08   2.08   .66 67.52  5.15
2018  941.94 "AFG" 34.91  .35 .06    .97   .61 81.01   .09
2019 1445.42 "AFG"    33  .36 .07   1.71   .82 71.62     2
2020 1009.47 "AFG" 36.04  .42 .05   1.05   .69 79.24  2.15
2021 1423.89 "AFG" 59.35  .64 .46   1.04   .98 63.61  3.76
2000   54.34 "AGO"  6.73    .   .  24.43   .05 26.33     .
2001   48.36 "AGO"  8.25    .   .  21.56    .1 27.87     .
2002  148.13 "AGO" 10.44    .   .  23.92     . 31.98     .
2003  210.32 "AGO" 10.41  .04   .  26.03   .06 30.08   .63
2004  162.47 "AGO"  9.87  .03   . 848.78   .08 27.64     .
2005   87.33 "AGO"  7.05  .03   .  24.02   .21 20.52     .
2006   41.39 "AGO"  4.77    .   .  22.11  99.9 21.02   .11
2007   48.62 "AGO"  2.06    .   .  18.76   .46 17.06   .13
2008   51.37 "AGO"  1.58    .   .  17.48  5.43 12.51     .
2009   49.63 "AGO"   .76    .   .  -9.23   7.1 14.56     .
2010   63.26 "AGO"   .43    .   . -12.53  1.27   9.8     .
2011   75.18 "AGO"   .54    .   .     -7  -.09  8.41     .
2012   87.84 "AGO"   .41    .   .   1.57  -.23  7.85     .
2013   68.29 "AGO"  1.18    .   .  -9.31 36.95  6.37     .
2014   64.37 "AGO"   .14    .   . -21.99 13.11  8.31     .
2015   66.12 "AGO"   .04    .   . -21.73 14.87  5.92     .
2016   56.23 "AGO"   .78  .01   .  -25.1  4.85  7.39   .04
2017    59.6 "AGO"   .59  .01   . -24.78 -2.07  6.91     .
2018   52.09 "AGO"   .48    0   . -23.02 -1.88  5.35     .
2019   45.31 "AGO"   .06    .   . -22.89 -2.17  4.83     .
2020   40.82 "AGO"   .67    .   . -23.83 -2.25  5.89     .
2021   40.11 "AGO"   .11    . .95   5.27 -2.31  4.91   .02
2000       . "AIA"     .    .   .      .     .     .     .
2001       . "AIA"     .    .   .      .     .     .     .
2002       . "AIA"     .    .   .      .     .     .     .
2003       . "AIA"     .    .   .      .     .     .     .
2004       . "AIA"     .    .   .      .     .     .     .
2005       . "AIA"     .    .   .      .     .     .     .
2006       . "AIA"     .    .   .      .     .     .     .
2007       . "AIA"     .    .   .      .     .     .     .
2008       . "AIA"     .    .   .      .     .     .     .
2009       . "AIA"     .    .   .      .     .     .     .
2010       . "AIA"     .    .   .      .     .     .     .
2011       . "AIA"     .    .   .      .     .     .     .
2012       . "AIA"     .    .   .      .     .     .     .
2013     .02 "AIA"     .    .   .      .     .     .     .
2014       . "AIA"     .    .   .      .     .     .     .
2015       . "AIA"     .    .   .      .     .     .     .
2016       . "AIA"     .    .   .      .     .     .     .
2017       . "AIA"     .    .   .      .     .     .     .
2018       . "AIA"     .    .   .      .     .     .     .
2019       . "AIA"     .    .   .      .     .     .     .
2020       . "AIA"     .    .   .      .     .     .     .
2021       . "AIA"     .    .   .      .     .     .     .
2000   65.14 "ALB" 13.51    .   .      .   .74  5.63     .
2001    60.2 "ALB" 11.07    .   .      .   .29   4.8     .
2002   86.67 "ALB" 16.63  .05   .      .   .05  8.41     .
2003      55 "ALB" 15.96  .32   .      .   .28  7.44     .
2004      54 "ALB"  10.2  .31   .      .   .27  8.93     .
2005   46.79 "ALB" 13.21 1.76   .      .   .22  6.39     .
2006   51.13 "ALB" 12.64    .   .      .     .   5.1     .
2007    39.4 "ALB" 10.05  .01   .      .   .38  4.69     .
2008    43.2 "ALB" 16.85    . .15      .   .36  2.87     .
2009   39.47 "ALB" 14.04    . .58      .    .2   .85     .
2010   33.56 "ALB" 15.35    . .22      .    .4  1.86     .
2011   28.33 "ALB" 11.64    . .21      .   .05  1.78     .
end
------------------ copy up to and including the previous line ------------------

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

Code:

foreach var of varlist var1 var2 var3 {
    replace `var' = 0 if `var' < 0
}