Dear all,

I am working with a matched employer-employee dataset from Brazil in which each observation represents a given month-year for each worker. The dataset is like:
year month counter wage
2017 11 11 0
2017 12 12 0
2018 1 13 5,000
2018 2 14 5,000
2018 3 15 0
2018 4 16 5,500
2018 5 17 0

I would like to create a variable that indicates the first month (based on the variable 'counter') in which each worker had a positive wage and the last month in which he/she had positive wage, i.e, I would like the dataset to be like the following:
year month counter wage first_time last_time
2017 11 11 0 13 16
2017 12 12 0 13 16
2018 1 13 5,000 13 16
2018 2 14 5,000 13 16
2018 3 15 0 13 16
2018 4 16 5,500 13 16
2018 5 17 0 13 16

Could you help me to find a solution for that?

Thank you very much!

Below I provide the code for importing the example dataset into Stata:

clear
input year month counter wage
2017 11 11 0
2017 12 12 0
2018 1 13 5000
2018 2 14 5000
2018 3 15 0
2018 4 16 5500
2018 5 17 0
end