Announcement

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

  • How to add values in different variables depending on condition and group?

    Dear Forum members,

    I have a question regarding how to add values in different variables depending on condition. For instance, I have the following variables:
    • Item_ID
    • Totaldue
    • Saleprice
    • Group_with
    Some (not all) "Item_ID" values are in grouped together with a few other values and the group would share a same value in the "Group_with" variable. I'm trying to add values in "Totaldue" and "Saleprice" for all those that share the same "Group_with" and
    1) assign the average of the sum of the group to each "Item_ID" in the same group

    2) and have another variable where I assign the sum to the "Item_ID" that has the lowest number among the group while putting value 0 to all other "Item_ID" in the same group.


    I would really appreciate your help.

    Thank you.

    Best,
    Nathan



  • #2
    Your post has gone unanswered for several hours despite heavy traffic on the forum. While I can only speak for myself, I believe the reason is that your descriptions of what you have and what you want are insufficiently clear for anybody to offer you concrete help. If nobody else gives you a helpful response soon, I suggest you post back with the following improvements:

    1. Show example data, using the -dataex- command to do so. If you are running version 17, 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. Hand-calculate the results you want for a small number of observations from your data set, and show what the results you are looking for would be. In showing these results, explain where each number not found in the original starting data came from and how it was calculated.

    I think if you do that, you will get a timely and helpful response.

    Comment


    • #3
      Nathan:
      I do echo Clyde's opinion here (like I did in many other instances ): I read your post three times, but I felt totally lost with guess-working about all the possible (and probably off target) replies; that's why I bowed out.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thank you very much for your input. I will follow those in the next post.

        Comment

        Working...
        X