Announcement

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

  • Average of columns

    Dear Statalist Forum Users,

    I need to generate a new variable and it should be an average of Australasia 1-3 by years, respectively. I couldn't do it with mean function. Could you please guide to solve this puzzle?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year double(Australasia1 Australasia2 Australasia3)
    2004         .031713725           .0188608         .061213625
    2005 .07910982500000001 .07479179999999999 .11829147500000001
    2006         .068764825          .09010705         .021152375
    2007          .01910585         .070793225         .020817725
    2008           .2299376         .156618025                  0
    2009          .07698375         .028891725                  0
    2010 .17976684999999998         .141374475          .21233075
    2011 .24364802500000002 .11400450000000001         .060823025
    2012         .132407025           .1499245          .02909345
    2013         .034845475          .08928675           .0304878
    2014           .1185409           .0925432           .0699606
    2015           .1742644          .13983335           .1468419
    2016           .2490718           .2701679         .198164525
    2017         .307399925          .35079265          .23733085
    2018         .172188025 .37054982500000005          .05440995
    2019 .21579435000000002 .30530257499999997 .12087587500000001
    2020 .31439150000000005 .12100587500000001         .112451975
    2021         .254914725         .121079775           .2600728
    2022         .193811375 .20712987499999996         .288426825
    2023         .074134325 .18276125000000001         .110590775
    2024                  0 .06948900000000001                  0
    end

    I am looking forward to hearing from you.

    Kind regards,
    Firangiz Aghayeva
    Last edited by Firangiz Aghayeva; 12 Dec 2024, 13:19.

  • #2
    See the -rowmean()- function of egen, or just note that the mean is the row sum divided by the number of summed variables.

    Code:
    egen wanted1= rowmean(Aus*)
    gen wanted2= (Australasia1 +Australasia2 +Australasia3)/3
    Last edited by Andrew Musau; 12 Dec 2024, 13:32.

    Comment


    • #3
      Dear Andrew,

      Thank you for your quick answer. It worked well.

      Kind regards,
      Firangiz Aghayeva

      Comment

      Working...
      X