Announcement

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

  • max min command

    Dear all,
    I'm trying to use max command but i get "command max is unrecognized".
    Is there any other ways like max ?!
    "su , mean only r(max)" is not good for my propose.


  • #2
    I don't know of a max command although one could be written. max() could be a function.

    Please expand on what you want here.

    summarize, meanonly is supposedly what you don't want, but what do you want?

    Comment


    • #3
      Welcome to Statalist.

      There is no "max command" in Stata. There is a max() function, and the egen command includes a max() function.

      With no description of what your purpose is, that summarize will not fulfill, any attempt to make a recommendation would be guesswork.

      Take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

      Section 12.1 is particularly pertinent

      12.1 What to say about your commands and your problem

      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
      ...
      Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.
      The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

      Comment


      • #4

        i have a panel data and i want to run a code like this :

        Code:
            local i=.
            local j=.
            gen dwnAAAtoD=.
            foreach var of varlist issue_id   {
            replace `i' =1 if rating==22
            bys issue_id : replace `i' =max(`i')
            replace `j' =1 if rating==1
            bys issue_id : replace `j' =max(`j')
            bys issue_id : replace dwnAAAtoD =`i'*`j'
             }
        Last edited by Ali Niazi; 05 Mar 2019, 10:28.

        Comment


        • #5
          This code
          Code:
          max(2,10,.,7)
          is not like this code
          Code:
          replace `i' = max(`i')
          because it lacks a command like generate or replace.
          Code:
          . generate x = max(2,10,.,7)
          
          . list x
          
               +----+
               |  x |
               |----|
            1. | 10 |
               +----+
          
          . display max(2,10,.,7)
          10
          
          . max(2,10,.,7)
          command max is unrecognized
          r(199);

          Comment


          • #6
            The Stata function max() requires two or more arguments and returns the maximum of those arguments. Like any function in Stata it can't be issued on its own but only within other commands, usually generate or replace or display.

            This isn't very well explained in the help, but a single argument is illegal:

            Code:
            . di max(2)
            invalid syntax
            r(198);
            
            . di max(2, 3)
            3
            Your code raises several difficulties even apart from that.

            Code:
            local i=.
            local j=.
            gen dwnAAAtoD=.
            So far, so good.

            Code:
            foreach var of varlist issue_id   {  
            
            }
            That's a loop in terms of var but you never refer to a local macro var inside the loop. That's not illegal, but usually code like that means that the programmer is confused or has made a mistake. In this case, the beginning of the loop will be fine (so long as there is really is a variable issue_id).

            Code:
              
             replace `i' =1 if rating==22
            You have defined local macro i as the character . (missing). Hence Stata will see

            Code:
             replace . =1 if rating==22
            That's illegal and Stata would issue an error message. After replace only one kind of thing is legal, a variable name.

            Code:
            bys issue_id : replace `i' =max(`i')
            replace `j' =1 if rating==1
            bys issue_id : replace `j' =max(`j')
            These commands are all illegal for the same reason, and two are illegal for the extra reason of supplying only one argument to max().

            Code:
            bys issue_id : replace dwnAAAtoD =`i'*`j'
            That's legal. As the local macro j was also defined as missing the result of this is

            Code:
             bys issue_id : replace dwnAAAtoD = .*.
            which is perfectly legal. The result would be to replace every value by missing.

            Note that the prefix

            Code:
            bys issue_id:
            is irrelevant to the result, which does not depend on the current value of that variable issue_id.

            I have looked at your code and tried hard to guess what you mean, which can't be what you say, but I failed.

            I have to ask that you drill down and explain what you want to do, because your code doesn't make it clear (to me).

            If you want groupwise maxima, then I would look at egen, whose max() function (in a different sense of the word) behaves differently.
            Last edited by Nick Cox; 05 Mar 2019, 11:19.

            Comment


            • #7
              first of all, thanks for your reply.
              consider this data with 3 issue_id
              issue_id date rating
              1 1991 22
              1 1992 21
              1 1995 1
              2 1991 22
              2 1993 4
              2 1995 3
              3 1991 22
              3 1992 21
              3 1993 18
              3 1994 16
              3 1995 1
              I want to write a code to find 5 years default frequency (rating which goes from 22 to 1 in this horizon ). I'm a stata beginner. the prior code was my try. I appreciate your help.
              Last edited by Ali Niazi; 05 Mar 2019, 11:27.

              Comment


              • #8
                Thanks for the detail, which perhaps will make sense to some. I don't work with finance data and have no idea what "5 years default frequency" means.

                Comment

                Working...
                X