Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: period averages

From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: period averages
Date   Thu, 28 Jul 2005 08:43:33 -0400

Joana said

I have a panel of 32 countries and 16 years. I have used Excel to
calculate 4-year averages for each countries. Is it possible to do
this in Stata? So far, I have only found commands for calculating
moving averages, which is NOT what I want.

Three ways:

define a group variable that identifies quadrennia, and egen mean from that.
bys country: g quad = int((_n-1)/4)+1
egen qavg =mean(data), by(cty3 quad)

use mvsumm which does calculate overlapping stats and throw away the values for years 1,2,3, or set them equal to the value for period 4 (_n==_N in a by-group).

define the group variable as above and collapse on it; that changes your data set into 32 countries and 4 quadrennia, if that is what you want.

Kit Baum, Boston College Economics

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index