Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Eliminating gaps


From   Cameron Hooper <[email protected]>
To   [email protected]
Subject   Re: st: Eliminating gaps
Date   Sat, 05 Mar 2005 23:58:05 -0500

To answer my own question ...

I just came across the tsfill function. I can use this to do what I want.

drop if x1 >= .
tsfill
save tmpdata
drop if x1 < .
keep id
duplicates drop id, force
merge id using tmpdata
sort id year
drop if _merge == 3
drop _merge

If anyone knows a better solution, please let me know.

Cameron

Cameron Hooper wrote:
When using rollreg on "real" data I learnt that my data cannot contain any gaps. Unfortunately many of my firms have gaps in their data so I need to remove them. Can anyone suggest how to do this? For concreteness here is an example of my problem. In the dataset below I need to remove all observations with id == 1. (In practice I don't know in advance which firms need to be removed, I need to test for gaps.) Also the vast majority of firms in my sample begin with a series of missing values.

. use http://www-personal.umich.edu/~chooper/stata/rrtest2
. list

+----------------------------+
| id y x1 x2 year |
|----------------------------|
1. | 1 12 80 100 1980 |
2. | 1 23 90 93 1981 |
3. | 1 45 100 62 1982 |
4. | 1 13 56 120 1983 |
5. | 1 22 65 90 1984 |
|----------------------------|
6. | 1 21 . 80 1985 |
7. | 1 56 120 12 1986 |
8. | 1 43 90 45 1987 |
9. | 1 29 67 67 1988 |
10. | 1 14 42 55 1989 |
|----------------------------|
11. | 2 34 76 87 1985 |
12. | 2 56 123 34 1986 |
13. | 2 32 56 56 1987 |
14. | 2 67 90 98 1988 |
15. | 2 83 54 54 1989 |
|----------------------------|
16. | 2 45 67 76 1990 |
17. | 2 12 43 23 1991 |
18. | 2 45 56 56 1992 |
19. | 2 23 43 67 1993 |
20. | 2 56 56 120 1994 |
|----------------------------|
21. | 2 34 78 100 1995 |
+----------------------------+

. tsset id year
panel variable: id, 1 to 2
time variable: year, 1980 to 1995

. rollreg y x1 x2, move(5) stub(rr)

Number of gaps in sample: 1

Observations with preceding time gaps
----------------------------------
Record | id year
----------+-----------------------
7 | 1 1986
----------------------------------
sample may not contain gaps
r(198);

Thanks

Cameron

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


--
Cameron Hooper <[email protected]>
Ross School of Business at the University of Michigan
701 Tappan St., Ann Arbor, MI 48109
phone: 734-615-4178 fax: 734-936-0282
Public Key: http://wwwkeys.pgp.net:11371/pks/lookup?op=index&search=0xFCCF8C91
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index