I have a survey data set (panel). In the dataset, I have a variable in which few numbers are wrongly entered. For example, if an establishment has started in a particular year (starting_year), the starting_year is not supposed to vary. In few of the years, the starting_year has been entered as 0. I have used the following commands to replace the wrongly entered values with the correct values but I am not able to replace it:

egen tag = tag(panel_id starting_year)

egen ndistinct = total(tag), by(panel_id)

bysort panel_id (starting_year) : replace starting_year = starting_year[_N] if missing(inityr) & ndistinct == 1

STATA result
(0 real changes made)

An analogous data file is attached. I would really appreciate the help.