Hi All,

I am having some trouble with understanding the xtset command even after reading through some past posts and the help section on it. I want to use the leads and lags function in a regression, but am having trouble understanding how the time variables are set. I thought that by having an encoded variable for all of the different products I have, I could use that as the panalvar and then I could use the "year" variable for timevar. Unfortunately, I am getting the error "Repeated time values within panel help." I have my data posted below--please let me know if you have any suggestions for fixing this issue so that I could use the lead/lag functionality with an assigned timevar.

Many thanks,
Jim


Code:
xtset id_test5 year
repeated time values within panel
r(451);

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str14 country str43 prod int year byte type float(percent after2016_soft_drink) long id_test5 byte(_Iyear_2015 _Iyear_2016 _Iyear_2017 _Iyear_2018 _Iyear_2019 _Iyear_2020)
"UK"      "Asian Speciality Drinks" 2014 0         100 0 1 0 0 0 0 0 0
"UK"      "Asian Speciality Drinks" 2015 0         100 0 1 1 0 0 0 0 0
"UK"      "Asian Speciality Drinks" 2016 0         100 0 1 0 1 0 0 0 0
"UK"      "Asian Speciality Drinks" 2017 0         100 0 1 0 0 1 0 0 0
"UK"      "Asian Speciality Drinks" 2018 0         100 0 1 0 0 0 1 0 0
"UK"      "Asian Speciality Drinks" 2019 0         100 0 1 0 0 0 0 1 0
"UK"      "Asian Speciality Drinks" 2020 0         100 0 1 0 0 0 0 0 1
"UK"      "Baby Food"               2014 0    90.39353 0 2 0 0 0 0 0 0
"UK"      "Baby Food"               2014 1    9.606463 0 2 0 0 0 0 0 0
"Ireland" "Baby Food"               2014 0    88.76344 0 2 0 0 0 0 0 0
"Ireland" "Baby Food"               2014 1    11.23656 0 2 0 0 0 0 0 0
"Ireland" "Baby Food"               2015 1   11.146546 0 2 1 0 0 0 0 0
"UK"      "Baby Food"               2015 1    9.811398 0 2 1 0 0 0 0 0
"Ireland" "Baby Food"               2015 0    88.85345 0 2 1 0 0 0 0 0
"UK"      "Baby Food"               2015 0     90.1886 0 2 1 0 0 0 0 0
"UK"      "Baby Food"               2016 1    9.562346 0 2 0 1 0 0 0 0
"Ireland" "Baby Food"               2016 0    88.91432 0 2 0 1 0 0 0 0
"UK"      "Baby Food"               2016 0    90.43765 0 2 0 1 0 0 0 0
"Ireland" "Baby Food"               2016 1   11.085676 0 2 0 1 0 0 0 0
"UK"      "Baby Food"               2017 0    90.41187 0 2 0 0 1 0 0 0
"UK"      "Baby Food"               2017 1    9.588136 0 2 0 0 1 0 0 0
"Ireland" "Baby Food"               2017 0    88.97702 0 2 0 0 1 0 0 0
"Ireland" "Baby Food"               2017 1   11.022975 0 2 0 0 1 0 0 0
"UK"      "Baby Food"               2018 0    90.35996 0 2 0 0 0 1 0 0
"UK"      "Baby Food"               2018 1    9.640036 0 2 0 0 0 1 0 0
"Ireland" "Baby Food"               2018 0    89.05828 0 2 0 0 0 1 0 0
"Ireland" "Baby Food"               2018 1   10.941716 0 2 0 0 0 1 0 0
"UK"      "Baby Food"               2019 1    9.680828 0 2 0 0 0 0 1 0
"UK"      "Baby Food"               2019 0    90.31917 0 2 0 0 0 0 1 0
"Ireland" "Baby Food"               2019 0    89.15837 0 2 0 0 0 0 1 0
"Ireland" "Baby Food"               2019 1    10.84163 0 2 0 0 0 0 1 0
"Ireland" "Baby Food"               2020 0    89.23181 0 2 0 0 0 0 0 1
"UK"      "Baby Food"               2020 1     9.54126 0 2 0 0 0 0 0 1
"UK"      "Baby Food"               2020 0    90.45874 0 2 0 0 0 0 0 1
"Ireland" "Baby Food"               2020 1   10.768182 0 2 0 0 0 0 0 1
"Ireland" "Baked Goods"             2014 0    96.40752 0 3 0 0 0 0 0 0
"UK"      "Baked Goods"             2014 2 .0010265667 0 3 0 0 0 0 0 0
"UK"      "Baked Goods"             2014 0    93.20556 0 3 0 0 0 0 0 0
"Ireland" "Baked Goods"             2014 2 .0011187661 0 3 0 0 0 0 0 0
"UK"      "Baked Goods"             2014 1    6.793414 0 3 0 0 0 0 0 0
"Ireland" "Baked Goods"             2014 1     3.59136 0 3 0 0 0 0 0 0
"UK"      "Baked Goods"             2015 1    6.942422 0 3 1 0 0 0 0 0
"Ireland" "Baked Goods"             2015 2 .0011032855 0 3 1 0 0 0 0 0
"UK"      "Baked Goods"             2015 0    93.05656 0 3 1 0 0 0 0 0
"Ireland" "Baked Goods"             2015 1   3.5733924 0 3 1 0 0 0 0 0
"UK"      "Baked Goods"             2015 2   .00101654 0 3 1 0 0 0 0 0
"Ireland" "Baked Goods"             2015 0    96.42551 0 3 1 0 0 0 0 0
"UK"      "Baked Goods"             2016 1     7.13343 0 3 0 1 0 0 0 0
"Ireland" "Baked Goods"             2016 1    3.575801 0 3 0 1 0 0 0 0
"UK"      "Baked Goods"             2016 0    92.86558 0 3 0 1 0 0 0 0
"Ireland" "Baked Goods"             2016 0    96.42312 0 3 0 1 0 0 0 0
"UK"      "Baked Goods"             2016 2 .0009982894 0 3 0 1 0 0 0 0
"Ireland" "Baked Goods"             2016 2 .0010741096 0 3 0 1 0 0 0 0
"Ireland" "Baked Goods"             2017 1    3.590291 0 3 0 0 1 0 0 0
"UK"      "Baked Goods"             2017 1    7.161265 0 3 0 0 1 0 0 0
"Ireland" "Baked Goods"             2017 2 .0010554073 0 3 0 0 1 0 0 0
"Ireland" "Baked Goods"             2017 0    96.40865 0 3 0 0 1 0 0 0
"UK"      "Baked Goods"             2017 0    92.83774 0 3 0 0 1 0 0 0
"UK"      "Baked Goods"             2017 2 .0009987949 0 3 0 0 1 0 0 0
"UK"      "Baked Goods"             2018 2  .001007963 0 3 0 0 0 1 0 0
"UK"      "Baked Goods"             2018 0    92.77442 0 3 0 0 0 1 0 0
"Ireland" "Baked Goods"             2018 2 .0010359032 0 3 0 0 0 1 0 0
"UK"      "Baked Goods"             2018 1    7.224566 0 3 0 0 0 1 0 0
"Ireland" "Baked Goods"             2018 0     96.3924 0 3 0 0 0 1 0 0
"Ireland" "Baked Goods"             2018 1   3.6065545 0 3 0 0 0 1 0 0
"UK"      "Baked Goods"             2019 0    92.65563 0 3 0 0 0 0 1 0
"Ireland" "Baked Goods"             2019 0    96.44029 0 3 0 0 0 0 1 0
"Ireland" "Baked Goods"             2019 1    3.558706 0 3 0 0 0 0 1 0
"UK"      "Baked Goods"             2019 2 .0010218396 0 3 0 0 0 0 1 0
"Ireland" "Baked Goods"             2019 2 .0010000111 0 3 0 0 0 0 1 0
"UK"      "Baked Goods"             2019 1    7.343345 0 3 0 0 0 0 1 0
"UK"      "Baked Goods"             2020 1    7.259027 0 3 0 0 0 0 0 1
"UK"      "Baked Goods"             2020 2 .0010701094 0 3 0 0 0 0 0 1
"UK"      "Baked Goods"             2020 0    92.73991 0 3 0 0 0 0 0 1
"Ireland" "Baked Goods"             2020 2 .0010402437 0 3 0 0 0 0 0 1
"Ireland" "Baked Goods"             2020 0    96.34309 0 3 0 0 0 0 0 1
"Ireland" "Baked Goods"             2020 1    3.655866 0 3 0 0 0 0 0 1
"Ireland" "Bottled Water"           2014 1   .24856895 0 4 0 0 0 0 0 0
"UK"      "Bottled Water"           2014 2 .0021144135 0 4 0 0 0 0 0 0
"Ireland" "Bottled Water"           2014 0    99.74924 0 4 0 0 0 0 0 0
"UK"      "Bottled Water"           2014 0    99.75207 0 4 0 0 0 0 0 0
"Ireland" "Bottled Water"           2014 2 .0021854744 0 4 0 0 0 0 0 0
"UK"      "Bottled Water"           2014 1    .2458168 0 4 0 0 0 0 0 0
"UK"      "Bottled Water"           2015 0    99.73034 0 4 1 0 0 0 0 0
"UK"      "Bottled Water"           2015 2 .0022652892 0 4 1 0 0 0 0 0
"UK"      "Bottled Water"           2015 1    .2673995 0 4 1 0 0 0 0 0
"Ireland" "Bottled Water"           2015 0    99.75259 0 4 1 0 0 0 0 0
"Ireland" "Bottled Water"           2015 2    .0021185 0 4 1 0 0 0 0 0
"Ireland" "Bottled Water"           2015 1       .2453 0 4 1 0 0 0 0 0
"Ireland" "Bottled Water"           2016 2 .0020976719 0 4 0 1 0 0 0 0
"UK"      "Bottled Water"           2016 0    99.71962 0 4 0 1 0 0 0 0
"UK"      "Bottled Water"           2016 2 .0023132558 0 4 0 1 0 0 0 0
"UK"      "Bottled Water"           2016 1   .27807018 0 4 0 1 0 0 0 0
"Ireland" "Bottled Water"           2016 1    .2415012 0 4 0 1 0 0 0 0
"Ireland" "Bottled Water"           2016 0     99.7564 0 4 0 1 0 0 0 0
"UK"      "Bottled Water"           2017 1   .29721242 0 4 0 0 1 0 0 0
"UK"      "Bottled Water"           2017 0    99.70034 0 4 0 0 1 0 0 0
"Ireland" "Bottled Water"           2017 0    99.76518 0 4 0 0 1 0 0 0
"Ireland" "Bottled Water"           2017 2 .0020299621 0 4 0 0 1 0 0 0
"UK"      "Bottled Water"           2017 2  .002451064 0 4 0 0 1 0 0 0
end
label values type Type
label def Type 0 "Control", modify
label def Type 1 "Sugars", modify
label def Type 2 "Artificial sugars", modify
label values id_test5 id_test5
label def id_test5 1 "Asian Speciality Drinks", modify
label def id_test5 2 "Baby Food", modify
label def id_test5 3 "Baked Goods", modify
label def id_test5 4 "Bottled Water", modify