Announcement

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

  • sum of a variable under a condition

    I am trying to summarize the serval variables if they are greater than the maximum of another variable. Below is my attempted code which is incorrect. How can I fix this?


    sum TLE_50_512 if TLE_50_512 > max (TLE_50_511)
    sum TLE_50_513 if TLE_50_513 > max (TLE_50_511)




  • #2
    Either of these examples should start you in a useful direction.

    1) Use egen to create a new variable containing the desired maximum to compare to.
    Code:
    egen max_50_511 = max(TLE_50_511)
    sum TLE_50_512 if TLE_50_512 > max_50_511
    sum TLE_50_513 if TLE_50_513 > max_50_511
    2) Use summarize to find the maximum, and save the scalar result returned by summarize (see the output of help summarize for details on the returned values) it in a scalar to compare to.
    Code:
    sum TLE_50_511
    scalar max_50_511 = r(max)
    sum TLE_50_512 if TLE_50_512 > max_50_511
    sum TLE_50_513 if TLE_50_513 > max_50_511

    Comment

    Working...
    X