Hi Stata users,
I am using Stata 18 and would like to generate a few variables with minimum and maximum values of the year and sales for a given product and year considering five years before and after the year of consideration. For example, considering product D, the minimum and maximum years are 2014 and 16 respectively while the minimum and maximum sales are 95 and 100 respectively.
Below is an example dataset with the original variables and desired variables
Thanks in advance!
I am using Stata 18 and would like to generate a few variables with minimum and maximum values of the year and sales for a given product and year considering five years before and after the year of consideration. For example, considering product D, the minimum and maximum years are 2014 and 16 respectively while the minimum and maximum sales are 95 and 100 respectively.
Below is an example dataset with the original variables and desired variables
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str1 product int(year sales min_year max_year) byte min_value int max_value "A" 2010 120 2010 2017 70 120 "A" 2011 105 2010 2018 70 120 "A" 2013 100 2010 2018 70 120 "A" 2014 95 2010 2018 70 120 "A" 2016 70 2010 2018 70 120 "A" 2017 85 2010 2018 70 120 "A" 2018 100 2011 2018 70 105 "B" 2012 80 2012 2017 80 110 "B" 2013 90 2012 2017 80 110 "B" 2014 95 2012 2017 80 110 "B" 2015 100 2012 2017 80 110 "B" 2016 110 2012 2017 80 110 "B" 2017 105 2012 2017 80 110 "C" 2010 75 2010 2015 75 120 "C" 2011 100 2010 2016 75 120 "C" 2012 120 2010 2017 75 120 "C" 2013 110 2010 2018 75 120 "C" 2014 105 2010 2019 75 120 "C" 2015 90 2010 2020 75 120 "C" 2016 85 2011 2021 85 120 "C" 2017 115 2012 2022 85 120 "C" 2018 100 2013 2023 85 115 "C" 2019 90 2014 2024 85 115 "C" 2020 95 2015 2025 80 115 "C" 2021 105 2016 2025 80 115 "C" 2022 100 2017 2025 80 115 "C" 2023 100 2018 2025 80 105 "C" 2024 90 2019 2025 80 105 "C" 2025 80 2020 2025 80 105 "D" 2014 95 2014 2016 95 100 "D" 2016 100 2014 2016 95 100 end

Thanks so much for your incredible help!!
Comment