Hi Statalist,

I'm trying to fill in missing years for my dataset, but something is off. The original dataset looks like the following (small cut):
Code:
input int year float ccode2 byte type_of_violence
2001   2 3
2015   2 3
2000  20 2
2001  20 2
2004  41 3
2005  41 3
2001  51 2
2002  51 2
2003  51 2
2002  70 3
2004  70 3
2005  70 2
2006  70 2
2007  70 3
2008  70 3
2009  70 3
2010  70 3
2011  70 3
2012  70 3
2013  70 3
2014  70 3
2015  70 3
2016  70 3
I'm trying to "fill in" the missing years. What I need are years 2000-2016 for every "ccode2." For example, for ccode2, I need years 2000-2016 for the observations and so on. The type_of_violence will be "." for the missing years (which I will recode later). I'm trying to merge this dataset to the master dataset later. When I try to add the missing years using the following code:
Code:
use IV_Violent_Events, clear
keep type_of_violence ccode2
expand 17
bysort type_of_violence ccode2:gen year=1999+_n
merge m:1 type_of_violence ccode2 year using IV_Violent_Events.dta
Some of the observations are okay, but some of them are pretty off.
Code:
130 1 2000 1
130 1 2001 1
130 1 2002 1
130 1 2003 1
130 1 2004 1
130 1 2005 1
130 1 2006 1
130 1 2007 1
130 1 2008 3
130 1 2009 1
130 1 2010 1
130 1 2011 1
130 1 2012 1
130 1 2013 1
130 1 2014 1
130 1 2015 1
130 1 2016 1
135 1 2000 3
135 1 2001 3
135 1 2002 1
135 1 2003 3
135 1 2004 3
135 1 2005 1
135 1 2006 1
135 1 2007 3
135 1 2008 3
135 1 2009 1
135 1 2010 1
135 1 2011 1
135 1 2012 1
135 1 2013 3
135 1 2014 1
135 1 2015 3
135 1 2016 1
135 1 2017 1
135 1 2018 1
135 1 2019 1
135 1 2020 1
135 1 2021 1
135 1 2022 1
135 1 2023 1
135 1 2024 1
135 1 2025 1
135 1 2026 1
135 1 2027 1
135 1 2028 1
135 1 2029 1
135 1 2030 1
135 1 2031 1
I'm not entirely sure what the problem is with the code, or with anything else. Thank you in advance for any help, as usual.

Best,
MW