Hello everyone,

I would like to replace the missing values (leftceo) by the last given observation-year, to calculate the tenure of a CEO.
This means in my case that the three missing values should be replaced by "2020".

I tried the following command: "bysort gvkey_year: replace leftceo=max(YEAR) if missing(leftceo)". Unfortunately Stata states that it is an invalid syntax.

Could someone help me, please?

Thanks in advance!


Array