[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Insheeting from an irregularly-dated panel?
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
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.
then use -tsfill- to have Stata fill in the observations (with missing
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
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 -
Finally, to interpolate the missing quarters appears straight-forward:
by id: ipolate x date, gen(x_all) epolate
Suggested refinements appreciated.
* For searches and help try: