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

Re: st: Insheeting from an irregularly-dated panel?


From   "Michael S. Hanson" <[email protected]>
To   [email protected]
Subject   Re: st: Insheeting from an irregularly-dated panel?
Date   Sat, 14 Aug 2004 01:50:55 -0400

On Aug 13, 2004, at 4:03 PM, Richard J Stoll wrote:

I think if you use -tsset- to tell Stata it's a quarterly panel, you can
then use -tsfill- to have Stata fill in the observations (with missing
data).
Thanks for the recommendation. In the end, I couldn't see how to get -tsfill- to work in my case. However, I did come up with a solution that might be helpful to others.

Recall the data are organized by row, with column headings of the form "jul1959", "apr1960", "jul1960", "jul1961", etc. -- i.e. multiple quarterly observations for some years, and at least one April (Q2) or July (Q3) observation per year. Below is the code I used to get these data into the desired balanced panel format in Stata:


insheet using datafile.csv
reshape long apr@ jul@, i(id) j(year)
gen x1 = .
rename apr x2
rename jul x3
gen x4 = .
reshape long x, i(id year) j(qtr)
gen date = yq(year,qtr)
format date %tq
drop year qtr
save datafile

The key, which took some experimenting, is to -reshape long- _twice_, and to use both "id" and "year" as i() variables the second time through. That, and some foresight in choosing the variable names x1 - x4.

Finally, to interpolate the missing quarters appears straight-forward:


by id: ipolate x date, gen(x_all) epolate

	Suggested refinements appreciated.

                                        -- Mike

*
*   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