Announcement

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

  • Maximum of indexed variables

    Dear users,

    I would like to please ask for your help concerning the following issue.

    I would like to create a variable which contains the maximum of n variables, called x1, x2, ..., xn.
    E.g., let n=3. Then, I would like to have
    Code:
    gen max = max(x1, x2, x3)
    Could you please aid me in referencing to x1 up to xn? Like in max = max(of x1-x3).
    Alternatively, I would highly appreciate if you could help me how to solve my problem in another way.

    Yours sincerely,
    Mario




















  • #2
    If you'd explain what you don't understand in -help max()- , that would help us understand your problem. Also, you don't tell us what your problem is in referencing x1 to xn. I also am wondering if you want a different max for each observation. Finally, I'll make a wild guess that you might want to know in which particular variable the maximum occurred. What I suspect you want is easy to do; the hard part for me here is figuring out what you want.

    Comment


    • #3
      Hello

      and thank you for your kind, quick reply.

      Your wild guess is not correct and even revisiting the help file makes me wonder where it might originate from.
      Although I rested assured my problem being entirely clear, I will add a picture.
      Click image for larger version

Name:	max1.JPG
Views:	1
Size:	13.4 KB
ID:	1491800


      So (I would like to write “of course“) I want a maximum for each different observation.
      The problem is that realiter I do not have n=3 but n>100. In fact, n is not fixed. Thus, it were prohibitive respectively infeasible to type out “max(x1, x2, …, xn)”. As the guidelines demand, my example was a minimal example.
      The problem posed now is that I cannot use max(x1-xn) and to be sure, let n=100, max(x1-x100). To be even surer, this would imply to have additional 97 columns in the above picture.

      Yours sincerely,
      Mario
      Last edited by Mario Sum; 04 Apr 2019, 05:23.

      Comment


      • #4
        you do not want -gen- and you do not want the max function; you want
        Code:
        egen max=rowmax(x1-x100)
        but note that this assumes these are contiguous; you could substitute "x*" if you want to include all variables which have variable names starting with "x"; see
        Code:
        help egen

        Comment


        • #5
          Exactly! Thank you very much, indeed!

          I noticed that I still have to keep this in mind.

          Comment

          Working...
          X