Hello All,
I have been getting stuck on computing the average of the variable score based on the three closest observations for the variable rating. For example, the variable rating for the first observation in the year 2016 and region 1 is 6.3507. The three closest observations for this observation based on the variable rating are 7.2844, 3.9329 and 3.3063. The new variable score1 that I have been trying to compute should be the average of their corresponding values for the variable score: 0.18, 0.27 and 0.15, which equals 0.2. It is extremely complex and time-consuming to solve it using Excel. I tried different ways using Stata. However, no success so far and really getting frustrated.
Any help is much appreciated!
Many thanks,
David
I have been getting stuck on computing the average of the variable score based on the three closest observations for the variable rating. For example, the variable rating for the first observation in the year 2016 and region 1 is 6.3507. The three closest observations for this observation based on the variable rating are 7.2844, 3.9329 and 3.3063. The new variable score1 that I have been trying to compute should be the average of their corresponding values for the variable score: 0.18, 0.27 and 0.15, which equals 0.2. It is extremely complex and time-consuming to solve it using Excel. I tried different ways using Stata. However, no success so far and really getting frustrated.
Any help is much appreciated!
Code:
*To install: ssc install dataex clear input int year int region float rating float score 2016 1 6.3507 0.22 2016 1 7.2844 0.18 2016 1 3.3063 0.15 2016 1 1.9716 0.39 2016 1 3.9329 0.27 2016 2 2.3123 0.51 2016 2 2.3670 0.42 2016 2 6.7519 0.41 2016 2 1.2646 0.36 2016 2 1.2286 0.58 2015 1 1.1943 0.98 2015 1 2.4667 0.67 2015 1 8.9587 0.17 2015 1 7.1866 0.33 2015 1 6.6857 0.42 2015 2 3.6258 0.72 2015 2 7.7948 0.66 2015 2 1.6079 0.6 2015 2 2.4596 0.55 2015 2 3.0391 0.43 2014 1 5.1069 0.59 2014 1 8.5398 0.52 2014 1 5.3647 0.36 2014 1 3.7527 0.39 2014 1 3.4095 0.09 2014 2 1.9004 0.65 2014 2 2.7130 0.60 2014 2 8.4072 0.50 2014 2 2.9089 0.52 2014 2 1.0119 0.53 end
David
Comment