Hello,

I am trying to assign consecutive years of exports to my data. My data consists of Years, products (hs06), countries and export value_CAD . I was able to achieve this originally when I limited my data to only one product in my analysis; example using lentil exports:
Code:
 keep if hs06 == 71340 
drop if year == 1988 | year == 1989 | year == 2016 | year == 2017
tsset country_code year
drop if export_q == 0
gen run = .
by country_code: replace run = cond(L.run == ., 1, L.run + 1)
by country_code: egen maxrun = max(run)
tsspell country_code
by country_code : generate No_Years = _N
the results appeared as :
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float year long hs06 str43 hs06_name str28 country double export_CAD float(run maxrun) byte(_spell _seq _end) float No_Years
1997 71340 "Lentils, dried/shelled" "St Pierre & Miquelon"   46260  1  4 1  1 1  5
2003 71340 "Lentils, dried/shelled" "St Pierre & Miquelon"    2357  1  4 2  1 0  5
2004 71340 "Lentils, dried/shelled" "St Pierre & Miquelon"    3074  2  4 2  2 0  5
2005 71340 "Lentils, dried/shelled" "St Pierre & Miquelon"    4476  3  4 2  3 0  5
2006 71340 "Lentils, dried/shelled" "St Pierre & Miquelon"    1046  4  4 2  4 1  5
1990 71340 "Lentils, dried/shelled" "United States"        1461685  1 26 1  1 0 26
1991 71340 "Lentils, dried/shelled" "United States"        2519920  2 26 1  2 0 26
1992 71340 "Lentils, dried/shelled" "United States"        1745353  3 26 1  3 0 26
1993 71340 "Lentils, dried/shelled" "United States"        1854908  4 26 1  4 0 26
1994 71340 "Lentils, dried/shelled" "United States"        1833379  5 26 1  5 0 26
1995 71340 "Lentils, dried/shelled" "United States"        1844376  6 26 1  6 0 26
1996 71340 "Lentils, dried/shelled" "United States"        3441881  7 26 1  7 0 26
1997 71340 "Lentils, dried/shelled" "United States"        6526230  8 26 1  8 0 26
1998 71340 "Lentils, dried/shelled" "United States"        6028648  9 26 1  9 0 26
1999 71340 "Lentils, dried/shelled" "United States"        3473161 10 26 1 10 0 26
end


When I try the same code without the line
Code:
keep if hs06 == 71340
I get an error repeated time values within panel
r(451);

My objective is to analyse the same trade spell duration for all products at once to get an idea of summary statistics for trade as a whole.

Thank you,