Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Is there a quick way of customizing linear interpolation?
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
st: RE: Is there a quick way of customizing linear interpolation?
Date
Thu, 22 Jul 2010 18:45:48 +0100
-ipolate- with -if- is, I guess, not the answer here. I think you can
hardly include all you want and exclude all you want.
A better answer is
1. -ipolate- any way.
2. Identify spells of missing values and reverse the -ipolate- of
missings for spells of three or more missings. -tsspell- from SSC is one
tool for this.
You explain your problem clearly but don't say much about your data.
How to use -tsspell- from SSC for #2 depends on your set-up. Here are
three examples.
(a) Data are in sequence, but no time variable or panel identifier.
gen long time = _n
* continue with code for (b)
(b) A time variable is defined, but no panel identifier.
tsset time
ipolate oldvar time, gen(newvar)
tsspell , cond(missing(oldvar))
egen length = max(_seq), by(_spell)
replace newvar = . if length > 2
(c) A time variable and panel identifier.
tsset id time
by id: ipolate oldvar time, gen(newvar)
tsspell, cond(missing(oldvar))
egen length = max(_seq), by(id _spell)
replace newvar = . if length > 2
See also
1. -cipolate- and -csipolate- from SSC.
2. dm0029 . . . . . . . . . . . . . . Speaking Stata: Identifying
spells
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
J. Cox
Q2/07 SJ 7(2):249--265 (no
commands)
shows how to handle spells with complete control over
spell specification
(FYI, "wanna" remains valleyspeak, not correct English!)
Nick
[email protected]
Halit Akturk
I am a Stata 11 user. Is there any way to customize ipolate command in
Stata in a quick way? I like to do linear interpolation but I have a
constraint. I like to fill in the missing observations as long as the
missing observations happen at most 2 times consequtively. For
instance, say I have the following data where "." stands for missing
observation:
1, 4, 5, ., 7, ., ., ., 9, ., ., 15.
The usual Stata's ipolate gives: 1, 4, 5, 6, 7, 7.5, 8, 8.5, 9,11, 13,
15.
The ipolate will fill in all of the missing observations. I don't
wanna do that. I like to fil in the missing values as long as they are
at most 2 observations consequtively. So the customized linear
interpolation (which is what I am looking for) should give me the
following result:
1, 4, 5, 6, 7, ., ., ., 9, 11, 13, 15. I hope I explained what I am
looking for well.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/