Announcement

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

  • Column Mean

    Hello,

    Sorry if this is a simple question, but I am trying to generate a variable that is an average of the rows above it (a column mean). However, its not clear to me how to do this.

    Using collapse will not work because I have different groups in the first column and because stata requires a "by" variable this would not work.

    There doesn't appear to be an equivalent command for column to creating means as there is for rows (i.e. rowmean)

    Has anyone found a way to generate a variable like this?

    thanks!

    Donovan

  • #2
    A running mean is just a running sum divided by a running count. This may help; if not, and other answers don't help, please give a data example as we always request (FAQ Advice #12).

    Code:
    sysuse auto, clear
    sort mpg 
    gen meansofar = sum(mpg) / sum(mpg < .) 

    Comment


    • #3
      Hazarding a wild guess (on account of the term "different groups in the first column"), I wonder whether you meant something like this:

      Code:
      . by foreign, sort : egen mymean = mean(mpg)
      Best regards,

      Marcos

      Comment

      Working...
      X