Hello,
I am trying to create a variable equal to the number of years of data available for each observation. I have a monthly dataset of agencies spanning 6 years. I used the following code but it's not working. There could be a way easier way of doing this too. Can anyone help me?
Thank you very much.
Tom
I am trying to create a variable equal to the number of years of data available for each observation. I have a monthly dataset of agencies spanning 6 years. I used the following code but it's not working. There could be a way easier way of doing this too. Can anyone help me?
Code:
gen identifier = _n levelsof identifier, local(identifierlvls) gen numberofyears=. foreach l of local identifierlvls { tab year if identifier==`l' matrix yearsmat`l' = r(r) replace numberofyears=yearsmat`l' if identifier==`l' }
Tom
Comment