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/