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: 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
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/