Announcement

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

  • Adding quantity of particular product from all importers and one particular exporter

    Dear all,

    I have a dataset with information about products (numeric), their quantity, the importer (ISO code) and the exporter (ISO code) who sold the product to the importer. Now I would like to sum up the quanitity of one product (several importers could have bought it from one person (exporter)) of all importers who imported it from one particular exporter.
    As I have a huge dataset, I would like to have one universal code for that if that is possible.

    I hope this was understandable.

    Thank you so much in advance for your help!

    Cheers

    Maria

  • #2
    Please read the Forum FAQ for excellent advice on how to improve your posts and maximize your chance of getting a timely and helpful response. In particular:

    1. When asking for help with code, post example data, and use the -dataex- command to do that. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    2. It is the norm in this community to use our real given name and surname as our user ID, to promote collegiality and professionalism. The Forum software, unfortunately, does not permit you to edit your user ID once it is established, but you can click on CONTACT US in the lower right corner of this page and message the forum administrator requesting that he do it for you.

    Now, I will venture a guess as to how your data are organized and suggest code that will do what you are looking for:

    Code:
    by product exporter, sort: gen total_all_importers = total(quantity_purchased)
    Additional note: some people think a data set with 1,000 observations is huge. Some people think a data set with a million is only moderate size. There are situations where one might use different coding approaches depending on the size of the data set. To get the best advice, if you are concerned about performance issues, it is best to give a more precise statement about the size of your data set.

    Comment


    • #3
      Clyde Schechter gives excellent advice as always. He means -egen- not -gen-.

      Comment


      • #4
        Indeed, I do mean -egen-, not -gen. Thank you, Nick.

        Comment

        Working...
        X