Joker
Joker

Reputation: 1

Unbalanced panel dataset

I am trying to construct a balanced dataset in Stata using xtbalance command with range() option. I have data for the years 2010-2013 and 2016. But the survey was not conducted in the years 2014 and 2015. Running xtbalance, range(2010 2016) fails as xtbalance does not realize that 2014 and 2015 are not there, and basically no observations are left in the constructed panel dataset.

How should I implement this? Is it possible to construct a balanced dataset for the years 2010-2013 and 2016? What command in Stata would allow me to do this?

Upvotes: 0

Views: 1108

Answers (1)

Nick Cox
Nick Cox

Reputation: 37208

This is more statistics than Stata, but here goes.

If you don't have data for 2014 and 2015, how is Stata expected to find them or estimate them? Only by imputation or interpolation, which would be a massive stretch.

You can get a balanced dataset with tsfill, but it's hard to see any point to that.

You could relabel years 2010-13 and 2016 as say "waves" 1 2 3 4 5, but that ignores the crucial gap.

Best to see and state the problem for what it is, a gap beyond your control.

xtbalance is from SSC, as you are asked to explain. (I see that it includes without permission or documentation code that I wrote, but that's a small deal.)

* Example generated by -dataex-. For more info, type help dataex
clear
input float(id year whatever)
1 2010  1
1 2011  2
1 2012  3
1 2013  4
1 2016  5
2 2010  7
2 2011  8
2 2012  9
2 2013 10
2 2016 12
end

tsset id year 
tsfill 

list, sepby(id)

     +----------------------+
     | id   year   whatever |
     |----------------------|
  1. |  1   2010          1 |
  2. |  1   2011          2 |
  3. |  1   2012          3 |
  4. |  1   2013          4 |
  5. |  1   2014          . |
  6. |  1   2015          . |
  7. |  1   2016          5 |
     |----------------------|
  8. |  2   2010          7 |
  9. |  2   2011          8 |
 10. |  2   2012          9 |
 11. |  2   2013         10 |
 12. |  2   2014          . |
 13. |  2   2015          . |
 14. |  2   2016         12 |
     +----------------------+


Upvotes: 1

Related Questions