My monthly data set looks like the following.
Code:
+---------------------------------------+
  |      date        m0       m1       m2 |
  |---------------------------------------|
  | 15jan2010   1994962   1674.6   8446.1 |
  | 15feb2010   2115182   1699.7   8495.7 |
  | 15mar2010   2079591   1711.9   8492.8 |
  | 15apr2010   2014449   1699.6   8523.1 |
  | 15may2010   2012331   1710.6   8577.8 |
  +---------------------------------------+
I would like to create a data set with four variables : year, m0_avg, m1_avg, and. m2_avg. For example, for the following dataex, the first observation will have 2010 as year and the m* variables will contain corresponding averages of 2010.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float date long m0 double(m1 m2)
18277 1994962 1674.6  8446.1
18308 2115182 1699.7  8495.7
18336 2079591 1711.9  8492.8
18367 2014449 1699.6  8523.1
18397 2012331 1710.6  8577.8
18428 2002433 1731.7    8597
18458 1994298 1724.4  8606.6
18489 1993664 1749.3  8656.9
18520 1961226 1766.5  8687.9
18550 1961720 1780.9    8737
18581 1973139 1826.2  8757.7
18611 2017000 1835.8  8789.7
18642 2047917 1853.4  8826.2
18673 2211605 1872.5  8871.6
18701 2395330 1891.3    8916
18732 2496574 1901.4  8978.2
18762 2567185 1938.7  9029.5
18793 2648548 1956.2  9113.7
18823 2684801 2001.9  9301.6
18854 2657678 2113.8  9515.3
18885 2637680 2128.1  9539.9
18915 2637757 2140.2  9571.5
18946 2605420 2164.1  9612.5
18976 2619586 2163.5  9651.3
19007 2640764 2201.8  9730.6
19038 2694422 2209.9  9773.4
19067 2655219   2229    9818
19098 2639850 2248.8  9872.4
19128 2616477 2257.2  9903.9
19159 2618755 2277.3  9973.8
19189 2647752 2318.5 10046.9
19220 2650750 2348.9   10118
19251 2594909 2390.1 10200.2
19281 2611775 2422.5 10261.5
19312 2646809 2421.2 10320.1
19342 2675945 2460.6 10445.9
19373 2741743 2473.3 10471.7
19404 2845251 2472.4 10468.5
19432 2935036 2480.4   10540
19463 3011737 2515.8 10575.3
19493 3116932 2530.7 10611.5
19524 3201472 2531.4   10666
19554 3290898 2545.8 10721.9
19585 3398930 2552.1 10780.3
19616 3486920 2584.5 10832.7
19646 3589515   2623 10945.6
19677 3684563 2623.1 10953.3
19707 3717450 2664.4 11015.9
19738 3728483 2696.4 11066.4
19769 3833354 2726.4 11148.9
19797 3885877 2754.8 11190.5
19828 3930681 2778.6 11246.9
19858 3911525 2795.2 11314.6
19889 3948691 2829.5 11366.8
19919 3989084 2841.6   11428
19950 4075039 2802.9 11457.3
19981 4049189 2862.2 11492.2
20011 4001451 2868.8 11552.6
20042 3830424 2884.9 11591.7
20072 3934455 2940.7 11670.3
end
format %td date