Announcement

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

  • Generate a new variable using Min and Max

    Hi everyone,

    Is there a way to generate a new variable by dividing the minimum and maximum values obtained from
    Code:
    summarize
    ?
    I have tried...
    Code:
     foreach x or variable1 variable2 variable3 egen {
    egen ratio_`x'= max(`x')/min(`x')
    ...with no success

  • #2
    There are several syntax errors there.

    But even if that syntax worked you would just put a constant in the new variable.

    This is legal if the variable names are real:

    Code:
    foreach x in variable1 variable2 variable3 { 
          su `x', meanonly 
          gen ratio_`x'  = r(max)/r(min) 
    }
    Is that what you want?

    Comment


    • #3
      Originally posted by Nick Cox View Post
      There are several syntax errors there.

      But even if that syntax worked you would just put a constant in the new variable.

      This is legal if the variable names are real:

      Code:
      foreach x in variable1 variable2 variable3 {
      su `x', meanonly
      gen ratio_`x' = r(max)/r(min)
      }
      Is that what you want?
      Yes, this is exactly what I was looking for. Thank you!

      Comment

      Working...
      X