Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: linear interpolation


From   Rafal Raciborski <rafal.raciborski@emory.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: linear interpolation
Date   Tue, 25 Jul 2006 16:28:50 -0400

scott,

i think i overdid my example. in your case the following should work:

tsset (your vars)
tsfill, full

and if you want to extrapolate to 2005, simply type -edit-, add only one observation (2005 for the year variable) and repeat as above.

--
anyway, to show you the underlying logic of my previous post, let's say you have 5,000 obs total and you need to add 18 new observations to each group identified by state and year. the "manual" way is to type -edit-, go to the very end of your dataset and add the years that you want, e.g. 1981, 1982, ..., 1989, 1991, 1992, ..., 1999, then -tsset- the data and use -tsfill, full-. this works well when you have only few observations to add (as in your case).

my original answer was better suited to adding a large number of years to each group. instead of the "manual" editing, you add a "fake" panel with all the years you want to use (e.g. 1980-2000 or 21 years total) by executing

count
local N = `r(N)' + 21
set obs `N'

now you will have 5,021 obs, and you want to replace observation 5,001 with 1980, 5,002 with 1981, ..., 5,021 with 2000. so in this articular case, you have to use

replace year = -3021 + _n if year==.

and then to -tsset- and -tsfill, full-.

but again, as i have just discovered, stata expands the in-between years automatically so there's no need to follow either of the long approaches.

rafal


================
Rafal Raciborski
Graduate student
Department of Political Science
Emory University
301 Tarbutton Hall
1555 Dickey Drive Atlanta, GA 30322
404-315-7498 (home)
rafal.raciborski@emory.edu
http://www.roofoos.net/


*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index