Bookmark and Share

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

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

st: Calculating rolling averages

From   William Hauser <[email protected]>
To   [email protected]
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

Will Hauser

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index