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

st: question on looping


From   Aaron Li <ylacademics@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: question on looping
Date   Tue, 11 Oct 2005 22:33:13 -0500

Hi,

Is there a smart way to calculate the standard deviation of var1 for
each id in each year, based on past 5 years' data. For example, for id
18 in year 1996, i want to calculate the st dev of var1 for the past 5
years 1991-1995 (here 3 data points). then, for id 18 in year 1998, i
want the st dev for var1 for the past 5 years 1993-1997; and then year
2000; and next id, and so on.... i have a large number of id's and
year's. many thanks,  aaron.

id	year	var1
18	1993	5.684
18	1993	18.80
18	1994           6.482
18	1996            5.99
18               1998            9.887
18	1998	78.52
27	2000	53.51
41	1983	1.969
71	1997	9.216
74	1995	1.758
74	1997	9.501
74	2001	15.89

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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