Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | James Bernard <jamesstatalist@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: calculating average in Stata |
Date | Wed, 6 Mar 2013 14:17:05 +0800 |
Hi all, I am trying to calculate average of observations for a variable. This is a panel data... grouped by firms observed over 20 years. Now, I want to calculate average of past three years of a variable to construct a new variable. Firm Year sales -------- ------------ -------------- A 1990 100 A 1991 missing A 1992 200 A 1993 A 1994 A 1995 So i would like to create a new average_3_sales variable that take in year 1993 the average of sales observation from year 1990 to 1992.... What Stata does is that it simply returns missing as 1991 observation is missing. Is there any solution to this? In my research it would be more reasonable to ignore the missing value and calculate average of 100 and 200 which is 150. so the value of the new variable would be 150 for year 1993. I appreciate your help in advance James * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/