Dear Stata users,
I have an unbalanced panel data set with the following variables: id, year, nobirths, type.
I want to estimate how many hospitals (id) closed if the number of births in that year was less than 300 and the type of hospitals that closed. I do not want to consider for my estimation hospitals of type==1.
In order to do that I am using the following code:
xtset id year
tsfill, full (in order to balance the panel)
gen type2=type[_n-1]
tab nobirths type2 if nobirths[_n-1]<300&year==2014&type[_n-1]!=.&nobirths[_n-1]>0|nobirths[_n-1]<300&year==2014&type2[_n-1]!=1&nobirths[_n-1]>0, missing

However, when I obtain the table, it lists type2==1. I can see that it is because when Stata does "gen type2=type[_n-1]" is only considering the previous observation and not considering that I have panel data. Could anyone help me with a better solution?