Coding in Stata:
In my unbalanced weekly panel dataset that spans 5 years, I seek to:
- Fill in weeks that are skipped. I am using the tsfill command for this.
- However, I don't want to fill in weeks if weeks are missing for more than 5 weeks in a row. That's to say, if weeks are missing for 5 weeks or less, we go ahead and generate those missing weeks with zero values; but if weeks are missing for more than 5 weeks, just ignore it.
The second step constitutes a challenge for me. Any suggestions?
sample original:
id week var1 var2 var3
1 1 0 3 0
1 3 1 0 0
1 5 1 0 0
1 20 0 4 0
sample desired:
id week var1 var2 var3
1 1 0 3 0
1 2 0 0 0 (new row!)
1 3 1 0 0
1 4 0 0 0 (new row!)
1 5 1 0 0
1 20 0 4 0