楼主: jeffic
2007 7

请问:怎样在全样本中挑出幸存者样本 [推广有奖]

  • 1关注
  • 11粉丝

已卖:495份资源

博士生

96%

还不是VIP/贵宾

-

威望
0
论坛币
1649 个
通用积分
2.0435
学术水平
7 点
热心指数
9 点
信用等级
4 点
经验
9504 点
帖子
268
精华
0
在线时间
423 小时
注册时间
2009-1-19
最后登录
2021-12-24

楼主
jeffic 在职认证  发表于 2013-4-9 14:59:47 |AI写论文
3论坛币
全样本的结构是:

id  year  leverage
1  1994  a
1  1995  b
1  1996  c
...  ...
2 1994  d
2 1995  e
...  ...
要达到的目的是:从全样本中挑选出幸存者样本,使得幸存者样本中的每一个id在至少连续10年内的leverage的值不等于零(也就是说选出至少连续存活了10年的id)

谢谢了哇!


最佳答案

ziyenano 查看完整内容

data ex; input id year leverage $; cards; 1 1992 a 1 1993 b 1 1995 c 1 1996 d 1 1997 0 1 1998 e 2 1992 a 2 1993 b 2 1994 c 2 1996 d 2 1995 e 2 1997 f 2 1997 a 2 1998 b 2 1999 c 3 1992 a 3 1993 b 3 1994 0 3 1996 e 3 1995 e 3 1997 f ; run; proc sort data=ex; by id year; run; data ex1(keep=id); symbol=1; count=0; do until(last.id); set ex; ...
关键词:幸存者 Leverage Lever Ever Leve 结构 样本 幸存者

沙发
ziyenano 发表于 2013-4-9 14:59:48
data ex;
input id year leverage $;
cards;
1 1992  a
1 1993  b
1 1995  c
1 1996  d
1 1997  0
1 1998  e
2 1992  a
2 1993  b
2 1994  c
2 1996  d
2 1995  e
2 1997  f
2 1997  a
2 1998  b
2 1999  c
3 1992  a
3 1993  b
3 1994  0
3 1996  e
3 1995  e
3 1997  f
;
run;

proc sort data=ex;
by id year;
run;

data ex1(keep=id);
symbol=1;
count=0;
do until(last.id);
set ex;
by id;
if first.id then continue;
if year-lag(year)=1 and leverage ne "0" then symbol+1;
else symbol=1;
count+(symbol>=5);/*这里测试选择连续存活5年的id,改为10即可*/
if last.id and count>0 then output;
end;
;
run;



藤椅
zhengbo8 发表于 2013-4-9 16:00:03
数据文件,附件。

板凳
pobel 在职认证  发表于 2013-4-9 16:35:42
data wanted;
   do until(last.id);
      set have;
          where leverage ne 0;
      by id year;
          y_diff=dif(year);
          if first.id then do; y_diff=.; count=0; end;
          if (first.id or y_diff=1) then count=count+1;
          else if y_diff>1 then count=1;
          if count>=10 then flag=1;
        end;
        if flag=1;
        keep id;
run;
已有 2 人评分威望 学术水平 热心指数 信用等级 收起 理由
星野 + 1 感谢您长久以来对论坛的支持,版主“webgu”.
a6566792 + 1 + 1 + 1 热心帮助其他会员

总评分: 威望 + 1  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

和谐拯救危机

报纸
jeffic 在职认证  发表于 2013-4-9 17:35:50
ziyenano 发表于 2013-4-9 16:32
data ex;
input id year leverage $;
cards;
OK啦 灰常感谢~~

地板
daiyingbo 发表于 2013-4-9 17:55:38
噢噢噢噢噢噢
谢谢的

7
chaosxiao 发表于 2013-4-11 11:25:09
data ex;
input id year leverage $;
cards;
1 1992  a
1 1993  b
1 1995  c
1 1996  d
1 1997  0
1 1998  e
2 1992  a
2 1993  b
2 1994  c
2 1996  d
2 1995  e
2 1997  f
2 1997  a
2 1998  b
2 1999  c
3 1992  a
3 1993  b
3 1994  0
3 1996  e
3 1995  e
3 1997  f
;
run;

proc sort data=ex;
by id year;
run;
data a;
set ex;
by id year;
retain live;
if first.id then live=0;
else live+1;
if last.id and live ge 5;

keep id live;
run;

8
chaosxiao 发表于 2013-4-11 11:27:31
proc sort data=ex nodupkey;
by id year;
run;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-22 16:03