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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: Calculating rolling averages


From   William Hauser <whauseriii@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Calculating rolling averages
Date   Fri, 9 Mar 2012 12:05:17 -0500

Hi all,
I am attempting to calculate the percentage of cases handled by a
judge that meet some criterion (e.g. being a violent offender).  The
data cover 13 years so obviously the averages for each judge change
overtime.  My first thought was the following command:

bysort id date:  egen pct=mean(offense_9) if date[_n]>date

I had hoped that Stata would calculate the average based only on cases
with a earlier (smaller) date but instead the command results in all
missing values because date[1]<date[2] and so forth.

Another thought was to use the rolling command (which I'm not sure how
to do anyways) but this requires the use of tsset.  When I tsset my
data I get an error, "repeated time values within panel" presumably
because each judge handles multiple cases a day.

I imagine this is probably a simple matter of syntax but I am in well
over my head.  Any insight you could provide would be greatly
appreciated.

Will Hauser

*
*   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