Dear all,
I am currently trying to build a variable which counts how many nonviolent_protest_episodes occured during the last 10 years when a certain condition is met (uturn==1). My data structure is country-year and looks the following (here an example for Bolivia):
I tried to code something like: egen u_turn_protest_count = total(nonviolent_protest_episodes) if uturn == 1 & inrange (year, year -9, year)
Stata tells the error code that inrange is not found which is expectable since I do not specify the years. My problem is that U-Turns happen in different times and countries and every time that happens I would like "to look 10 years back" and calculate how many nonviolent_protest_episodes occured before the U-Turn started. Unfortunately, I have not found an answer here in this forum or anywhere else in the internet. I use Stata 17.0
I would greatly appreciate if someone could help me out.
Many thanks in advance,
Alexander
I am currently trying to build a variable which counts how many nonviolent_protest_episodes occured during the last 10 years when a certain condition is met (uturn==1). My data structure is country-year and looks the following (here an example for Bolivia):
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str32 country_name int year float(uturn nonviolent_protest_episodes) "Bolivia" 2001 0 0 "Bolivia" 2002 0 0 "Bolivia" 2003 0 1 "Bolivia" 2004 0 1 "Bolivia" 2005 0 1 "Bolivia" 2006 1 0 "Bolivia" 2007 1 0 "Bolivia" 2008 1 0 "Bolivia" 2009 1 0 "Bolivia" 2010 1 0 "Bolivia" 2011 1 0 "Bolivia" 2012 1 0 "Bolivia" 2013 1 0 "Bolivia" 2014 1 0 "Bolivia" 2015 1 0 "Bolivia" 2016 1 0 "Bolivia" 2017 1 0 "Bolivia" 2018 1 0 "Bolivia" 2019 1 2 "Bolivia" 2020 1 0 "Bolivia" 2021 1 0 "Bolivia" 2022 1 0 "Bolivia" 2023 1 0 end
Stata tells the error code that inrange is not found which is expectable since I do not specify the years. My problem is that U-Turns happen in different times and countries and every time that happens I would like "to look 10 years back" and calculate how many nonviolent_protest_episodes occured before the U-Turn started. Unfortunately, I have not found an answer here in this forum or anywhere else in the internet. I use Stata 17.0
I would greatly appreciate if someone could help me out.
Many thanks in advance,
Alexander
Comment