Announcement

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

  • How to identify the largest observation per group

    Dear members

    I have loan data where a firm ( borrower Id) has multiple loans per year and would like to find the largest loan for borrower id in each year . Specifically, I would like to creat a new variable containing only the largest loan amount for each borrower id in a given year for robustness .

    would you kindly provide me the code ?

    Blessings and thanks for your kind response

  • #2
    I don't know what is robust about selecting the maximum, but

    Code:
    egen max_loan = max(loan) , by(borrower_id year)
    should point in a good direction.

    (In Stata an observation is a case, record, or row in the dataset. Maximum value is a better term here for what you want.)

    Comment


    • #3
      Dear Nick
      as always, thank you for your prompt response and help.

      Comment


      • #4
        Regarding the robustness, the max loan amount per borrower id will be used in a robustness model.

        Comment


        • #5
          No idea what that means, but that doesn't matter.

          Comment


          • #6
            Hey Nick
            a follow up question: so I used your code but the problem is that I only want to have the max loan in a given year per borrower id without duplicating the same amount for the same borrower id in a given year.
            thanks

            Comment


            • #7
              See the tag() function in the help for egen which is designed for precisely this problem.

              Comment


              • #8
                Thank you Nick, it worked now.

                Comment

                Working...
                X