Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identify missing observations unbalanced panel

    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?

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    You seldom need to balance panels. Most estimators work find in unbalanced panels. Also, if you have xtset your data, you should not use [_n-1] - this will lag across hospitals since _n-1 for the first observation for a given hospital is from a different hospital. Use L. instead. You are not conditioning on "births in that year" - everything is conditioned on the previous year (with the going across hospitals problem I noted).

    I find your if conditions without spaces hard to read - you might consider using spaces.

    Do hospitals change their type? If not, you can just use type!=1.

    Comment


    • #3
      Thank you, Phil Bromiley. I understood what is my mistake. I will reformulate my question to be easier to understand: how do I find missing years in an unbalanced panel by id?

      Comment

      Working...
      X