Announcement

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

  • compute mean of other observations

    Hi,

    Suppose I have the following observations. I would like to calculate the sales average for each observation based on the weekly average value computed from the other channels. For example, for the first observation, this is channel 1 so I will compute the week sales average based on 10 (channel 2) + 6 (channel 3) from week 1 and divide by two. How can I write a code to do this for a larger dataset. Thanks.


    Channel Sales Week Avg
    1 3 1
    1 9 2
    2 10 1
    2 2 2
    3 6 1
    3 15 2

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(channel sales week avg)
    1  3 1 .
    1  9 2 .
    2 10 1 .
    2  2 2 .
    3  6 1 .
    3 15 2 .
    end
    
    rangestat (mean) sales, by(week) excludeself interval(channel . .)
    To run this code you must install -rangestat-, by Robert Picard, Nick Cox, and Roberto Ferrer, available from SSC.

    Comment


    • #3
      Hi Clyde, thank you so much for the prompt reply and help. I appreciate it.

      Comment

      Working...
      X