楼主: funwin
8213 37

有谁知道 如何用宏语言实现bootstrap resampling? [推广有奖]

31
funwin 发表于 2010-4-9 22:01:23
以下只是我个人的一些思路,希望高手能够指教一下!

Proc sql;


Create table newdata (drop=_1-_100) as


Select *, pre+_1 as y1,


pre+_2 as y2,



………


pre+_100 as y100,

From originaldata;

Quit;

怎么能把这个100步,用loop或宏语句表示呢?

Proc reg data=newdata;


Model y1=x1 x2 x3 x4


By co;

Run;

……….

Proc reg data=newdata;


Model y100=x1 x2 x3 x4;


By co;

Run;

这里也涉及到怎么用loop或宏语句表示.还有如何把我要的每家公司的每次sampleintercept, t value of intercept显示出来?用ods语句?

Data pvalue;


Count=0;


Numiters=100;


If t_new>t_obs then count=count+1;



End;





p_value=count/numiters;

Run;

用这个语句能够计算出我所要的p-value吗?

32
jingju11 发表于 2010-4-10 00:34:57
31# funwin
什么是pre?

I see, the PRE is the old Y without including intercept

33
funwin 发表于 2010-4-10 02:51:54
yeah, pre is just a variable, equals to b*X1+c*X2+d*X3..., that's right, you got it,

34
jingju11 发表于 2010-4-10 03:13:20
funwin 发表于 2010-4-9 22:01
以下只是我个人的一些思路,希望高手能够指教一下!

Proc sql;



Create table newdata (drop=_1-_100) as



Select *, pre+_1 as y1,



pre+_2 as y2,




………



pre+_100 as y100,


From originaldata;


Quit;


怎么能把这个100步,用loop或宏语句表示呢?

Proc reg data=newdata;



Model y1=x1 x2 x3 x4



By co;


Run;


……….


Proc reg data=newdata;



Model y100=x1 x2 x3 x4;



By co;


Run;


这里也涉及到怎么用loop或宏语句表示.还有如何把我要的每家公司的每次sampleintercept, t value of intercept显示出来?用ods语句?

Data pvalue;



Count=0;



Numiters=100;



If t_new>t_obs then count=count+1;




End;






p_value=count/numiters;


Run;


用这个语句能够计算出我所要的p-value吗?

  1. %macro RegMcr;
  2. data new;
  3.   set yours;
  4.   array _{100}; array newY{100};
  5.   do i = 1 to 100;
  6.     newY[i] = pre+_[i];
  7.   end;
  8. run;
  9.    proc reg data = new outest=est1(keep = sex _model_ _type_ _depvar_ Intercept where = (_type_ in ('PARMS', 'T'))) tableout noprint;
  10.       by sex;
  11.   %do i = 1 %to 100;
  12.        newY%sysfunc(putn(&i, z5.)): model  newY&i = x1-x4;
  13.      %end;
  14. proc transpose data = est1 out = est2(rename = (PARMS = Intercept) drop = _name_ _label_);
  15.   id _type_;
  16.   var intercept;
  17.   by co _model_;
  18. run;
  19. %mend RegMcr;
  20. %RegMcr
  21.   ;
复制代码

35
jingju11 发表于 2010-4-10 03:25:41
For each Y, you have 100 corresponding bootstrap-Y’s and thus 100 bootstrap-intercepts. Among those 100 intercepts' T statistics, how many exceed the T of the original intercept (only 1 for each company)? If that is what you are asking, so
  1. data a;
  2. input Co T; datalines;
  3. 1 1
  4. 1 2
  5. 1 3
  6. 2 1
  7. ;
  8. data b;
  9. input Co T; datalines;
  10. 1 2
  11. 2 0
  12. ;
  13. proc sql;
  14. select Co, count(*) as n 'N of Ta>Tb'  from
  15.   (select a.*, b.T as Tb from a, b where a.Co = b.Co) where  T > Tb
  16.   group by Co
  17. ;
  18. quit;
复制代码

36
funwin 发表于 2010-4-10 07:48:49
34# jingju11

So useful. It's been done. I really appreciate your kindly help.
Have a good weekend.

37
funwin 发表于 2010-4-10 07:53:28
35# jingju11

Yeah, that's what I need. You've totally grabbed my idea for data processing. Cheers.

38
funwin 发表于 2010-5-30 05:09:10
上次多谢你指点,帮我解决了bootstrap中的残值再抽样问题,非常感谢。
现在想用另一种bootstrap方法(这simulation方法,我称之为jointly sampling.):
1, 对每家公司,按公式:Yi,t=ai+bi*Bi,t+ci*Ci,t 做时间序列回归。得出每家公司的ai, 以及 Zi,t=Yi,t-ai;
2, 然后对每家公司的时间t进行有放回的再抽样(抽取300次,我的研究时间段一共300个月),不管每家公司原来有多少期,都抽出同样300期。比如有一家公司虽然只有70期,但也抽出300期来。
(上次进行的是残值再抽样,而且抽取的次数和公司原来的期数一致)
3;做 Zi,t =alphai+bi*Bi,t+ci*Ci,t 时间序列回归(每个公司都有抽取出来的300期了),得出一个新的alphai and t-statistic of alpha ;
5. 步骤2-3,重复1000次。也就是说每家公司最后有1000个 new alpha and t-statitics of alpha.
不知如何能够实现?望jingju11能否再次指教一下!非常感激

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-25 04:44