Announcement

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

  • Summing observations with bilateral trade data

    Dear Statalist community,
    I'm working on bilateral trade openness between countries, and I am searching for a way to sum observations from country a to b with b to a. Here is an example of the dataset I am dealing with:
    Code:
    iso3_o    iso3_d    year    import_openness
    DEU    FRA    1978    .0306583
    DEU    FRA    1979    .0312403
    FRA    DEU    1978    .0185003
    FRA    DEU    1979    .020072
    Here,I would like to sum the import openness from Germany to France and from France to Germany for each year. I was wondering if there was a way to compute this for a large dataset (400k+ observations). I've succeeded using the command -reshape- accordingly, but it does not work for the complete dataset as there is too many values.
    The goal is to generate a new variable that looks like this:
    Click image for larger version

Name:	Screenshot (31).png
Views:	1
Size:	9.4 KB
ID:	1498564


    With each element being the import openness between country i and j at time t (import flow divided by the importer GDP).

    Thank you in advance !

  • #2
    I don't that reshape is either needed or even helpful here. The sum of whatever over e.g. exporters is

    Code:
    egen double total_i = total(whatever), by(iso3_o year) 
    and that over importers is similar. Those appear to be your denominator terms.

    For handling dyads some tricks are explained within https://www.stata-journal.com/articl...article=dm0043

    Comment


    • #3
      Dear Nick,
      Thank you for your swift answer. I found what I needed using your link, and it works like a charm.

      Code:
      generate first = cond(iso3_o < iso3_d, iso3_o, iso3_d)
      generate second = cond(iso3_o > iso3_d, iso3_o, iso3_d)
      
      bysort first second year: egen bil_open = sum(import_openness)
      drop import_openness first second
      Thanks again for your support !

      Cheers
      LP

      Comment


      • #4
        Originally posted by Leo Picard View Post
        Dear Nick,
        Thank you for your swift answer. I found what I needed using your link, and it works like a charm.

        Code:
        generate first = cond(iso3_o < iso3_d, iso3_o, iso3_d)
        generate second = cond(iso3_o > iso3_d, iso3_o, iso3_d)
        
        bysort first second year: egen bil_open = sum(import_openness)
        drop import_openness first second
        Thanks again for your support !

        Cheers
        LP
        This has been immensely helpful! Thank you so much!

        Comment

        Working...
        X