全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
2741 3
2022-06-25
今天学习了三次样条插值的原理,以及stata实现,延伸阅读有matlab以及excel的例子,大家感兴趣可以阅读~

帖子也分为三部分:

一、三次样条插值cubic spline interpolation原理
二、三次样条插值的stata实现
1. mata方法
2. csipolate方法
三、延伸阅读

~~~~~~~~~~~~~~
一、三次样条插值cubic spline interpolation原理

简单来说,为了对缺失的数据点进行插值,同时保证我们插值之后的图形在原有的数据点上一阶导数和二阶导数都是相等的【也就是图形看起来是平滑、没有跳点的,我们就需要使用三次样条插值。这也是这种插值方法的优势所在。

原理步骤为,在两个真实数据点之间插值,采用三次多项式拟合的方法进行拟合;其次对于真实数据点在左右两侧拟合的三次多项式加以限制,即两侧一阶导数和二阶导数相等。

这样得到三次多项式拟合的参数。

二、三次样条插值的stata实现
1. mata方法:上传了一个附件do,也可以看下面的文本。
spline.do
大小:(1.14 KB)

只需: 1 个论坛币  马上下载




use "https://www.dropbox.com/s/3y3h39dwbgghusp/stata_spline.dta?dl=0"

mata // This line launches the mata system inside Stata

X = st_data((1,36),"x") // This pulls in the x quarterly markers data.

Y = st_data((1,36),"y") // This pulls in the quarterly y data we want to interpolate between.

XX = st_data(.,"xx") // This pulls in the xx monthly markers we want to interpolate at.

A = spline3(X,Y) // This generates the cubic spline coefficients matrix, and stores it in A.

B = spline3eval(A,XX) // This performs the interpolation, and store the values in B.

st_store(.,"yy",B) // This pushes the inpolated figures in B back into the yy variable in Stata.

end



2. csipolate方法:
ssc install csipolate

csipolate creates newvar by averaging non-missing values of yvar and using natural cubic spline interpolation of missing values of yvar, given xvar. That is,  provided that xvar is not missing,



三、延伸阅读

https://columbiaeconomics.com/2012/06/06/stata-do-file-for-cubic-spline-interpolation/





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2022-6-26 10:51:50
谢谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2022-6-27 05:36:13
谢谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2022-9-4 22:00:36
谢谢分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群