如何限制插值的最大缺失间隙

How to limit the maximum missing gap of interpolated values

当内插或外推(使用 ipolate 有或没有 epolate)缺失值时,是否可以预先限制要内插(或外推)的缺失间隙大小,或者计算间隙大小 post hoc?

我真正想要的是将最大连续插值(我的数据是每年一次)限制为三年。

你总是可以计算法术的长度,然后有条件地使用 ipolate。这里我使用SSC中的tsspell来计算这样人为引入的长度:

webuse grunfeld, clear 
set seed 2803 
replace invest = . if runiform() < 0.2 
tsset company year 
* need previous -ssc install tsspell- to run this 
tsspell , cond(missing(invest)) 
egen length = max(_seq), by(company _spell) 
tab length 
list company year invest if length >= 3, sepby(company _spell)

     +-------------------------+
     | company   year   invest |
     |-------------------------|
 13. |       1   1947        . |
 14. |       1   1948        . |
 15. |       1   1949        . |
     |-------------------------|
 41. |       3   1935        . |
 42. |       3   1936        . |
 43. |       3   1937        . |
     +-------------------------+

ipolate invest year if length <= 2, by(company) epolate