全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学
5343 8
2010-05-03
最近在学习SAS,正在读Analyzing stock using sas system.

其中第二章节用reg的方法来分析23只股票。目的就是用股票的dividend对growth rate,pe比值还有股票的std做regression。书不错,例子也很好懂。可是我在运用他的例子准备plot 线性回归的residual的时候,发现没有R(residual)这一项,reg这个函数根本没有R输出啊。

我在附件里加了我的完整的code,可以直接运行的,各位高人如果能看看就太好了。

我卡在最后plot这步,

proc plot data=dcf_reg1 vpct=125;
       plot r*gc='*' / vref=0;
       title2 'PE Regression Residuals';
       title3 'versus Compound Growth Rate';
    run;

第二行的r*gc 里的r被sas抱怨说找不到,按道理应该是reg自动输出吧,可是我看上一步的输出里,reg的确没有输出任何的residual。

















data dcf2 ;
        input year stock1 stock2 stock3 stock4 stock5 stock6 stock7 stock8 stock9 stock10 stock11 stock12 stock13 stock14 stock15 stock16 stock17 stock18
              stock19 stock20 stock21 stock22 stock23;
                array stock(23) stock1-stock23;
                array lstock(23) lstock1-lstock23;
                do i=1 to 23;
                        lstock(i) = log(stock(i));
                end;
                year2 = year*year;

        label stock1='3M Company'
                stock2='Allegheny Power'
                stock3='Cincinnati G&E'
                stock4='Detroit Edison'
                stock5='Dominion Resources'
                stock6='Duke Power'
                stock7='Eli Lilly'
                stock8='Green Mountain Power'
                stock9='Iowa-Ill Gas & Electric'
                stock10='Kansas Power & Light'
                stock11='Kentucky Utilities'
                stock12='Minnesota Power & Light'
                stock13='Northern States Power'
                stock14='Oklahoma Gas & Electric'
                stock15='Orange & Rockland Utilities'
                stock16='Pennsylvania Power & Light'
                stock17='Piedmont Natural Gas'
                stock18='Potomac Electric Power'
                stock19='TECO Energy'
                stock20='Texas Utilities'
                stock21='Union Electric'
                stock22='Wisconsin Energy'
                stock23='Wicor'
                     lstock1='Natural Log 3M Company'
          lstock2='Natural Log Allegheny Power';
       cards;
    81 1.50 2.01 2.07 1.62 1.43 1.04  .58 1.44 1.10 1.08 1.06
     1.06 1.25 1.68 1.64 2.21  .87  .79  .84 1.85 1.52  .88 1.05
    82 1.60 2.28 2.12 1.68 1.53 1.12  .67 1.52 1.18 1.18 1.10
     1.14 1.33 1.76 1.74 2.30  .93  .84  .92 2.00 1.58  .95 1.07
    83 1.65 2.50 2.16 1.68 1.63 1.16  .69 1.60 1.24 1.26 1.14
     1.20 1.43 1.84 1.86 2.38  .97  .89 1.00 2.16 1.66 1.03 1.07
    84 1.70 2.63 2.16 1.68 1.73 1.21  .75 1.68 1.30 1.36 1.18
     1.28 1.55 1.92 1.98 2.46 1.07  .97 1.08 2.32 1.72 1.12 1.11
    85 1.75 2.70 2.16 1.68 1.83 1.27  .80 1.74 1.37 1.46 1.22
     1.38 1.69 2.00 2.09 2.56 1.16 1.08 1.16 2.48 1.78 1.22 1.18
    86 1.80 2.86 2.16 1.68 1.91 1.32  .90 1.78 1.45 1.56 1.26
     1.52 1.83 2.08 2.16 2.57 1.19 1.18 1.24 2.64 1.86 1.32 1.28
    87 1.86 2.94 2.18 1.68 1.99 1.37 1.00 1.83 1.52 1.63 1.29
     1.66 1.96 2.18 2.20 2.66 1.29 1.30 1.32 2.77 1.92 1.42 1.30
    88 2.12 3.02 2.23 1.68 2.07 1.44 1.15 1.89 1.59 1.70 1.34
     1.72 2.07 2.28 2.24 2.74 1.44 1.38 1.40 2.86 1.94 1.52 1.32
    89 2.60 3.10 2.30 1.68 2.15 1.52 1.35 1.95 1.63 1.75 1.40
     1.78 2.17 2.38 2.28 2.84 1.57 1.46 1.50 2.91 2.02 1.63 1.37
    90 2.82 3.16 2.40 1.76 2.23 1.60 1.64 2.00 1.67 1.79 1.46
     1.86 2.27 2.48 2.32 2.95 1.66 1.52 1.60 2.96 2.10 1.74 1.42
    ;
run;



