Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Standard deviation for trailing x months


From   Nick K <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index