Hi, I want to calculate the cumulative frequency (new var: cum_freq) per state for each observation of the 5 years prior to the observation using the total_freq.
It would be perfect if the code would be easily adjustable for a different time period (e.g. 3 years).
would that code be working:
It would be perfect if the code would be easily adjustable for a different time period (e.g. 3 years).
would that code be working:
Code:
rangestat (sum) total_freq, by(State) interval(Year -5 -1)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int Year str2 State float total_freq 1980 "AL" 1 1981 "AL" 1 1982 "AL" 2 1983 "AL" 3 1984 "AL" 0 1985 "AL" 3 1986 "AL" 1 1987 "AL" 0 1988 "AL" 1 1989 "AL" 1 1990 "AL" 0 1991 "AL" 1 1992 "AL" 1 1993 "AL" 2 1994 "AL" 2 1995 "AL" 3 1996 "AL" 0 1997 "AL" 0 1998 "AL" 3 1999 "AL" 3 2000 "AL" 2 2001 "AL" 0 2002 "AL" 3 2003 "AL" 3 2004 "AL" 1 2005 "AL" 4 2006 "AL" 3 2007 "AL" 2 2008 "AL" 4 2009 "AL" 3 2010 "AL" 0 2011 "AL" 5 2012 "AL" 3 2013 "AL" 1 2014 "AL" 2 2015 "AL" 2 2016 "AL" 3 2017 "AL" 8 2018 "AL" 4 2019 "AL" 3 2020 "AL" 9 2021 "AL" 6 2022 "AL" 3 2023 "AL" 6 1980 "AK" 0 1981 "AK" 0 1982 "AK" 0 1983 "AK" 0 1984 "AK" 0 1985 "AK" 0 1986 "AK" 0 1987 "AK" 0 1988 "AK" 0 1989 "AK" 0 1990 "AK" 0 1991 "AK" 0 1992 "AK" 0 1993 "AK" 0 1994 "AK" 0 1995 "AK" 0 1996 "AK" 0 1997 "AK" 0 1998 "AK" 0 1999 "AK" 0 2000 "AK" 0 2001 "AK" 0 2002 "AK" 1 2003 "AK" 1 2004 "AK" 0 2005 "AK" 0 2006 "AK" 1 2007 "AK" 1 2008 "AK" 0 2009 "AK" 1 2010 "AK" 0 2011 "AK" 0 2012 "AK" 0 2013 "AK" 0 2014 "AK" 0 2015 "AK" 1 2016 "AK" 0 2017 "AK" 0 2018 "AK" 0 2019 "AK" 1 2020 "AK" 0 2021 "AK" 0 2022 "AK" 1 2023 "AK" 0 1980 "AZ" 0 1981 "AZ" 0 1982 "AZ" 0 1983 "AZ" 2 1984 "AZ" 0 1985 "AZ" 0 1986 "AZ" 0 1987 "AZ" 0 1988 "AZ" 0 1989 "AZ" 0 1990 "AZ" 0 1991 "AZ" 0 end
Comment