Announcement

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

  • using the averageif function with "<>" in STATA

    I want to create a variable avgcal for a specific brand which gives the average of calories of all other brands:

    Brand name Calories

    Cornflakes 100
    Rice krispies 50
    Frosted flake 120

    So for cornflakes, i should get (50+120)/2, for rice krispies (100+120))/2 and for frosted flake (100+50)/2. I need a command that will generate a column with these numbers for all the brands. Please help.


  • #2
    if I understand correctly, this is a FAQ:

    http://www.stata.com/support/faqs/da...ng-properties/

    Comment


    • #3
      Rich has the positive answer. In the very simplest case, with one set of observations and no missings, this would be just

      Code:
      su calories, meanonly 
      gen ave_others = (r(sum) - calories) / (_N - 1)
      Note that there is no averageif function in Stata and that <> has no special meaning in Stata

      If you're assuming that everyone recognises syntax from some other software, that will be wrong!

      Comment

      Working...
      X