Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Standard deviation for trailing x months


From   Nick K <coffeemug.nick@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Standard deviation for trailing x months
Date   Tue, 29 Nov 2011 16:21:10 +0100

Hi,

I have panel data with observations per firm for a number of months. I
want to calculate the standard deviation of returns over 60 months
preceding the sample year. For example, to calculate the value for
1993 I want to calculate the sd for period between Jan 1988 and Dec
1992.

I know how to calculate it for all years for 1 firm:
bys company date: egen sd=sd(return)

Doing it for subsamples within each firm is harder. I can imagine that
if I generated a group variable for each "block" (e.g. observations
between Jan 1988 and Dec 1992 are 1, next block is 2 and so on) I
could use the above command, but I don't know how to generate these
groups either.

Thank you
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index