Dear all

I am trying to calculate the average bond maturity over the preceding three months as an instrumental variable in my analysis. it is worth noting that my data is unbalanced and one firm_id can have multiple observations within one year. Therefore, declaring the data as a panel using firm_id would not work. Therefore,
My command is :
xtset observations_num Year

gen matruity_moveavrg=(F1.maturity+maturity+L1.maturit y)/3

the generated new variable is missing and the code is incorrect.
any help is highly appreciated in proving the correct code.