代码拉取完成,页面将自动刷新
同步操作将从 连享会/STATA-DEA 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#delim ;
version 12.0;
*
Creation of Figure 1.
SSC packages used:
bspline, keyby, expgen.
Output graphics files created:
figseq3.eps
*;
clear all;
set scheme sj;
sysuse auto, clear;
keyby foreign make;
desc;
*
Linear spline regression models
*;
local xmin=1500;
local xmax=5100;
local xrange=`xmax'-`xmin';
local intmin=`xrange'/12;
global tflist;
foreach nint of num 1(1)4 {;
local knotdiff=(`xmax'-`xmin')/`nint';
flexcurv, xvar(weight) power(1) refp(`xmin'(`knotdiff')`xmax') gene(ls`nint'_);
desc ls`nint'_*;
regress mpg ls`nint'_*, noconst nohead;
* Compute predicted values *;
preserve;
clear;
set obs `=`xmax'-`xmin'+1';
gene byte nint=`nint';
gene long predseq=_n;
lab var predseq "Prediction sequence number";
gene weight=`xmin'+_n-1;
compress;
flexcurv, xvar(weight) power(1) refp(`xmin'(`knotdiff')`xmax') gene(ls`nint'_);
predict mpghat;
summ predseq weight mpghat, de;
tempfile tfcur;
keyby nint weight;
desc;
save `"`tfcur'"', replace;
global tflist `"$tflist `"`tfcur'"'"';
restore;
};
*
Produce plots
*;
preserve;
expgen =4, copyseq(nint);
lab var nint "Number of intervals between knots";
keyby nint foreign make;
append using $tflist;
gene byte nknot=nint+1;
lab var nknot "number of knots";
keyby nknot foreign make predseq, miss;
desc;
scatter mpg weight || line mpghat weight, sort lpattern(solid) || ,
by(nknot, compact row(2) legend(off))
xlab(`xmin'(`intmin')`xmax', angle(270) grid)
ylab(10(5)45, angle(0))
ytitle("Mileage (mpg)")
xsize(4) ysize(4);
graph export figseq3.eps, replace;
more;
restore;
exit;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。