data dcf9;
        input firm $32. pe  pr ;
        label pe='Price Earning Ratio 1990'
                  pr='Dividend Payout Ratio 1990';
                  cards;
        3M Company                  14.0 48
    Allegheny Power             10.5 88
    Cincinnati G&E               7.3 58
    Detroit Edison               8.2 54
    Dominion Resources          10.3 76
    Duke Power                  12.1 67
    Eli Lilly                   19.1 42
    Green Mountain Power        10.8 87
    Iowa-Ill Gas & Electric     10.6 84
    Kansas Power & Light        10.0 80
    Kentucky Utilities           9.9 74
    Minnesota Power & Light     10.5 78
    Northern States Power       12.3 81
    Oklahoma Gas & Electric     10.7 73
    Orange & Rockland Utilities  9.8 78
    Pennsylvania Power & Light  10.6 75
    Piedmont Natural Gas        11.3 68
    Potomac Electric Power      13.0 94
    TECO Energy                 12.3 65
    Texas Utilities              8.1 67
    Union Electric              10.0 77
    Wisconsin Energy            10.7 63
    Wicor                       20.9  .
    ;
run;


/*Calculating the Standard Deviations of Dividend Growth Rates*/
proc means data=dcf2 noprint;
        var stock1-stock23;
        output out=dcf_std1 std=std1-std23;
run;


proc transpose data=dcf_std1 out=dcf_std2(rename=(col1=std));
        var std1-std23;
run;


data dcf_cal2;
        merge dcf9 dcf_std2 dcf_call;
run;

proc print data=dcf_cal2;
        var pe gc pr std;
        title2'Cross-Sectional Multiple Regression Data';
        title3'23 Observations';
run;

proc reg data=dcf_cal2;
        model pe=gc pr std;
        output out=dcf_reg1;
run;







谢谢大家
二维码

扫码加我 拉你入群

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

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

全部回复
2010-5-3 05:59:55
1# shewenhao

****1. ***;
216  data dcf_cal2;
217          merge dcf9 dcf_std2 dcf_call;
ERROR: File WORK.DCF_CALL.DATA does not exist.
218  run;


proc plot data=dcf_reg1 vpct=125;
        plot r*gc='*' / vref=0;
        title2 'PE Regression Residuals';
        title3 'versus Compound Growth Rate';
     run;

第二行的r*gc 里的r被sas抱怨说找不到,按道理应该是reg自动输出吧,可是我看上一步的输出里,reg的确没有输出任何的residual


*** 2. ***;
can you use
plot residual.*gc='*'  ;

after your figuring out errors 1.
二维码

扫码加我 拉你入群

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

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

2010-5-3 08:18:37
2# gzjb

关于你运行我的程序出错,因为我忘记加了一段代码,不好意思,现在加上附件。

谢谢你的回复gzjb, 我尝试了用你的residual. 替换r但是还是不行,输出如下


784  proc plot data=dcf_reg1 vpct=125;
785         plot residual.*gc='*' / vref=0;
                 ----------
                 22       200
ERROR: Variable NAME not found.
NOTE: The previous statement has been deleted.
ERROR 22-322: Syntax error, expecting one of the following: a name, (.


我现在补齐所有文件,请先运行压缩包里的d2文件,然后运行d9这样就不会出现gzjb所贴的报错,不好意思:)谢谢大家

gzjb,如果你有时间能再泡一下这个完整版本么?这样你就会看到最后的error


谢谢啦

d9.zip
大小:(3.81 KB)

 马上下载

本附件包括:

  • d9.sas
  • d2.sas





ERROR 200-322: The symbol is not recognized and will be ignored.
786         title2 'PE Regression Residuals';
787         title3 'versus Compound Growth Rate';
788      run;
二维码

扫码加我 拉你入群

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

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

2010-5-3 15:47:28
大哥,我晕!
proc reg data=dcf_cal2;
        model pe=gc pr std;
        output out=dcf_reg1;
run;

residual不会自动generate,你要specify。
output out=myout r=residual;
在myout里边你可以找到residual。关于其他的数据,详细请参考SAS的help file!
二维码

扫码加我 拉你入群

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

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

2010-5-3 16:35:38
4# Isscaliu

前辈,多谢赐教。总算不报错了,yeah。但是现在有如下log:


985  proc reg data=dcf_cal2;
986      model pe=gc pr std;
987      output out=dcf_reg1 r=residual;
988  run;

WARNING: The variable _NAME_ or _TYPE_ exists in a data set that is not TYPE=CORR, COV, SSCP, etc.
989
990
991
992

NOTE: The data set WORK.DCF_REG1 has 23 observations and 88 variables.
NOTE: PROCEDURE REG used (Total process time):
      real time           0.12 seconds
      cpu time            0.12 seconds


993  proc plot data=dcf_reg1;
994         plot residual*t;
995         title2 'PE Regression Residuals';
996         title3 'versus Compound Growth Rate';
997      run;

看不懂 warning啥意思,但是我看了一下reg的out=dcf_reg1 里边确实有residual这一项了。然后我最后作图在result里边也有输出了,但就是双击那个plot就是不显示,是不是和则个warning有关啊。能看一下么?:)谢谢了。

VIP果然不一样啊!
二维码

扫码加我 拉你入群

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

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

2010-5-3 17:12:29
问题就是窗口一直运行
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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