Announcement

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

  • Loop to take average of every 20 rows and store it

    Hey,

    I keep it basic. I have 10 000 rows of numeric values with a variable name temperature.. I would like Stata to take the average of 20 entries and store that.

    So for example the first loop goes, through the first 20 rows, takes the average and then stores it. Next loop it goes through rows 20-40, takes the average of those and returns it. Repeat this for (10 000/20) = 500 times. End result is a variable name called new_temperature which has averages.

    I feel that this problem is easy enough so that I dont need to provide an example data-set.

    Thank you!

  • #2
    Code:
    egen group = seq(), block(20)
    egen new_temperature = mean(temperature), by(group)

    Comment

    Working...
    X