Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Summation with restrictions

    Hello,

    I'm working with a dataset which includes information about 5 countries. In this case, I only want to work with 3 variables. The data looks like this:

    reporter partner aux
    Belgium Israel .0097238
    Belgium Italy .0004703
    Belgium Japan .0017738
    Belgium Mexico .0038083

    Israel Belgium .0058587
    Israel Italy .0009222
    Israel Japan .0017172
    Israel Mexico .0051594


    Where aux is the respective distance between each pair of countries by the GDP of each partner (say aux=Dij / GDPj).
    So, I want to generate a new variable which shows the sum of these aux values for each combination of countries BUT without considering its respective aux value. Also it must be by reporter.
    For example, the new variable should show in the first row (Belgium-Israel) the sum of .0004703+.0017738+.0038083 (these are the aux values of the other combination for Belgium, with italy, Japan and Mexico). Then, in the second row (Belgium-Italy) the sum of .0097238+.0017738+.0038083. Also, I want the same for Israel.

    I hope you understand what I want.

    Thanks!!



    Last edited by Javier Vasquez; 29 Oct 2019, 16:51.

  • #2
    This requires rangestat from SSC (ssc install rangestat).
    Code:
    rangestat (sum) aux, interval(aux . .) by(reporter) excludeself
    Last edited by Wouter Wakker; 30 Oct 2019, 01:08.

    Comment


    • #3
      I wonder about the intended calculations. Unless the order of the pairings of countries has some inherent meaning, then you're generating data based on the alphabetical order of countries. So, if Italy happened to come before Israel in the alphabet, you'd get different results.
      Just a concern.

      You probably can do this with egen with a by condition, and then subtract out the value for the specific observation.

      Comment


      • #4
        Wouter,

        It worked! Thanks

        Phil,

        No worries, it doesn't matter the order of countries. Thanks though

        Comment

        Working...
        X